List of usage examples for org.apache.commons.lang3 StringUtils repeat
public static String repeat(final char ch, final int repeat)
From source file:org.xwiki.rendering.internal.renderer.xwiki20.XWikiSyntaxChainingRenderer.java
@Override public void endHeader(HeaderLevel level, String id, Map<String, String> parameters) { print(" " + StringUtils.repeat("=", level.getAsInt())); }
From source file:org.xwiki.rendering.internal.renderer.xwiki20.XWikiSyntaxChainingRenderer.java
@Override public void onEmptyLines(int count) { print(StringUtils.repeat('\n', count)); }
From source file:org.xwiki.rendering.internal.renderer.xwiki20.XWikiSyntaxChainingRenderer.java
/** * {@inheritDoc}/* w w w . ja v a 2s.co m*/ * @since 1.6M2 */ @Override public void beginDefinitionTerm() { if (getBlockState().getDefinitionListItemIndex() > 0) { getPrinter().print("\n"); } if (this.listStyle.length() > 0) { print(this.listStyle.toString()); if (this.listStyle.charAt(0) == '1') { print("."); } } print(StringUtils.repeat(':', getBlockState().getDefinitionListDepth() - 1)); print("; "); }
From source file:org.xwiki.rendering.internal.renderer.xwiki20.XWikiSyntaxChainingRenderer.java
/** * {@inheritDoc}/*from ww w .j a v a 2s. c om*/ * @since 1.6M2 */ @Override public void beginDefinitionDescription() { if (getBlockState().getDefinitionListItemIndex() > 0) { getPrinter().print("\n"); } if (this.listStyle.length() > 0) { print(this.listStyle.toString()); if (this.listStyle.charAt(0) == '1') { print("."); } } print(StringUtils.repeat(':', getBlockState().getDefinitionListDepth() - 1)); print(": "); }
From source file:org.xwiki.rendering.internal.renderer.xwiki20.XWikiSyntaxChainingRenderer.java
/** * {@inheritDoc}/*from www. jav a2 s . c o m*/ * @since 1.6M2 */ @Override public void beginQuotationLine() { if (getBlockState().getQuotationLineIndex() > 0) { getPrinter().print("\n"); } print(StringUtils.repeat('>', getBlockState().getQuotationDepth())); }
From source file:org.xwiki.rendering.internal.renderer.xwiki20.XWikiSyntaxEscapeHandler.java
public void escape(StringBuffer accumulatedBuffer, XWikiSyntaxListenerChain listenerChain, boolean escapeLastChar, Pattern escapeFirstIfMatching) { BlockStateChainingListener blockStateListener = listenerChain.getBlockStateChainingListener(); // Escape tilde symbol (i.e. the escape character). // Note: This needs to be the first replacement since other replacements below also use the tilde symbol replaceAll(accumulatedBuffer, ESCAPE_CHAR, ESCAPE_CHAR + ESCAPE_CHAR); // Escape anything that looks like starting of custom parameters replaceAll(accumulatedBuffer, "(%", ESCAPE_CHAR + "(%"); // When in a paragraph we need to escape symbols that are at beginning of lines and that could be confused // with list items, headers or tables. if (blockStateListener.isInLine() && isOnNewLine()) { // Look for list pattern at beginning of line and escape the first character only (it's enough) escapeFirstMatchedCharacter(LIST_PATTERN, accumulatedBuffer); // Look for header pattern at beginning of line and escape the first character only (it's enough) escapeFirstMatchedCharacter(HEADER_PATTERN, accumulatedBuffer); // Look for table character patterns at beginning of line and escape the first character only (it's enough) escapeFirstMatchedCharacter(TABLE_PATTERN, accumulatedBuffer); // Look for quote pattern at beginning of line and escape the first character only (it's enough) escapeFirstMatchedCharacter(QUOTE_PATTERN, accumulatedBuffer); }/*from w ww . j av a 2 s . com*/ // Escape table characters if (blockStateListener.isInTable()) { replaceAll(accumulatedBuffer, "|", ESCAPE_CHAR + "|"); replaceAll(accumulatedBuffer, "!!", ESCAPE_CHAR + "!!"); } if (escapeFirstIfMatching != null) { escapeFirstMatchedCharacter(escapeFirstIfMatching, accumulatedBuffer); } // When in a header we need to escape "=" symbols since otherwise they would be confused for end of section // characters. if (blockStateListener.isInHeader()) { replaceAll(accumulatedBuffer, "=", ESCAPE_CHAR + "="); } // Escape verbatim "{{{" replaceAll(accumulatedBuffer, "{{{", ESCAPE_CHAR + "{" + ESCAPE_CHAR + "{" + ESCAPE_CHAR + "{"); // Escape "{{" replaceAll(accumulatedBuffer, "{{", ESCAPE_CHAR + "{" + ESCAPE_CHAR + "{"); // Escape groups replaceAll(accumulatedBuffer, "(((", ESCAPE_CHAR + "(" + ESCAPE_CHAR + "(" + ESCAPE_CHAR + "("); replaceAll(accumulatedBuffer, ")))", ESCAPE_CHAR + ")" + ESCAPE_CHAR + ")" + ESCAPE_CHAR + ")"); // Escape reserved keywords Matcher matcher = DOUBLE_CHARS_PATTERN.matcher(accumulatedBuffer.toString()); for (int i = 0; matcher.find(); i = i + 2) { accumulatedBuffer.replace(matcher.start() + i, matcher.end() + i, ESCAPE_CHAR + matcher.group().charAt(0) + ESCAPE_CHAR + matcher.group().charAt(1)); } // Escape ":" in "image:something", "attach:something" and "mailto:something" // Note: even though there are some restriction in the URI specification as to what character is valid after // the ":" character following the scheme we only check for characters greater than the space symbol for // simplicity. escapeURI(accumulatedBuffer, "image:"); escapeURI(accumulatedBuffer, "attach:"); escapeURI(accumulatedBuffer, "mailto:"); // Escape last character if we're told to do so. This is to handle cases such as: // - onWord("hello:") followed by onFormat(ITALIC) which would lead to "hello://" if the ":" wasn't escaped // - onWord("{") followed by onMacro() which would lead to "{{{" if the "{" wasn't escaped if (escapeLastChar) { accumulatedBuffer.insert(accumulatedBuffer.length() - 1, '~'); } // Escape begin link replaceAll(accumulatedBuffer, "[[", ESCAPE_CHAR + "[" + ESCAPE_CHAR + "["); // Escape link label int linkLevel = getLinkLevel(listenerChain); if (linkLevel > 0) { // This need to be done after anything else because link label add another level of escaping (escaped as // link label and then escaped as wiki content). String escape = StringUtils.repeat(ESCAPE_CHAR, linkLevel); replaceAll(accumulatedBuffer, ESCAPE_CHAR, escape + ESCAPE_CHAR); replaceAll(accumulatedBuffer, "]]", escape + "]" + escape + "]"); replaceAll(accumulatedBuffer, ">>", escape + ">" + escape + ">"); replaceAll(accumulatedBuffer, "||", escape + "|" + escape + "|"); } }
From source file:org.xwiki.rendering.internal.transformation.macro.MacroTransformationTest.java
/** * Test that we have a safeguard against infinite recursive macros. */// w ww. j ava 2 s .c o m @Test public void testInfiniteRecursionMacroTransform() throws Exception { String expected = "beginDocument\n" + StringUtils.repeat("beginMacroMarkerStandalone [testrecursivemacro] []\n", 1000) + "onMacroStandalone [testrecursivemacro] []\n" + StringUtils.repeat("endMacroMarkerStandalone [testrecursivemacro] []\n", 1000) + "endDocument"; XDOM dom = new XDOM(Arrays.asList( (Block) new MacroBlock("testrecursivemacro", Collections.<String, String>emptyMap(), false))); this.transformation.transform(dom, new TransformationContext(dom, Syntax.XWIKI_2_0)); WikiPrinter printer = new DefaultWikiPrinter(); BlockRenderer eventBlockRenderer = getComponentManager().getInstance(BlockRenderer.class, Syntax.EVENT_1_0.toIdString()); eventBlockRenderer.render(dom, printer); Assert.assertEquals(expected, printer.toString()); }
From source file:org.xwiki.rendering.parser.xwiki10.util.CleanUtil.java
/** * Check the provided string contains enough new lines at the beginning and add the need ones. * /* w w w . ja v a 2 s . com*/ * @param content the content to convert. * @param nb the number of new lines the string need to contains at the beginning. * @return the converted string. */ public static String setLeadingNewLines(String content, int nb) { String cleanedContent = content; Matcher matcher = STARTING_NLNOOUTPUT_GROUP_PATTERN.matcher(content); int foundNb = matcher.find() ? StringUtils.countMatches(matcher.group(0), "\n") : 0; if (foundNb < nb) { cleanedContent = StringUtils.repeat("\n", nb - foundNb) + content; } return cleanedContent; }
From source file:org.xwiki.rendering.parser.xwiki10.util.CleanUtil.java
/** * Check the provided string contains enough new lines at the end and add the need ones. * //from ww w .j ava2 s . c o m * @param content the content to convert. * @param nb the number of new lines the string need to contains at the end. * @return the converted string. */ public static String setTrailingNewLines(String content, int nb) { String cleanedContent = content; Matcher matcher = ENDING_NLNOOUTPUT_GROUP_PATTERN.matcher(content); int foundNb = matcher.find() ? StringUtils.countMatches(matcher.group(0), "\n") : 0; if (foundNb < nb) { cleanedContent = content + StringUtils.repeat("\n", nb - foundNb); } return cleanedContent; }
From source file:org.xwiki.rendering.parser.xwiki10.util.CleanUtil.java
/** * Check the provided string contains enough new lines at the end and add the need ones. * /* w w w . j a v a2 s. c o m*/ * @param content the content to convert. * @param nb the number of new lines the string need to contains at the end. */ public static void setTrailingNewLines(StringBuffer content, int nb) { Matcher matcher = ENDING_NLNOOUTPUT_GROUP_PATTERN.matcher(content); int foundNb = matcher.find() ? StringUtils.countMatches(matcher.group(0), "\n") : 0; if (foundNb < nb) { content.append(StringUtils.repeat("\n", nb - foundNb)); } }