annotate src/org/nwoca/ssdt/tools/html2wiki/TagTransformer.java @ 4:22ed6d93442c

Start modifying transformers to Confluence wiki syntax
author smith@nwoca.org
date Tue, 25 Jan 2011 21:59:31 -0500
parents f8b1ea49d065
children
rev   line source
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
1 package org.nwoca.ssdt.tools.html2wiki;
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
2
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
3 import java.util.regex.*;
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
4
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
5 class TagTransformer implements Transformer {
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
6
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
7 private Pattern tagPattern;
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
8 private String replacementBegin;
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
9 private String replacementEnd;
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
10
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
11 public TagTransformer(String regexp, String replacementBegin, String replacementEnd) {
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
12 this(regexp, false, replacementBegin, replacementEnd);
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
13 }
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
14
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
15 public TagTransformer(String regexp, boolean multiline, String replacementBegin, String replacementEnd) {
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
16 tagPattern = multiline
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
17 ? Pattern.compile(regexp, Pattern.MULTILINE + Pattern.DOTALL)
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
18 : Pattern.compile(regexp);
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
19
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
20 this.replacementBegin = replacementBegin;
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
21 this.replacementEnd = replacementEnd;
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
22
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
23 }
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
24
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
25 public TagTransformer(String regexp, String replacement) {
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
26 this(regexp, replacement, replacement);
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
27 }
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
28
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
29 public void apply(StringBuffer buffer) {
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
30 Matcher matcher = tagPattern.matcher(buffer);
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
31
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
32 boolean first = true;
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
33 while (matcher.find(first ? 0 : matcher.start())) {
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
34 buffer.replace(matcher.start(), matcher.end(), replacementBegin + matcher.group(1) + replacementEnd);
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
35 first = false;
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
36 }
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
37
0
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
38 }
f8b1ea49d065 Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
smith@nwoca.org
parents:
diff changeset
39
4
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
40 public String toString() {
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
41 return "Replace: " + tagPattern.pattern() + " with " + replacementBegin + "..." + replacementEnd;
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
42 }
22ed6d93442c Start modifying transformers to Confluence wiki syntax
smith@nwoca.org
parents: 0
diff changeset
43 }