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.sonar.plugins.xml.checks.NewlineCheck.java
/** * Validate newlines for node.//from ww w .j av a 2 s . co m */ private void validateNewline(Node node) { // check if we have a newline after the elements and after each childelement. boolean newline = false; Node lastChild = null; for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { switch (child.getNodeType()) { case Node.COMMENT_NODE: case Node.ELEMENT_NODE: // check if there is a new node before we have had any newlines. if (!newline) { createViolation(SaxParser.getLineNumber(child), "Node should be on the next line"); } else { newline = false; } lastChild = child; break; case Node.TEXT_NODE: // newline check is OK if there is non whitespace or the whitespace contains a newline if (!StringUtils.isWhitespace(child.getTextContent()) || child.getTextContent().contains("\n")) { newline = true; } break; default: break; } } // validate first last child. validateLastChild(newline, lastChild); // check the child elements for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeType() == Node.ELEMENT_NODE) { validateNewline(child); } } }
From source file:org.sventon.model.TextFile.java
/** * Replaces leading spaces with the HTML entity <code> </code>. * * @param string Input string. Can be one or more lines. * @return Replaced output string./*ww w . j a v a 2s.c om*/ */ public static String replaceLeadingSpaces(final String string) { if (StringUtils.isEmpty(string)) { return string; } final StringBuilder sb = new StringBuilder(); final String[] lines = NL_REGEXP.split(string); for (final String line : lines) { if (!StringUtils.isWhitespace(line)) { String result = org.springframework.util.StringUtils.trimLeadingWhitespace(line); int removedSpacesCount = line.length() - result.length(); for (int i = 0; i < removedSpacesCount; i++) { result = NBSP + result; } sb.append(result); } else { sb.append(line); } // Make sure to only append NEWLINE when multiple lines. if (lines.length > 1) { sb.append(NL); } } return sb.toString(); }
From source file:org.xmlactions.common.text.Html.java
/** * This will remove the json or xml element from a page. The inner content of the json or xml or html element is returned. * //w w w. java 2s . c o m * If it removes a json or xml element then it will set the content type to reflect the file mime type. * * If no json/xml start and end is found then the page is untouched. * * @param page * @return the inner content of the json/xml element. */ private String _removeOuterJsonOrXml(String page) { String startJsonPattern = "<json"; String endJsonPattern = "</json>"; String startXmlPattern = "<xml"; String endXmlPattern = "</xml>"; String html = page.toLowerCase(); int startIndex = html.indexOf(startJsonPattern); if (startIndex >= 0) { int indexFrom = page.indexOf('>', startIndex); if (indexFrom >= 0) { int indexTo = html.lastIndexOf(endJsonPattern); if (indexTo >= 0) { if (page.length() > indexTo) { if (StringUtils.isWhitespace(page.substring(indexTo + endJsonPattern.length()))) { page = page.substring(indexFrom + 1, indexTo); setContentType(CONTENT_TYPE_JSON); } } else { page = page.substring(indexFrom + 1, indexTo); setContentType(CONTENT_TYPE_JSON); } } } } else { startIndex = html.indexOf(startXmlPattern); if (startIndex >= 0) { int indexFrom = page.indexOf('>', startIndex); if (indexFrom >= 0) { int indexTo = html.lastIndexOf(endXmlPattern); if (indexTo >= 0) { if (page.length() > indexTo) { if (StringUtils.isWhitespace(page.substring(indexTo + endXmlPattern.length()))) { page = page.substring(indexFrom + 1, indexTo); setContentType(CONTENT_TYPE_XML); } } else { page = page.substring(indexFrom + 1, indexTo); setContentType(CONTENT_TYPE_XML); } } } } } return page; }
From source file:org.xmlactions.common.text.Html.java
/** * This will remove the json or xml or html element from a page. The inner content of the json or xml or html element is returned. * // w w w . j a va2 s. co m * If it removes a json or xml element then it will set the content type to reflect the file mime type. * * If no json/xml/html start and end is found then the page is untouched. * * @param page * @return the inner content of the json/xml/html element. */ public String removeOuterJsonOrXmlOrHtml(String page) { String startJsonPattern = "<json"; String endJsonPattern = "</json>"; String startXmlPattern = "<xml"; String endXmlPattern = "</xml>"; String startHtmlPattern = "<html"; String endHtmlPattern = "</html>"; String html = page.toLowerCase(); int startIndex = html.indexOf(startJsonPattern); if (startIndex >= 0) { int indexFrom = page.indexOf('>', startIndex); if (indexFrom >= 0) { int indexTo = html.lastIndexOf(endJsonPattern); if (indexTo >= 0) { if (page.length() > indexTo) { if (StringUtils.isWhitespace(page.substring(indexTo + endJsonPattern.length()))) { page = page.substring(indexFrom + 1, indexTo); setContentType(CONTENT_TYPE_JSON); } } else { page = page.substring(indexFrom + 1, indexTo); setContentType(CONTENT_TYPE_JSON); } } } } else { startIndex = html.indexOf(startXmlPattern); if (startIndex >= 0) { int indexFrom = page.indexOf('>', startIndex); if (indexFrom >= 0) { int indexTo = html.lastIndexOf(endXmlPattern); if (indexTo >= 0) { if (page.length() > indexTo) { if (StringUtils.isWhitespace(page.substring(indexTo + endXmlPattern.length()))) { page = page.substring(indexFrom + 1, indexTo); setContentType(CONTENT_TYPE_XML); } } else { page = page.substring(indexFrom + 1, indexTo); setContentType(CONTENT_TYPE_XML); } } } } else { startIndex = html.indexOf(startHtmlPattern); if (startIndex >= 0) { int indexFrom = page.indexOf('>', startIndex); if (indexFrom >= 0) { int indexTo = html.lastIndexOf(endHtmlPattern); if (indexTo >= 0) { if (page.length() > indexTo) { if (StringUtils.isWhitespace(page.substring(indexTo + endHtmlPattern.length()))) { page = page.substring(indexFrom + 1, indexTo); //setContentType(CONTENT_TYPE_HTML); } } else { page = page.substring(indexFrom + 1, indexTo); //setContentType(CONTENT_TYPE_HTML); } } } } } } return page; }
From source file:org.xmlactions.pager.actions.highlighter.HighlighterAction.java
private boolean hasContent(XMLObject xo) { if (xo.getContent() == null) { return false; }/* w w w . j av a 2 s . c o m*/ return !StringUtils.isWhitespace(xo.getContent()); }
From source file:solidbase.config.Configuration.java
/** * Returns the first configuration error for display. * * @return The first configuration error. *///from www .j a v a2 s . co m public String getFirstError() { Database database = this.defaultDatabase; if (database != null) { if (StringUtils.isBlank(database.driver)) return "Missing 'connection.driver' or -driver"; if (StringUtils.isBlank(database.url)) return "Missing 'connection.url' or -url"; if (StringUtils.isBlank(database.userName)) return "Missing 'connection.username' or -username"; if (StringUtils.isBlank(this.upgradeFile) && StringUtils.isBlank(this.sqlFile)) return "Missing 'upgrade.file', -upgradefile, 'sql.file' or -sqlfile"; if (!StringUtils.isBlank(this.sqlFile) && !StringUtils.isBlank(this.target)) return "'upgrade.target', -target is not allowed in combination with 'sql.file', -sqlfile"; for (Database secondary : this.secondaryDatabases.values()) { // Driver and url are inherited, so they can be null but not blank if (StringUtils.isWhitespace(secondary.driver)) return "Missing 'connection." + secondary.name + ".driver'"; if (StringUtils.isWhitespace(secondary.url)) return "Missing 'connection." + secondary.name + ".url'"; if (StringUtils.isBlank(secondary.userName)) return "Missing 'connection." + secondary.name + ".username'"; } } else { if (!StringUtils.isBlank(this.sqlFile)) return "'sql.file' property or -sqlfile commandline option specified but no database configured"; if (!StringUtils.isBlank(this.upgradeFile)) return "'upgrade.file' property or -upgradefile commandline option specified but no database configured"; if (!StringUtils.isBlank(this.target)) return "'upgrade.target' property or -target commandline option specified but no database configured"; } return null; }
From source file:tds.itempreview.ConfigBuilder.java
private Config buildConfigPages(Collection<ITSGroups> itsGroupsList) { boolean ignorePassages = ItemPreviewSettings.getIgnorePassages().getValue(); String passageLayout = ItemPreviewSettings.getPassageLayout().getValue(); boolean passageReplace = ignorePassages && !(StringUtils.isEmpty(passageLayout) || StringUtils.isWhitespace(passageLayout)); Config config = new Config(); config.setSections(new ArrayList<Section>()); config.setPages(new ArrayList<Page>()); for (ITSGroups itsGroups : itsGroupsList) { ITSGroup firstGroup = itsGroups == null || itsGroups.size() == 0 ? null : itsGroups.get(0); if (firstGroup == null) continue; String sectionLbl = firstGroup.getGroupingText(); String sectionID = StringUtils.replace(sectionLbl, " ", ""); // create section Section configSection = new Section(); configSection.setId(sectionID);/*from w w w . j a v a2 s .c om*/ configSection.setLabel(sectionLbl); config.getSections().add(configSection); // create pages for (ITSGroup itsGroup : itsGroups) { Page configPage = new Page(); // configPage.ID = itsGroup.GroupID; configPage.setLabel(itsGroup.getLabel()); configPage.setSectionId(configSection.getId()); // create passage if (itsGroup.getPassage() != null) { Content configPassage = new Content(); setDocumentInfo(configPassage, itsGroup.getPassage()); configPage.setPassage(configPassage); } // create items if (itsGroup.getItems() != null && itsGroup.getItems().size() > 0) { configPage.setItems(new ArrayList<Item>()); for (IITSDocument itsItem : itsGroup.getItems()) { Item configItem = new Item(); setDocumentInfo(configItem, itsItem); configPage.getItems().add(configItem); // check if replace passage layout if (passageReplace && itsGroup.getItems().size() == 1 && itsItem.getStimulusKey() > 0) { configPage.setLayoutName(passageLayout); } } } config.getPages().add(configPage); } } return config; }