UWC - trac improvements: attachment handling for images with uri encoding, images with size attributes, horizontal rule. Adjust build so dist dir is in root directory
diff --git a/build.xml b/build.xml
index ea80365..f4a2f5c 100644
--- a/build.xml
+++ b/build.xml
@@ -217,7 +217,8 @@
<delete dir="target/uwc/output"/>
<antcall target="CreateExecutableJarFileWithExternalLibrary"/>
- <zip basedir="target" excludes="uwc/classes/**, uwc/lib/**, target/uwc/lib/**" excludesfile="bin/run_uwc_devel.sh" destfile="../dist/uwc.zip"/>
+ <mkdir dir="./dist"/>
+ <zip basedir="target" excludes="uwc/classes/**, uwc/lib/**, target/uwc/lib/**" excludesfile="bin/run_uwc_devel.sh" destfile="./dist/uwc.zip"/>
</target>
<target name="CreateExecutableJarFileWithExternalLibrary">
@@ -286,7 +287,7 @@
</target>
<target name="package-spoof" description="Create spoof jar for use with APR">
- <jar jarfile="../dist/uwc-spoof.jar">
+ <jar jarfile="./dist/uwc-spoof.jar">
<fileset dir="./src/etc"/>
</jar>
</target>
diff --git a/conf/converter.trac.properties b/conf/converter.trac.properties
index 959cf60..49f1258 100644
--- a/conf/converter.trac.properties
+++ b/conf/converter.trac.properties
@@ -19,6 +19,9 @@
Trac.0030-graphviz.java-regex-tokenizer=(?s)\{\{\{\s*#!graphviz\s*digraph[^\{]+\{(.*?)\}\s*\}\}\}{replace-with}{flowchart}$1{flowchart}
Trac.0050-preformatted.java-regex-tokenizer=(?ms)^\{{3}(.*?)^\}{3}{replace-multiline-with}{noformat}$1{noformat}
+# hide horizontal rules so they dont get transformed
+Trac.0055-hr.java-regex-tokenizer=(?<=^|\n)([-]{4})(?=\n){replace-with}$1
+
# Escape characters that have a special meaning in Confluence
Trac.0060-escape_exclamation_marks.java-regex=!{replace-with}\\!
Trac.0061-escape_minus_at_beginning.java-regex=(\s)\-{replace-with}$1\\-
@@ -61,6 +64,8 @@
Trac.0600-macro_image_attachment_external.java-regex=(?i)\[\[Image\(http(?:.*?)raw-attachment\/wiki\/([^\)]+)\)\]\]{replace-with}!$1!
Trac.0601-macro_image_on_other_page.java-regex=(?i)\[\[Image\(wiki:([^:]+):([^\)]+)\)\]\]{replace-with}[[Image($1^$2)]]
Trac.0602-macro_image_attachment.java-regex=(?i)\[\[Image\(([^\)]+)\)\]\]{replace-with}!$1!
+Trac.0603-image_params1.java-regex=(?<!\\)!([^!,]+),\s*(\w[^!]+)(?<!\\)!{replace-with}!$1|$2!
+Trac.0604-image_params2.class=com.atlassian.uwc.converters.trac.ImageParamConverter
Trac.0640-pageoutline-toc.java-regex=(?i)\[\[PageOutline(\([^\)]+\))?\]\]{replace-with}{toc}
Trac.0650-macro_br.java-regex=(?i)\[\[BR\]\] ?{replace-with}NEWLINE
Trac.0660-doublebracket-links.java-regex=\[{2}([^\]]+)\]{2}{replace-with}[$1]
diff --git a/sampleData/trac/SampleTrac-ExpectedImage.txt b/sampleData/trac/SampleTrac-ExpectedImage.txt
index 8be97cb..a944905 100644
--- a/sampleData/trac/SampleTrac-ExpectedImage.txt
+++ b/sampleData/trac/SampleTrac-ExpectedImage.txt
@@ -9,3 +9,7 @@
external link (but still internal image)
!PageTitle^file.png!
!Subpage^file.png!
+
+image with parameters
+!pagename^filename.png|width=230px,align=right!
+
diff --git a/sampleData/trac/SampleTrac-InputImage.txt b/sampleData/trac/SampleTrac-InputImage.txt
index 25f672a..7db31d7 100644
--- a/sampleData/trac/SampleTrac-InputImage.txt
+++ b/sampleData/trac/SampleTrac-InputImage.txt
@@ -9,3 +9,7 @@
external link (but still internal image)
[[Image(https://mytrac.com/context/raw-attachment/wiki/PageTitle/file.png)]]
[[Image(https://mytrac.com/context/raw-attachment/wiki/PageTitle/Subpage/file.png)]]
+
+image with parameters
+[[Image(wiki:pagename:filename.png, width=230px align=right)]]
+
diff --git a/src/com/atlassian/uwc/converters/trac/AttachmentConverter.java b/src/com/atlassian/uwc/converters/trac/AttachmentConverter.java
index cdc80c2..2acf542 100644
--- a/src/com/atlassian/uwc/converters/trac/AttachmentConverter.java
+++ b/src/com/atlassian/uwc/converters/trac/AttachmentConverter.java
@@ -1,11 +1,14 @@
package com.atlassian.uwc.converters.trac;
import java.io.File;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import com.atlassian.uwc.converters.BaseConverter;
import com.atlassian.uwc.converters.IllegalLinkNameConverter;
+import com.atlassian.uwc.converters.tikiwiki.RegexUtil;
import com.atlassian.uwc.ui.Page;
/**
@@ -25,8 +28,8 @@
log.info("Converting Trac Attachments -- complete");
}
-
- /**
+
+ /**
* determines which attachments are present for the specified page in the
* Trac attachments directory and attaches them all
* @param page object to attach pages to
@@ -45,8 +48,10 @@
}
for (File file : attachments) {
- if (file.isFile())
- page.addAttachment(file);
+ if (file.isFile()) {
+ String name = urldecode(file.getName());
+ page.addAttachment(file, name);
+ }
}
}
diff --git a/src/com/atlassian/uwc/converters/trac/ImageParamConverter.java b/src/com/atlassian/uwc/converters/trac/ImageParamConverter.java
new file mode 100644
index 0000000..00191cb
--- /dev/null
+++ b/src/com/atlassian/uwc/converters/trac/ImageParamConverter.java
@@ -0,0 +1,45 @@
+package com.atlassian.uwc.converters.trac;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.log4j.Logger;
+
+import com.atlassian.uwc.converters.BaseConverter;
+import com.atlassian.uwc.converters.tikiwiki.RegexUtil;
+import com.atlassian.uwc.ui.Page;
+
+public class ImageParamConverter extends BaseConverter {
+ Logger log = Logger.getLogger(this.getClass());
+
+ public void convert(Page page) {
+ log.info("Converting Trac Image Parameters -- starting");
+ String input = page.getOriginalText();
+ String converted = convertImageParams(input);
+ page.setConvertedText(converted);
+ log.info("Converting Trac Image Parameters -- complete");
+
+ }
+
+ Pattern image = Pattern.compile("(?<!\\\\)!([^!|]+\\|)([^!]+)(?<!\\\\)!");
+ private String convertImageParams(String input) {
+ Matcher imageFinder = image.matcher(input);
+ StringBuffer sb = new StringBuffer();
+ boolean found = false;
+ while (imageFinder.find()) {
+ found = true;
+ String filename = imageFinder.group(1);
+ String params = imageFinder.group(2);
+ params = params.replaceAll(" +", ",");
+ String replacement = "!" + filename + params +"!";
+ replacement = RegexUtil.handleEscapesInReplacement(replacement);
+ imageFinder.appendReplacement(sb, replacement);
+ }
+ if (found) {
+ imageFinder.appendTail(sb);
+ return sb.toString();
+ }
+ return input;
+ }
+
+}