private List<String> readLines(String content) { String[] lines = StringUtils.splitPreserveAllTokens(content, "\n"); for (int i = 0; i < lines.length; i++) { String line = lines[i]; lines[i] = StringUtils.stripEnd(line, "\r"); } return Arrays.asList(lines); }
/** * @param binaryName Name of one of the kdu_* binaries * @return */ private static String getPath(String binaryName) { String path = Configuration.getInstance().getString(PATH_TO_BINARIES_CONFIG_KEY); if (path != null && path.length() > 0) { path = StringUtils.stripEnd(path, File.separator) + File.separator + binaryName; } else { path = binaryName; } return path; }
private String prefixedWithDefaultUrl(String url) { Optional<String> declaredDefaultUrl = getDeclaredDefaultUrl(); if (declaredDefaultUrl.isPresent() && isARelativeUrl(url)) { return StringUtils.stripEnd(declaredDefaultUrl.get(), "/") + "/" + StringUtils.stripStart(url, "/"); } else { return url; } }
/** Pop the most recent HTML tag from the lexer stack. */ protected void popTag(String tagType) throws ParserException { if (this.tagStack.size() <= 1) { logger.warn( "popTag called on an empty tag stack or on the root stack element. Please report this error on jamwiki.org, and provide the wiki syntax for the topic being parsed."); } if (!this.peekTag().getTagType().equals(tagType)) { // handle the case where the tag being popped is not the current tag on // the stack. this can happen with mis-matched HTML // ("<u><strong>text</u></strong>"), tags that aren't automatically // closed, and other more random scenarios. this.popMismatchedTag(tagType); return; } JFlexTagItem currentTag = this.peekTag(); if (this.tagStack.size() > 1) { // only pop if not the root tag currentTag = this.tagStack.pop(); } CharSequence html = currentTag.toHtml(); if (StringUtils.isBlank(html)) { // if the tag results in no content being generated then there is // nothing more to do. return; } JFlexTagItem previousTag = this.peekTag(); if (!currentTag.isInlineTag() || currentTag.getTagType().equals("pre")) { // if the current tag is not an inline tag, make sure it is on its own lines if (previousTag.getTagContent().length() > 0 && Character.isWhitespace( previousTag.getTagContent().charAt(previousTag.getTagContent().length() - 1))) { String trimmedContent = StringUtils.stripEnd(previousTag.getTagContent().toString(), null); previousTag .getTagContent() .delete(trimmedContent.length(), previousTag.getTagContent().length()); } previousTag.getTagContent().append('\n'); previousTag.getTagContent().append(html); previousTag.getTagContent().append('\n'); } else { previousTag.getTagContent().append(html); } if (PARAGRAPH_OPEN_LOCATION_LIST.containsKey(tagType)) { // force a paragraph open after block tags. this tag may not actually // end up in the final output if there aren't any newlines in the // wikitext after the block tag. make sure that PARAGRAPH_OPEN_LOCATION_LIST // does not contain "p", otherwise we loop infinitely. this.pushTag("p", null); } }