/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.jme.ant;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.StringWriter;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
/**
*
* @author normenhansen
*/
public class FixWikiLinks extends Task {
File file;
String helpPath;
@Override
public void execute() throws BuildException {
validate();
BufferedReader rdr;
try {
rdr = new BufferedReader(new FileReader(file));
StringWriter out = new StringWriter();
String line = rdr.readLine();
while (line != null) {
//internal links
line = line.replaceAll("doku\\.php/([^>]*):([^>]*):([^>]*):([^>]*)\\?do=export_xhtmlbody", helpPath + "$1/$2/$3/$4.html");
line = line.replaceAll("doku\\.php/([^>]*):([^>]*):([^>]*)\\?do=export_xhtmlbody", helpPath + "$1/$2/$3.html");
line = line.replaceAll("doku\\.php/([^>]*):([^>]*)\\?do=export_xhtmlbody", helpPath + "$1/$2.html");
line = line.replaceAll("doku\\.php/([^>]*)\\?do=export_xhtmlbody", helpPath + "$1.html");
//images
line = line.replaceAll("/lib/exe/fetch\\.php/([^>]*):([^>]*):([^>]*):([^>]*)\"", "nbdocs:/" + helpPath + "$1/$2/$3/$4\"");
line = line.replaceAll("/lib/exe/fetch\\.php/([^>]*):([^>]*):([^>]*)\"", "nbdocs:/" + helpPath + "$1/$2/$3\"");
line = line.replaceAll("/lib/exe/fetch\\.php/([^>]*):([^>]*)\"", "nbdocs:/" + helpPath + "$1/$2\"");
line = line.replaceAll("/lib/exe/fetch\\.php/([^>]*)\"", "nbdocs:/" + helpPath + "$1\"");
// line = line.replaceAll("/lib/exe/fetch\\.php?([^>]*)\"", "nbdocs:/" + helpPath + "external/$1\"").replaceAll("[_[^\\w\\däüö:ÄÜÖ\\/\\+\\-\\. ]]", "_");
line = line.replaceAll("]*)>]*)>", "");
line = line.replaceAll("]*)\\?([^>]*)\">", "");
// vvvv------v
//line=line.replaceAll("]*)>(.*(?))","$2");
//remove class, name and id from tags
line = line.replaceAll(" class=\"([^>]*)\">", ">");
line = line.replaceAll(" name=\"([^>]*)\">", ">");
line = line.replaceAll(" id=\"([^>]*)\">", ">");
//remove obnoxious spans using negative look-behind..
line = line.replaceAll("([^>]*)", "$1");
//remove links to http://www.google.com/search added by wiki
line = line.replaceAll("(.*)", "$3");
//make external links netbeans help external links
// line = line.replaceAll("(.*)", "