예제 #1
0
  /** {@inheritDoc} */
  @Override
  public final int doWikiStartTag() throws IOException {
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage page = m_wikiContext.getPage();

    if (page != null) {
      if (page instanceof Attachment) {
        pageContext.getOut().print(engine.beautifyTitle(((Attachment) page).getParentName()));
      } else {
        String name = page.getName();

        int entrystart = name.indexOf("_blogentry_");

        if (entrystart != -1) {
          name = name.substring(0, entrystart);
        }

        int commentstart = name.indexOf("_comments_");

        if (commentstart != -1) {
          name = name.substring(0, commentstart);
        }

        pageContext.getOut().print(engine.beautifyTitle(name));
      }
    }

    return SKIP_BODY;
  }
  /**
   * Makes WikiText from a Collection.
   *
   * @param links Collection to make into WikiText.
   * @param separator Separator string to use.
   * @param numItems How many items to show.
   * @return The WikiText
   */
  protected String wikitizeCollection(Collection links, String separator, int numItems) {
    if (links == null || links.isEmpty()) return "";

    StringBuffer output = new StringBuffer();

    Iterator it = links.iterator();
    int count = 0;

    //
    // The output will be B Item[1] A S B Item[2] A S B Item[3] A
    //
    while (it.hasNext() && ((count < numItems) || (numItems == ALL_ITEMS))) {
      String value = (String) it.next();

      if (count > 0) {
        output.append(m_after);
        output.append(m_separator);
      }

      output.append(m_before);

      // Make a Wiki markup link. See TranslatorReader.
      output.append("[" + m_engine.beautifyTitle(value) + "|" + value + "]");
      count++;
    }

    //
    // Output final item - if there have been none, no "after" is printed
    //
    if (count > 0) output.append(m_after);

    return output.toString();
  }