1 package org.plog4u.wiki.filter;
4 import java.io.IOException;
6 import java.util.Arrays;
8 public class FilterUtil {
9 public static String getImageRoot() {
10 return "theme/images";
13 public static String getSpaceRoot() {
17 public static String getExecRoot() {
21 public static String getCommentsRoot() {
25 private static List extensions = Arrays.asList(new String[] { "png", "jpg", "jpeg", "gif" });
27 public static String normalizeServerImageName(String wikiLink) {
28 wikiLink = wikiLink.replaceAll(":", "/");
29 return wikiLink.replaceAll(" ", "_");
32 public static String createServerImage(String location, String name, String extension, boolean createHTMLLevel, int level) {
33 StringBuffer filename = new StringBuffer();
34 if (location != null) {
35 filename.append(location);
38 String normalized = normalizeServerImageName(name);
40 if (location == null && createHTMLLevel) {
41 for (int i = 0; i < level; i++) {
42 filename.append("../");
46 filename.append(normalized);
47 if (!normalized.startsWith("Image/") && extension != null) {
49 filename.append(extension);
51 return filename.toString();
54 public static String createServerImage(String location, String name, String extension) {
55 return createServerImage(location, name, extension, false, 0);
58 public static String createHTMLLink(String location, String name, String extension, boolean createHTMLLevel, int level) {
59 StringBuffer filename = new StringBuffer();
60 if (location != null) {
61 filename.append(location);
64 // System.out.println(filename);
65 String normalized = FilterUtil.normalizeWikiLink(name);
67 if (location == null && createHTMLLevel) {
68 for (int i = 0; i < level; i++) {
69 filename.append("../");
73 filename.append(normalized);
74 if (!normalized.startsWith("Image/")) {
76 filename.append(extension);
78 return filename.toString();
81 public static String createHTMLLink(String location, String name, String extension) {
82 return createHTMLLink(location, name, extension, false, 0);
85 public static String normalizeWikiLink(String wikiLink) {
86 if (wikiLink.length() > 0) {
87 int index = wikiLink.lastIndexOf('/');
89 if (wikiLink.length() == index + 1) {
90 wikiLink = wikiLink.substring(0, index + 1) + wikiLink.substring(index + 1, 1).toUpperCase();
91 } else if (wikiLink.length() > index + 1) {
92 wikiLink = wikiLink.substring(0, index + 1) + wikiLink.substring(index + 1, index + 2).toUpperCase()
93 + wikiLink.substring(index + 2);
96 if (wikiLink.length() > 1) {
97 wikiLink = wikiLink.substring(0, 1).toUpperCase() + wikiLink.substring(1);
99 wikiLink = wikiLink.substring(0, 1).toUpperCase();
103 wikiLink = wikiLink.replaceAll(":", "/");
104 return wikiLink.replaceAll(" ", "_");