[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/util ...
Christian Bauer
christian at hibernate.org
Fri Nov 9 10:08:27 EST 2007
User: cbauer
Date: 07/11/09 10:08:27
Modified: examples/wiki/src/main/org/jboss/seam/wiki/util
WikiUtil.java
Log:
Various updates to core classes and views, required for forum plugin
Revision Changes Path
1.19 +59 -7 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/util/WikiUtil.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: WikiUtil.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/util/WikiUtil.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- WikiUtil.java 12 Oct 2007 16:31:30 -0000 1.18
+++ WikiUtil.java 9 Nov 2007 15:08:27 -0000 1.19
@@ -24,7 +24,10 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Date;
+import java.util.regex.Pattern;
import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
/**
* Adds stuff to and for JSF that should be there but isn't. Also stuff that is exposed
@@ -110,28 +113,53 @@
}
public static String renderURL(Node node) {
+ return renderURL(node, null);
+ }
+
+ public static String renderURL(Node node, Comment comment) {
if (isFile(node)) return renderFileLink((File)node);
WikiPreferences wikiPrefs = (WikiPreferences) Component.getInstance("wikiPreferences");
if (wikiPrefs.isRenderPermlinks()) {
- return renderPermLink(node);
+ return renderPermLink(node, comment);
} else {
- return renderWikiLink(node);
+ return renderWikiLink(node, comment);
}
}
public static String renderPermLink(Node node) {
+ return renderPermLink(node, null);
+ }
+
+ public static String renderPermLink(Node node, Comment comment) {
if (node == null || node.getId() == null) return "";
if (isFile(node)) return renderFileLink((File)node);
WikiPreferences prefs = (WikiPreferences)Component.getInstance("wikiPreferences");
- return prefs.getBaseUrl() + "/" + node.getId() + prefs.getPermlinkSuffix();
+ StringBuilder url = new StringBuilder();
+ url.append(prefs.getBaseUrl());
+ if (!prefs.getBaseUrl().endsWith("/")) url.append("/");
+ url.append(node.getId());
+ url.append(prefs.getPermlinkSuffix());
+ if (comment != null) url.append("#comment").append(comment.getId());
+ return url.toString();
}
public static String renderWikiLink(Node node) {
+ return renderWikiLink(node, null);
+ }
+
+ public static String renderWikiLink(Node node, Comment comment) {
if (node == null || node.getId() == null) return "";
WikiPreferences prefs = (WikiPreferences)Component.getInstance("wikiPreferences");
- if (node.getArea().getWikiname().equals(node.getWikiname()))
- return prefs.getBaseUrl() + "/" + node.getArea().getWikiname();
- return prefs.getBaseUrl() + "/" + node.getArea().getWikiname() + "/" + node.getWikiname();
+ StringBuilder url = new StringBuilder();
+ url.append(prefs.getBaseUrl());
+ if (!prefs.getBaseUrl().endsWith("/")) url.append("/");
+ if (node.getArea().getWikiname().equals(node.getWikiname())) {
+ url.append(node.getArea().getWikiname());
+ } else {
+ url.append(node.getArea().getWikiname()).append("/").append(node.getWikiname());
+ }
+ if (comment != null) url.append("#comment").append(comment.getId());
+ return url.toString();
}
private static String renderFileLink(File file) {
@@ -207,6 +235,12 @@
return sb.toString();
}
+ public static String removeMacros(String string) {
+ String REGEX_MACRO = Pattern.quote("[") + "<=[a-z]{1}?[a-zA-Z0-9]+?" + Pattern.quote("]");
+ return string.replaceAll(REGEX_MACRO, "");
+
+ }
+
// TODO: This would be the job of a more flexible seam text parser...
public static String disableFloats(String string) {
return string.replaceAll("float:\\s?(right)|(left)", "float:none")
@@ -296,12 +330,30 @@
return spaces.toString();
}
+ public static String formatDate(Date date) {
+ SimpleDateFormat fmt = new SimpleDateFormat("MMM dd, yyyy hh:mm aaa");
+ return fmt.format(date);
+ }
+
+ public static String attachSignature(String wikiText, String sig) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(wikiText).append("\n\n-- ").append(sig);
+ return builder.toString();
+ }
+
+ public static boolean isRegularUser(User user) {
+ User guestUser = (User)Component.getInstance("guestUser");
+ User adminUser = (User)Component.getInstance("adminUser");
+ if (user.getId().equals(guestUser.getId()) || user.getId().equals(adminUser.getId())) return false;
+ return true;
+ }
+
/**
* Used for conditional rendering of JSF messages, again, inflexible EL can't take value bindings with arguments
* or support simple String concat...
*/
public static boolean hasMessage(String namingContainer, String componentId) {
- return FacesContext.getCurrentInstance().getMessages(namingContainer + ":" + componentId).hasNext();
+ return FacesContext.getCurrentInstance().getMessages(namingContainer.replaceAll("\\\\", "") + ":" + componentId).hasNext();
}
}
More information about the jboss-cvs-commits
mailing list