예제 #1
0
  @Override
  public List<Block> execute(Object parameters, String content, MacroTransformationContext context)
      throws MacroExecutionException {
    XDOM parsedDom;
    // get a parser for the desired syntax identifier
    Parser parser = getSyntaxParser(context.getSyntax().toIdString());

    try {
      // parse the content of the wiki macro that has been injected by the component manager the
      // content of the macro call itself is ignored.
      parsedDom = parser.parse(new StringReader(content));
    } catch (ParseException e) {
      throw new MacroExecutionException(
          "Failed to parse content ["
              + content
              + "] with Syntax parser ["
              + parser.getSyntax()
              + "]",
          e);
    }

    List<MacroBlock> potentialCells = parsedDom.getChildrenByType(MacroBlock.class, false);
    int count = this.countCells(potentialCells);
    if (count == 0) {
      throw new MacroExecutionException(
          "TableRow macro expect at least one cell macro as first-level children");
    }

    // Make the actual cells, injecting <td> tags around cell macros
    this.makeCells(potentialCells);

    return Collections.singletonList((Block) parsedDom);
  }
예제 #2
0
  /** {@inheritDoc} */
  public List<Block> execute(
      SectionMacroParameters parameters, String content, MacroTransformationContext context)
      throws MacroExecutionException {
    XDOM parsedDom;

    // get a parser for the desired syntax identifier
    Parser parser = getSyntaxParser(context.getSyntax().toIdString());

    try {
      // parse the content of the wiki macro that has been injected by the
      // component manager
      // the content of the macro call itself is ignored.
      parsedDom = parser.parse(new StringReader(content));
    } catch (ParseException e) {
      throw new MacroExecutionException(
          "Failed to parse content ["
              + content
              + "] with Syntax parser ["
              + parser.getSyntax()
              + "]",
          e);
    }

    List<MacroBlock> potentialColumns = parsedDom.getChildrenByType(MacroBlock.class, false);

    int count = this.countColumns(potentialColumns);

    if (count == 0) {
      throw new MacroExecutionException(
          "Section macro expect at least one column macro as first-level children");
    }

    double computedColumnWidth = ((TOTAL_WIDTH - COLUMN_RIGHT_PADDING_RATE * (count - 1)) / count);

    // Make the actual columns injecting divs around column macros
    this.makeColumns(potentialColumns, computedColumnWidth);

    // finally, clear the floats introduced by the columns
    Map<String, String> clearFloatsParams = new HashMap<String, String>();
    clearFloatsParams.put(PARAMETER_STYLE, STYLE_CLEAR_BOTH);

    parsedDom.addChild(new GroupBlock(clearFloatsParams));

    Map<String, String> sectionParameters = new HashMap<String, String>();
    if (parameters.isJustify()) {
      sectionParameters.put(PARAMETER_STYLE, STYLE_TEXT_ALIGN_JUSTIFY);
    }

    Block sectionRoot = new GroupBlock(sectionParameters);
    sectionRoot.addChildren(parsedDom.getChildren());

    return Collections.singletonList(sectionRoot);
  }