List of usage examples for org.apache.commons.lang StringUtils isWhitespace
public static boolean isWhitespace(String str)
Checks if the String contains only whitespace.
From source file:org.apache.shindig.gadgets.rewrite.CssResponseRewriter.java
/** * Rewrite the CSS content in a style DOM node. * @param styleNode Rewrite the CSS content of this node * @param source Uri of content/* ww w. j a v a2 s . c o m*/ * @param uriMaker a UriMaker * @param extractImports If true remove the import statements from the output and return their * referenced URIs. * @param gadgetContext The gadgetContext * @return Empty list of extracted import URIs. */ public List<String> rewrite(Element styleNode, Uri source, UriMaker uriMaker, boolean extractImports, GadgetContext gadgetContext) throws RewritingException { try { CssTree.StyleSheet stylesheet = cssParser.parseDom(styleNode.getTextContent(), source); List<String> imports = rewrite(stylesheet, source, uriMaker, extractImports, gadgetContext); // Write the rewritten CSS back into the element String content = cssParser.serialize(stylesheet); if (StringUtils.isEmpty(content) || StringUtils.isWhitespace(content)) { // Remove the owning node styleNode.getParentNode().removeChild(styleNode); } else { styleNode.setTextContent(content); } return imports; } catch (GadgetException ge) { if (ge.getCause() instanceof ParseException) { LOG.log(Level.WARNING, "Caja CSS parse failure: " + ge.getCause().getMessage() + " for " + source); return Collections.emptyList(); } else { throw new RewritingException(ge, ge.getHttpStatusCode()); } } }
From source file:org.apache.torque.generator.configuration.source.SourceTransformerSaxHandler.java
/** * {@inheritDoc}/*from www . j a v a 2s . c om*/ */ @Override public void startElement(String uri, String localName, String rawName, Attributes attributes) throws SAXException { if (level == 0) { level++; if (rawName.equals(TRANSFORMER_TAG)) { String className = attributes.getValue(TRANSFORMER_CLASS_ATTRIBUTE); if (className == null) { throw new SAXException("The attribute " + TRANSFORMER_CLASS_ATTRIBUTE + " must not be null for the element " + TRANSFORMER_TAG); } elements = attributes.getValue(ELEMENTS_ATTRIBUTE); sourceTransformer = createJavaSourceTransformer(className); } else { throw new SAXException("Unknown element " + rawName); } } else if (level == 1) { level++; propertyName = rawName; simplePropertyValue = new StringBuilder(); } else if (level == 2) { level++; if (simplePropertyValue.length() > 0 && !StringUtils.isWhitespace(simplePropertyValue.toString())) { throw new SAXException( "Cannot parse both text content and child elements " + " in element " + propertyName); } simplePropertyValue = null; if (listPropertyValue == null) { listPropertyValue = new ArrayList<String>(); } listPropertyEntry = new StringBuilder(); } else { throw new SAXException("unknown Element " + rawName); } }
From source file:org.artifactory.rest.common.list.KeyValueList.java
public KeyValueList(String s) { super();/*from www.j a v a2 s .c om*/ String[] splittedValues = BACKSLASH_PIPE_PATTERN.split(s); for (String v : splittedValues) { try { if (!StringUtils.isWhitespace(v)) { add(v.trim()); } } catch (Exception ex) { log.error("Error while parsing list parameter '{}': {}.", s, ex.getMessage()); throw new WebApplicationException(ex, Response.Status.BAD_REQUEST); } } }
From source file:org.artifactory.rest.common.list.StringList.java
public StringList(String s) { super();/*from ww w . j a v a2s . c o m*/ for (String v : s.split(",")) { try { if (!StringUtils.isWhitespace(v)) { add(v.trim()); } } catch (Exception ex) { log.error("Error while parsing list parameter '{}': {}.", s, ex.getMessage()); throw new WebApplicationException(ex, Response.Status.BAD_REQUEST); } } }
From source file:org.codice.ddf.security.migratable.impl.SecurityMigratable.java
private void exportCrlFile(Path propertiesPath, Path exportDirectory, Collection<MigrationWarning> migrationWarnings) throws MigrationException { LOGGER.debug("Exporting CRL from property [{}] in file [{}]...", CRL_PROP_KEY, propertiesPath.toString()); String crlPathStr = migratableUtil.getJavaPropertyValue(propertiesPath, CRL_PROP_KEY); if (crlPathStr == null) { return;//from w w w . j av a 2 s . c om } if (StringUtils.isWhitespace(crlPathStr)) { String error = String.format( "Failed to export CRL. No CRL path found in file [%s]. Property [%s] from properties file [%s] has a blank value.", propertiesPath, CRL_PROP_KEY, propertiesPath); throw new ExportMigrationException(error); } Path crlPath = Paths.get(crlPathStr); migratableUtil.copyFile(crlPath, exportDirectory, migrationWarnings); }
From source file:org.commonwl.view.workflow.WorkflowFormValidator.java
/** * Checks if a string is empty or whitespace * @param str The string to be checked/*w ww . j a v a 2 s .c o m*/ * @return Whether the string is empty or whitespace */ private boolean isEmptyOrWhitespace(String str) { return (str == null || str.length() == 0 || StringUtils.isWhitespace(str)); }
From source file:org.dspace.search.QueryArgs.java
/** * Builds a query-part using the field and value passed in * with ' --> " (single to double quote) translation. * * @param myquery the value the query will look for * @param myfield the field myquery will be looked for in * * @return the query created//from ww w . j a v a 2s . com */ private String buildQueryPart(String myquery, String myfield) { StringBuilder newQuery = new StringBuilder(); newQuery.append("("); boolean newTerm = true; boolean inPhrase = false; char phraseChar = '\"'; StringTokenizer qtok = new StringTokenizer(myquery, " \t\n\r\f\"\'", true); while (qtok.hasMoreTokens()) { String token = qtok.nextToken(); if (StringUtils.isWhitespace(token)) { if (!inPhrase) { newTerm = true; } newQuery.append(token); } else { // Matched the end of the phrase if (inPhrase && token.charAt(0) == phraseChar) { newQuery.append("\""); inPhrase = false; } else { // If we aren't dealing with a new term, and have a single quote // don't touch it. (for example, the apostrophe in it's). if (!newTerm && token.charAt(0) == '\'') { newQuery.append(token); } else { // Treat - my"phrased query" - as - my "phrased query" if (!newTerm && token.charAt(0) == '\"') { newQuery.append(" "); newTerm = true; } // This is a new term in the query (ie. preceeded by nothing or whitespace) // so apply a field restriction if specified if (newTerm && !myfield.equals("ANY")) { newQuery.append(myfield).append(":"); } // Open a new phrase, and closing at the corresponding character // ie. 'my phrase' or "my phrase" if (token.charAt(0) == '\"' || token.charAt(0) == '\'') { newQuery.append("\""); inPhrase = true; newTerm = false; phraseChar = token.charAt(0); } else { newQuery.append(token); newTerm = false; } } } } } newQuery.append(")"); return newQuery.toString(); }
From source file:org.eclipse.uomo.ucum.parsers.DefinitionParser.java
public UcumModel parse(InputStream stream) throws XmlPullParserException, IOException, ParseException { XmlPullParserFactory factory = XmlPullParserFactory .newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); factory.setNamespaceAware(true);//from w ww . ja va 2s . c om XmlPullParser xpp = factory.newPullParser(); xpp.setInput(stream, null); int eventType = xpp.next(); if (eventType != START_TAG) throw new XmlPullParserException(Messages.DefinitionParser_0); if (!xpp.getName().equals("root")) //$NON-NLS-1$ throw new XmlPullParserException( Messages.DefinitionParser_2 + xpp.getName() + Messages.DefinitionParser_3); final DateFormat fmt = new SimpleDateFormat(Messages.DefinitionParser_DateFormat); Date date = fmt.parse(xpp.getAttributeValue(null, "revision-date").substring(7, 32)); //$NON-NLS-1$ UcumModel root = new UcumModel(xpp.getAttributeValue(null, "version"), //$NON-NLS-1$ xpp.getAttributeValue(null, "revision"), date); //$NON-NLS-1$ xpp.next(); while (xpp.getEventType() != END_TAG) { if (xpp.getEventType() == TEXT) { if (StringUtils.isWhitespace(xpp.getText())) xpp.next(); else throw new XmlPullParserException(Messages.DefinitionParser_8 + xpp.getText()); } else if (xpp.getName().equals(PREFIX.visibleName())) root.getPrefixes().add(parsePrefix(xpp)); else if (xpp.getName().equals(BASEUNIT.visibleName())) root.getBaseUnits().add(parseBaseUnit(xpp)); else if (xpp.getName().equals(UNIT.visibleName())) root.getDefinedUnits().add(parseUnit(xpp)); else throw new XmlPullParserException(Messages.DefinitionParser_9 + xpp.getName()); } return root; }
From source file:org.eclipse.uomo.ucum.parsers.DefinitionParser.java
private void skipWhitespace(XmlPullParser xpp) throws XmlPullParserException, IOException { while (xpp.getEventType() == TEXT && StringUtils.isWhitespace(xpp.getText())) xpp.next();//w ww.ja va 2 s . co m }
From source file:org.eclipse.uomo.xml.impl.XMLReader.java
public void characters(char[] ch, int start, int length) throws SAXException { current().findText(ch, start, length, StringUtils.isWhitespace(new String(ch, start, length))); }