package net.hillsdon.svnwiki.wiki;

import java.util.Arrays;

import net.hillsdon.svnwiki.vc.PageStore;
import net.hillsdon.svnwiki.vc.PageStoreException;

import org.radeox.api.engine.WikiRenderEngine;
import org.radeox.engine.BaseRenderEngine;
import org.radeox.util.Encoder;

public class SvnWikiRenderEngine extends BaseRenderEngine implements WikiRenderEngine {

  private final PageStore _store;

  public SvnWikiRenderEngine(final PageStore store) {
    _store = store;
  }

  @Override
  public boolean exists(final String name) {
    try {
      // TODO: make this more efficient!
      return Arrays.asList(_store.list()).contains(name);
    }
    catch (PageStoreException e) {
      throw new RuntimeException(e);
    }
  }
  
  @Override
  public void appendCreateLink(final StringBuffer buffer, final String name, final String view) {
    appendLink(buffer, name, view);
  }

  @Override
  public void appendLink(final StringBuffer buffer, final String name, final String view) {
    buffer.append(String.format("<a href='%s'>%s</a>", Encoder.escape(name), Encoder.escape(view)));
  }

  @Override
  public void appendLink(final StringBuffer buffer, final String name, final String view, final String anchor) {
    buffer.append(String.format("<a href='%s#%s'>%s</a>", Encoder.escape(name), Encoder.escape(anchor), Encoder.escape(view)));
  }

  @Override
  public boolean showCreate() {
    return true;
  }
  
}

@@ -272,16 +272,123 @@
 coder;%0A%0A
+/**%0A * Customize the Radeox rendering engine to produce correct links for our wiki.%0A * %0A * @author mth%0A */%0A
 public c
@@ -957,38 +957,120 @@
     
-appendLink(buffer, 
+buffer.append(String.format(%22%3Ca class='new-page' href='%25s'%3E%25s%3C/a%3E%22, Encoder.escape(
 name
+)
 , 
+Encoder.escape(
 view)
+))
 ;%0A  
@@ -1203,32 +1203,54 @@
 tring.format(%22%3Ca
+ class='existing-page'
  href='%25s'%3E%25s%3C/a
@@ -1464,16 +1464,38 @@
 rmat(%22%3Ca
+ class='existing-page'
  href='%25

Add CSS classes to the links to indicate if they point to an existing page or not.