/** * Simply concatenate the serialized form of each BlockContent contained in the given bloc. * * @param wikiElement Block to serialize. * @param dispatcher Dispatcher used to call the correct serialization for each content * @return serialized form of the given wikiElement. */ public static String render(Block wikiElement, WikiTextElementDispatcher dispatcher) { String prefix = ""; // If the given block has style and is not a TableCell, we have to render it with a prefix. if (!(wikiElement instanceof TableCell) && (AttributeStyleSerializer.renderAttributeForBloc(wikiElement.getAttributes()).length() > 0)) { prefix = WikiTextResourceSerializer.LINE_BREAK + PARAGRAPH_PREFIX + " " + WikiTextResourceSerializer.LINE_BREAK; return renderWithBlocPrefix(wikiElement, dispatcher, prefix) + WikiTextResourceSerializer.LINE_BREAK; } else { if (lastElementWasParagraph(wikiElement)) { prefix = WikiTextResourceSerializer.LINE_BREAK; } } return renderWithBlocPrefix(wikiElement, dispatcher, prefix); }
/** * Return the string corresponding to the serialized form of the prefix and the styles of the * given bloc. * * @param block block to render * @param blockPrefix prefix of this bloc. * @return the string corresponding to the serialized form of the prefix and the styles of the * given bloc. */ private static String renderPrefixAndStyle(Block block, String blockPrefix) { String renderedPrefixAndStyle = ""; if (blockPrefix.length() > 0) { String blockPrefixEnd = ""; // We first get the beginning of the blockPrefix. if (blockPrefix.contains(DOT)) { blockPrefixEnd = blockPrefix.substring(blockPrefix.indexOf(DOT), blockPrefix.length()); renderedPrefixAndStyle = blockPrefix.substring(0, blockPrefix.indexOf(DOT)); } else { renderedPrefixAndStyle = blockPrefix; } // Now that we have the prefix, we insert the style renderedPrefixAndStyle += AttributeStyleSerializer.renderAttributeForBloc(block.getAttributes()); // We redress the dots at the end of the blockPrefix renderedPrefixAndStyle += blockPrefixEnd; } return renderedPrefixAndStyle; }