List of usage examples for org.apache.commons.lang StringUtils stripAll
public static String[] stripAll(String[] strs)
Strips whitespace from the start and end of every String in an array.
From source file:org.codice.ddf.endpoints.OpenSearchEndpoint.java
/** * @param searchTerms Space delimited list of search terms. * @param maxResults Maximum # of results to return. If count is also specified, the count value will * take precedence over the maxResults value * @param sources Comma delimited list of data sources to query (default: default sources selected). * @param maxTimeout Maximum timeout (msec) for query to respond (default: mt=30000). * @param startIndex Index of first result to return. Integer >= 0 (default: start=1). * @param count Number of results to retrieve per page (default: count=10). * @param geometry WKT Geometries (Support POINT and POLYGON). * @param bbox Comma delimited list of lat/lon (deg) bounding box coordinates (geo format: * geo:bbox ~ West,South,East,North). * @param polygon Comma delimited list of lat/lon (deg) pairs, in clockwise order around the * polygon, with the last point being the same as the first in order to close the * polygon./*from w w w. j a va2 s.c om*/ * @param lat Latitude in decimal degrees (typical GPS receiver WGS84 coordinates). * @param lon Longitude in decimal degrees (typical GPS receiver WGS84 coordinates). * @param radius The radius (m) parameter, used with the lat and lon parameters, specifies the * search distance from this point (default: radius=5000). * @param dateStart Specifies the beginning of the time slice of the search on the modified time field * (RFC-3339 - Date and Time format, i.e. YYYY-MM-DDTHH:mm:ssZ). Default value of * "1970-01-01T00:00:00Z" is used when dtend is indicated but dtstart is not * specified * @param dateEnd Specifies the ending of the time slice of the search on the modified time field * (RFC-3339 - Date and Time format, i.e. YYYY-MM-DDTHH:mm:ssZ). Current GMT * date/time is used when dtstart is specified but not dtend. * @param dateOffset Specifies an offset, backwards from the current time, to search on the modified * time field for entries. Defined in milliseconds. * @param sort Specifies sort by field as sort=<sbfield>:<sborder>, where <sbfield> may be 'date' * or 'relevance' (default is 'relevance'). The conditional param <sborder> is * optional but has a value of 'asc' or 'desc' (default is 'desc'). When <sbfield> is * 'relevance', <sborder> must be 'desc'. * @param format Defines the format that the return type should be in. (example:atom, html) * @param selector Defines a comma delimited list of XPath selectors to narrow the query. * @param type Specifies the type of data to search for. (example: nitf) * @param versions Specifies the versions in a comma delimited list. * @return */ @GET public Response processQuery(@QueryParam(PHRASE) String searchTerms, @QueryParam(MAX_RESULTS) String maxResults, @QueryParam(SOURCES) String sources, @QueryParam(MAX_TIMEOUT) String maxTimeout, @QueryParam(START_INDEX) String startIndex, @QueryParam(COUNT) String count, @QueryParam(GEOMETRY) String geometry, @QueryParam(BBOX) String bbox, @QueryParam(POLYGON) String polygon, @QueryParam(LAT) String lat, @QueryParam(LON) String lon, @QueryParam(RADIUS) String radius, @QueryParam(DATE_START) String dateStart, @QueryParam(DATE_END) String dateEnd, @QueryParam(DATE_OFFSET) String dateOffset, @QueryParam(SORT) String sort, @QueryParam(FORMAT) String format, @QueryParam(SELECTOR) String selector, @Context UriInfo ui, @QueryParam(TYPE) String type, @QueryParam(VERSION) String versions, @Context HttpServletRequest request) { final String methodName = "processQuery"; LOGGER.trace("ENTERING: " + methodName); Response response; String localCount = count; LOGGER.debug("request url: " + ui.getRequestUri()); // honor maxResults if count is not specified if ((StringUtils.isEmpty(localCount)) && (!(StringUtils.isEmpty(maxResults)))) { LOGGER.debug("setting count to: " + maxResults); localCount = maxResults; } try { String queryFormat = format; OpenSearchQuery query = createNewQuery(startIndex, localCount, sort, maxTimeout); if (!(StringUtils.isEmpty(sources))) { LOGGER.debug("Received site names from client."); Set<String> siteSet = new HashSet<String>(Arrays.asList(StringUtils.stripAll(sources.split(",")))); // This code block is for backward compatibility to support src=local. // Since local is a magic work, not in any specification, weneed to // eventually remove support for it. if (siteSet.remove(LOCAL)) { LOGGER.debug("Found 'local' alias, replacing with " + SystemInfo.getSiteName() + "."); siteSet.add(SystemInfo.getSiteName()); } if (siteSet.contains(framework.getId()) && siteSet.size() == 1) { LOGGER.debug("Only local site specified, saving overhead and just performing a local query on " + framework.getId() + "."); } else { LOGGER.debug("Querying site set: " + siteSet); query.setSiteIds(siteSet); } query.setIsEnterprise(false); } else { LOGGER.debug("No sites found, defaulting to enterprise query."); query.setIsEnterprise(true); } // contextual if (searchTerms != null && !searchTerms.trim().isEmpty()) { try { query.addContextualFilter(searchTerms, selector); } catch (ParsingException e) { throw new IllegalArgumentException(e.getMessage()); } } // temporal // single temporal criterion per query if ((dateStart != null && !dateStart.trim().isEmpty()) || (dateEnd != null && !dateEnd.trim().isEmpty()) || (dateOffset != null && !dateOffset.trim().isEmpty())) { query.addTemporalFilter(dateStart, dateEnd, dateOffset); } // spatial // single spatial criterion per query addSpatialFilter(query, geometry, polygon, bbox, radius, lat, lon); if (type != null && !type.trim().isEmpty()) { query.addTypeFilter(type, versions); } Map<String, Serializable> properties = new HashMap<String, Serializable>(); for (Object key : request.getParameterMap().keySet()) { if (key instanceof String) { Object value = request.getParameterMap().get(key); if (value instanceof Serializable) { properties.put((String) key, ((String[]) value)[0]); } } } response = executeQuery(queryFormat, query, ui, properties); } catch (IllegalArgumentException iae) { LOGGER.warn("Bad input found while executing a query", iae); response = Response.status(Response.Status.BAD_REQUEST) .entity(wrapStringInPreformattedTags(iae.getMessage())).build(); } catch (RuntimeException re) { LOGGER.warn("Exception while executing a query", re); response = Response.serverError() .entity(wrapStringInPreformattedTags("Exception while executing a query")).build(); } LOGGER.trace("EXITING: " + methodName); return response; }
From source file:org.codice.ddf.ui.searchui.query.service.SearchService.java
private Set<String> getSourceIds(String sources) { Set<String> sourceIds; if (StringUtils.equalsIgnoreCase(sources, LOCAL_SOURCE)) { LOGGER.debug("Received local query"); sourceIds = new HashSet<String>(Arrays.asList(searchController.getFramework().getId())); } else if (!(StringUtils.isEmpty(sources))) { LOGGER.debug("Received source names from client: {}", sources); sourceIds = new HashSet<String>(Arrays.asList(StringUtils.stripAll(sources.split(",")))); } else {//from www . j av a 2s . co m LOGGER.debug("Received enterprise query"); SourceInfoResponse sourceInfo = null; try { sourceInfo = searchController.getFramework().getSourceInfo(new SourceInfoRequestEnterprise(true)); } catch (SourceUnavailableException e) { LOGGER.debug("Exception while getting source status. Defaulting to all sources. " + "This could include unavailable sources.", e); } if (sourceInfo != null) { sourceIds = new HashSet<String>(); for (SourceDescriptor source : sourceInfo.getSourceInfo()) { if (source.isAvailable()) { sourceIds.add(source.getSourceId()); } } } else { sourceIds = searchController.getFramework().getSourceIds(); } } return sourceIds; }
From source file:org.docx4j.fonts.BestMatchingMapper.java
/** * Populate the fontMappings object. We make an entry for each * of the documentFontNames./*from ww w . j ava 2s . co m*/ * * @param documentFontNames - the fonts used in the document * @param wmlFonts - the content model for the fonts part * @throws Exception */ public void populateFontMappings(Set<String> documentFontNames, org.docx4j.wml.Fonts wmlFonts) throws Exception { /* org.docx4j.wml.Fonts fonts is obtained as follows: * * FontTablePart fontTablePart= wordMLPackage.getMainDocumentPart().getFontTablePart(); * org.docx4j.wml.Fonts fonts = (org.docx4j.wml.Fonts)fontTablePart.getJaxbElement(); * * If the document doesn't have a font table, * * org.docx4j.openpackaging.parts.WordprocessingML.FontTablePart fontTable * = new org.docx4j.openpackaging.parts.WordprocessingML.FontTablePart(); * fontTable.unmarshalDefaultFonts(); */ // We need to make a map out of it. List<Fonts.Font> fontList = wmlFonts.getFont(); Map<String, Fonts.Font> fontsInFontTable = new HashMap<String, Fonts.Font>(); for (Fonts.Font font : fontList) { fontsInFontTable.put((font.getName()), font); } log.info("\n\n Populating font mappings."); // Go through the font names, and determine which ones we can render! for (String documentFontName : documentFontNames) { PhysicalFont fontMatched = null; log.debug("\n\n" + documentFontName); // Since docx4all invokes this method when opening // each new document, the mapping may have been done // last time. We don't need to do it again if (get(documentFontName) != null) { log.info(documentFontName + " already mapped."); if (lastSeenNumberOfPhysicalFonts == PhysicalFonts.getPhysicalFonts().size()) { // TODO - set this up properly! log.info(".. and no need to check again."); continue; // Assume bold, italic etc already mapped } else { log.info(".. but checking again, since physical fonts have changed."); } } // Embedded fonts - bypass panose for these if (regularForms.get(documentFontName) != null) { put(documentFontName, regularForms.get(documentFontName)); log.debug(".. mapped to embedded regular form "); continue; } else if (boldForms.get(documentFontName) != null) { put(documentFontName, boldForms.get(documentFontName)); log.debug(".. mapped to embedded bold form "); continue; } else if (italicForms.get(documentFontName) != null) { put(documentFontName, italicForms.get(documentFontName)); log.debug(".. mapped to embedded italic form "); continue; } else if (boldItalicForms.get(documentFontName) != null) { put(documentFontName, boldItalicForms.get(documentFontName)); log.debug(".. mapped to embedded bold italic form "); continue; } // boolean normalFormFound = false; // Panose setup org.docx4j.wml.FontPanose wmlFontPanoseForDocumentFont = null; Fonts.Font font = fontsInFontTable.get(documentFontName); if (font == null) { log.error("Font " + documentFontName + "not found in font table!"); } else { wmlFontPanoseForDocumentFont = font.getPanose1(); } org.docx4j.fonts.foray.font.format.Panose documentFontPanose = null; if (wmlFontPanoseForDocumentFont != null && wmlFontPanoseForDocumentFont.getVal() != null) { try { documentFontPanose = org.docx4j.fonts.foray.font.format.Panose .makeInstance(wmlFontPanoseForDocumentFont.getVal()); } catch (IllegalArgumentException e) { log.error(e.getMessage()); // For example: // Illegal Panose Array: Invalid value 10 > 8 in position 5 of [ 4 2 7 5 4 10 2 6 7 2 ] } if (documentFontPanose != null) { log.debug(".. " + documentFontPanose.toString()); } } else { log.debug(".. no panose info!!!"); } /* What about a panose match? * * We rely on this almost exclusively at present. It works very well, with the following exceptions: * * Garamond-Bold .. [ 2 2 8 4 3 3 7 1 8 3 ] Looking for [ 2 2 8 4 3 3 1 1 8 3 ] ^----------- stuffs us up * */ // TODO - only do this for latin fonts! if (documentFontPanose == null) { log.debug(" --> null Panose"); } else { // Is the Panose value valid? if (log.isDebugEnabled() && org.docx4j.fonts.foray.font.format.Panose .validPanose(documentFontPanose.getPanoseArray()) != null) { // NB org.apache.fop.fonts.Panose only exists in our patched FOP log.debug(documentFontName + " : " + org.docx4j.fonts.foray.font.format.Panose .validPanose(documentFontPanose.getPanoseArray())); //This is the case for 'Impact' which has //Invalid value 9 > 8 in position 5 of 2 11 8 6 3 9 2 5 2 4 } String panoseKey = findClosestPanoseMatch(documentFontName, documentFontPanose, PhysicalFonts.getPhysicalFonts(), MATCH_THRESHOLD); if (panoseKey == null) { log.debug(documentFontName + " --> no panose match"); } else { fontMatched = PhysicalFonts.getPhysicalFonts().get(panoseKey); if (fontMatched != null) { put(documentFontName, PhysicalFonts.getPhysicalFonts().get(panoseKey)); log.debug("Mapped " + documentFontName + " --> " + panoseKey + "( " + PhysicalFonts.getPhysicalFonts().get(panoseKey).getEmbeddedFile()); } else { log.debug("font with key " + panoseKey + " doesn't exist!"); } // Out of interest, is this match in font substitutions table? FontSubstitutions.Replace rtmp = (FontSubstitutions.Replace) explicitSubstitutionsMap .get(documentFontName); if (rtmp != null && rtmp.getSubstFonts() != null) { if (rtmp.getSubstFonts().contains(panoseKey)) { log.debug("(consistent with explicit substitutes)"); } else { log.debug("(lucky, since this is missing from explicit substitutes)"); } } } // // However we found our match for the normal form of // // this document font, we still need to do // // bold, italic, and bolditalic? // // MicrosoftFonts.Font msFont = (MicrosoftFonts.Font)msFontsFilenames.get(documentFontName); // // if (msFont==null) { // log.warn("Font not found in MicrosoftFonts.xml"); // continue; // } // //// PhysicalFont fmTmp; //// // org.apache.fop.fonts.Panose seekingPanose = null; // if (msFont.getBold()!=null) { // log.debug("this font has a bold form"); // seekingPanose = documentFontPanose.getBold(); // fmTmp = getAssociatedPhysicalFont(documentFontName, panoseKey, seekingPanose); // if (fmTmp!=null) { // fontMappings.put(documentFontName+BOLD, fmTmp); // } // } // // fmTmp = null; // seekingPanose = null; // if (msFont.getItalic()!=null) { // log.debug("this font has an italic form"); // seekingPanose = documentFontPanose.getItalic(); // fmTmp = getAssociatedPhysicalFont(documentFontName, panoseKey, seekingPanose); // if (fmTmp!=null) { // fontMappings.put(documentFontName+ITALIC, fmTmp); // } // } // // fmTmp = null; // seekingPanose = null; // if (msFont.getBolditalic()!=null) { // log.debug("this font has a bold italic form"); // seekingPanose = documentFontPanose.getBold(); // seekingPanose = seekingPanose.getItalic(); // fmTmp = getAssociatedPhysicalFont(documentFontName, panoseKey, seekingPanose); // if (fmTmp!=null) { // fontMappings.put(documentFontName+BOLD_ITALIC, fmTmp); // } // } continue; // we're done with this document font } // Finally, try explicit font substitutions // - most likely to be useful for a font that doesn't have panose entries // if ( normalFormFound) { // continue; // } // Don't bother trying this for bold, italic if you've already // got the normal form log.debug("So try explicit font substitutions table"); FontSubstitutions.Replace replacement = (FontSubstitutions.Replace) explicitSubstitutionsMap .get((generateFontKey(documentFontName))); if (replacement != null) { // log.debug( "\n" + fontName + " found." ); // String subsFonts = replacement.getSubstFonts(); // Is there anything in subsFonts we can use? String[] tokens = StringUtils.stripAll(replacement.getSubstFonts().split(";")); boolean foundMapping = false; for (int x = 0; x < tokens.length; x++) { // log.debug(tokens[x]); fontMatched = getPhysicalFontByKey(tokens[x]); if (fontMatched != null) { String physicalFontFile = fontMatched.getEmbeddedFile(); log.debug("PDF: " + documentFontName + " --> " + physicalFontFile); foundMapping = true; // Out of interest, does this have a Panose value? // And what is the distance? if (fontMatched.getPanose() == null) { log.debug(".. as expected, lacking Panose"); } else if (documentFontPanose != null) { org.docx4j.fonts.foray.font.format.Panose physicalFontPanose = null; try { physicalFontPanose = org.docx4j.fonts.foray.font.format.Panose .makeInstance(fontMatched.getPanose().getPanoseArray()); } catch (IllegalArgumentException e) { log.error(e.getMessage()); // For example: // Illegal Panose Array: Invalid value 10 > 8 in position 5 of [ 4 2 7 5 4 10 2 6 7 2 ] } if (physicalFontPanose != null) { long pd = documentFontPanose.difference(physicalFontPanose, null); if (pd >= MATCH_THRESHOLD) { log.debug(".. with a panose distance exceeding threshold: " + pd); } else { // Sanity check log.error(".. with a low panose distance (! How did we get here?) : " + pd); } } } break; } else { // log.debug("no match on token " + x + ":" // + tokens[x]); } } if (!foundMapping) { log.debug(documentFontName + " --> Couldn't find any of " + replacement.getSubstFonts()); } } else { log.debug("Nothing in FontSubstitutions.xml for: " + documentFontName); // TODO - add default fallback values } if (fontMatched != null) { put(documentFontName, fontMatched); log.warn("Mapped " + documentFontName + " --> " + fontMatched.getName() + "( " + fontMatched.getEmbeddedFile()); } else { log.debug("Nothing added for: " + documentFontName); } } lastSeenNumberOfPhysicalFonts = PhysicalFonts.getPhysicalFonts().size(); }
From source file:org.eclim.installer.step.VimStep.java
/** * Parses the results of echoing vim runtime path to a file. * * @param file The file containing the results. * @return The results.//from ww w . j a va2 s . c o m */ private String[] parseVimRuntimePathResults(java.io.File file) { FileInputStream in = null; try { String contents = IOUtils.toString(in = new FileInputStream(file)); String[] paths = StringUtils.stripAll(StringUtils.split(contents, ',')); ArrayList<String> results = new ArrayList<String>(); for (String path : paths) { if (new File(path).isDirectory()) { results.add(path.replace('\\', '/')); } } return results.toArray(new String[results.size()]); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(in); file.deleteOnExit(); file.delete(); } return null; }
From source file:org.eclipse.jubula.rc.common.tester.ListTester.java
/** * Splits the enumeration of values./*w w w . j a v a 2 s . c om*/ * @param values The values to split * @param separator The separator, may be <code>null</code> * @return The array of values */ private String[] split(String values, String separator) { String[] list = StringParsing.splitToArray(values, ((separator == null) || (separator.length() == 0) ? INDEX_LIST_SEP_CHAR : separator.charAt(0)), TestDataConstants.ESCAPE_CHAR_DEFAULT); list = StringUtils.stripAll(list); return list; }
From source file:org.intermine.web.logic.aspects.Aspect.java
/** * Set the starting point class names as a space seperated list. * @param classnames class names as a space seperated list *///from w w w .j a va 2 s . co m public void setStartingPoints(String classnames) { String classes[] = StringUtils.split(classnames); classes = StringUtils.stripAll(classes); startingPoints = Arrays.asList(classes); }
From source file:org.sonar.batch.scan.DefaultProjectBootstrapper.java
/** * Transforms a comma-separated list String property in to a array of trimmed strings. * * This works even if they are separated by whitespace characters (space char, EOL, ...) * *//*w w w .j a v a 2 s . co m*/ static String[] getListFromProperty(Properties properties, String key) { return StringUtils.stripAll(StringUtils.split(properties.getProperty(key, ""), ',')); }
From source file:org.sonar.batch.scan.ProjectReactorBuilder.java
/** * Transforms a comma-separated list String property in to a array of trimmed strings. * * This works even if they are separated by whitespace characters (space char, EOL, ...) * *//* w ww. j a va 2 s. c o m*/ static String[] getListFromProperty(Map<String, String> properties, String key) { return (String[]) ObjectUtils .defaultIfNull(StringUtils.stripAll(StringUtils.split(properties.get(key), ',')), new String[0]); }
From source file:org.sonar.plugins.codesize.SizingProfile.java
private void parse(String codeSizeProfile) { String[] lines = StringUtils.split(codeSizeProfile, '\n'); FileSetDefinition fileSetDefinition = null; for (String line : lines) { if (!StringUtils.isBlank(line)) { String[] kv = StringUtils.stripAll(StringUtils.split(line, ":=")); if (kv.length > 1) { if (INCLUDES.contains(kv[0])) { fileSetDefinition.addIncludes(kv[1]); } else if (EXCLUDES.contains(kv[0])) { fileSetDefinition.addExcludes(kv[1]); }//w w w . j a va 2 s . c om } else { fileSetDefinition = new FileSetDefinition(line.trim()); getFileSetDefinitions().add(fileSetDefinition); } } } }
From source file:org.sonar.plugins.web.checks.scripting.UnifiedExpressionCheck.java
public void setFunctions(String list) { functions = StringUtils.stripAll(StringUtils.split(list, ",")); }