[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui ...
Christian Bauer
christian at hibernate.org
Fri Jul 6 10:38:38 EDT 2007
User: cbauer
Date: 07/07/06 10:38:38
Modified: examples/wiki/src/main/org/jboss/seam/wiki/core/ui
UIWikiFormattedText.java
WikiFormattedTextHandler.java
Log:
Compiles and runs on latest Seam CVS
Revision Changes Path
1.25 +33 -12 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/UIWikiFormattedText.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIWikiFormattedText.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/UIWikiFormattedText.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- UIWikiFormattedText.java 21 Jun 2007 11:05:48 -0000 1.24
+++ UIWikiFormattedText.java 6 Jul 2007 14:38:38 -0000 1.25
@@ -9,19 +9,33 @@
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import javax.el.ExpressionFactory;
import org.jboss.seam.Component;
+import org.jboss.seam.el.SeamExpressionFactory;
import org.jboss.seam.ui.util.JSF;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.core.Conversation;
+import org.jboss.seam.core.Expressions;
import org.jboss.seam.wiki.core.engine.WikiLink;
import org.jboss.seam.wiki.core.engine.WikiTextParser;
import org.jboss.seam.wiki.core.engine.WikiTextRenderer;
+import org.jboss.seam.wiki.core.engine.WikiLinkResolver;
import org.jboss.seam.wiki.core.model.File;
+import org.jboss.seam.wiki.core.model.Document;
+import org.jboss.seam.wiki.core.model.Directory;
import org.jboss.seam.wiki.util.WikiUtil;
public class UIWikiFormattedText extends UIOutput {
+ public static final String ATTR_LINK_STYLE_CLASS = "linkStyleClass";
+ public static final String ATTR_BROKEN_LINK_STYLE_CLASS = "brokenLinkStyleClass";
+ public static final String ATTR_ATTACHMENT_LINK_STYLE_CLASS = "attachmentLinkStyleClass";
+ public static final String ATTR_THUMBNAIL_LINK_STYLE_CLASS = "thumbnailLinkStyleClass";
+ public static final String ATTR_UPDATE_RESOLVED_LINKS = "updateResolvedLinks";
+ public static final String ATTR_RENDER_BASE_DOCUMENT = "renderBaseDocument";
+ public static final String ATTR_RENDER_BASE_DIRECTORY = "renderBaseDirectory";
+
private List<String> plugins;
public static final String COMPONENT_FAMILY = "org.jboss.seam.wiki.core.ui.UIWikiFormattedText";
@@ -55,6 +69,14 @@
// Use the WikiTextParser to resolve macros
WikiTextParser parser = new WikiTextParser((String) getValue(), false, true);
+ // Resolve the base document and directory we are resolving against
+ final Document baseDocument = (Document)getAttributes().get(ATTR_RENDER_BASE_DOCUMENT);
+ final Directory baseDirectory = (Directory)getAttributes().get(ATTR_RENDER_BASE_DIRECTORY);
+ parser.setCurrentDocument(baseDocument);
+ parser.setCurrentDirectory(baseDirectory);
+
+ parser.setResolver((WikiLinkResolver)Component.getInstance("wikiLinkResolver"));
+
// Set a customized renderer for parser macro callbacks
parser.setRenderer(new WikiTextRenderer() {
@@ -62,8 +84,8 @@
return "<a href=\""
+ (inlineLink.isBroken() ? inlineLink.getUrl() : WikiUtil.renderURL(inlineLink.getNode()))
+ "\" class=\""
- + (inlineLink.isBroken() ? getAttributes().get("brokenLinkStyleClass")
- : getAttributes().get("linkStyleClass")) + "\">"
+ + (inlineLink.isBroken() ? getAttributes().get(ATTR_BROKEN_LINK_STYLE_CLASS)
+ : getAttributes().get(ATTR_LINK_STYLE_CLASS)) + "\">"
+ inlineLink.getDescription() + "</a>";
}
@@ -71,15 +93,16 @@
return "<a href=\""
+ externalLink.getUrl()
+ "\" class=\""
- + (externalLink.isBroken() ? getAttributes().get("brokenLinkStyleClass")
- : getAttributes().get("linkStyleClass")) + "\">"
+ + (externalLink.isBroken() ? getAttributes().get(ATTR_BROKEN_LINK_STYLE_CLASS)
+ : getAttributes().get(ATTR_LINK_STYLE_CLASS)) + "\">"
+ externalLink.getDescription() + "</a>";
}
public String renderFileAttachmentLink(int attachmentNumber, WikiLink attachmentLink) {
return "<a href=\""
+ + WikiUtil.renderURL(baseDocument)
+ "#attachment" + attachmentNumber + "\" class=\""
- + getAttributes().get("attachmentLinkStyleClass") + "\">"
+ + getAttributes().get(ATTR_ATTACHMENT_LINK_STYLE_CLASS) + "\">"
+ attachmentLink.getDescription() + "[" + attachmentNumber + "]" + "</a>";
}
@@ -105,7 +128,7 @@
return "<a href=\""
+ (inlineLink.isBroken() ? inlineLink.getUrl() : WikiUtil.renderURL(inlineLink
.getNode())) + "\" class=\""
- + getAttributes().get("thumbnailLinkStyleClass") + "\"><img src=\""
+ + getAttributes().get(ATTR_THUMBNAIL_LINK_STYLE_CLASS) + "\"><img src=\""
+ thumbnailUrl + "\"/></a>";
}
@@ -140,22 +163,20 @@
}
public void setAttachmentLinks(List<WikiLink> attachmentLinks) {
- // Put attachments (wiki links...) into the event context for later
- // rendering
+ // Put attachments (wiki links...) into the event context for later rendering
Contexts.getEventContext().set("wikiTextAttachments", attachmentLinks);
}
public void setExternalLinks(List<WikiLink> externalLinks) {
- // Put external links (to targets not on this wiki) into the event
- // context for later rendering
+ // Put external links (to targets not on this wiki) into the event context for later rendering
Contexts.getEventContext().set("wikiTextExternalLinks", externalLinks);
}
});
// Run the parser (default to true for updating resolved links)
Boolean updateResolvedLinks =
- getAttributes().get("updatedResolvedLinks") == null
- || Boolean.valueOf((String) getAttributes().get("updatedResolvedLinks"));
+ getAttributes().get(ATTR_UPDATE_RESOLVED_LINKS) == null
+ || Boolean.valueOf((String) getAttributes().get(ATTR_UPDATE_RESOLVED_LINKS));
parser.parse(updateResolvedLinks);
facesContext.getResponseWriter().write(parser.toString());
1.9 +16 -10 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiFormattedTextHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: WikiFormattedTextHandler.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiFormattedTextHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- WikiFormattedTextHandler.java 21 Jun 2007 11:05:48 -0000 1.8
+++ WikiFormattedTextHandler.java 6 Jul 2007 14:38:38 -0000 1.9
@@ -17,7 +17,6 @@
import org.jboss.seam.faces.ResourceLoader;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.ui.component.UILoadStyle;
-import org.jboss.seam.util.Resources;
import org.jboss.seam.wiki.core.action.PluginPreferenceEditor;
import org.jboss.seam.wiki.core.action.prefs.WikiPreferences;
@@ -80,17 +79,22 @@
@Override
protected void setAttributes(FaceletContext ctx, Object instance) {
UIComponent cmp = (UIComponent) instance;
- setAttribute(ctx, cmp, "linkStyleClass");
- setAttribute(ctx, cmp, "brokenLinkStyleClass");
- setAttribute(ctx, cmp, "attachmentLinkStyleClass");
- setAttribute(ctx, cmp, "thumbnailLinkStyleClass");
- setAttribute(ctx, cmp, "updateResolvedLinks");
+ setAttribute(ctx, cmp, UIWikiFormattedText.ATTR_LINK_STYLE_CLASS);
+ setAttribute(ctx, cmp, UIWikiFormattedText.ATTR_BROKEN_LINK_STYLE_CLASS);
+ setAttribute(ctx, cmp, UIWikiFormattedText.ATTR_ATTACHMENT_LINK_STYLE_CLASS);
+ setAttribute(ctx, cmp, UIWikiFormattedText.ATTR_THUMBNAIL_LINK_STYLE_CLASS);
+ setAttribute(ctx, cmp, UIWikiFormattedText.ATTR_UPDATE_RESOLVED_LINKS);
+ setAttribute(ctx, cmp, UIWikiFormattedText.ATTR_RENDER_BASE_DOCUMENT);
+ setAttribute(ctx, cmp, UIWikiFormattedText.ATTR_RENDER_BASE_DIRECTORY);
}
private void setAttribute(FaceletContext ctx, UIComponent cmp, String name) {
TagAttribute attribute = this.getAttribute(name);
- if (attribute != null)
- cmp.getAttributes().put(name, attribute.getObject(ctx));
+ if (attribute != null) {
+ Object o = attribute.getObject(ctx);
+ if (o == null) throw new IllegalArgumentException("Attribute '" + name + "' resolved to null");
+ cmp.getAttributes().put(name, o);
+ }
}
@Override
@@ -199,10 +203,12 @@
}
}
+ /*
+ * If this plugin has preferences and editing is enabled, instantiate a
+ * plugin preferences editor and put it in the PAGE context
+ */
private void createPreferencesEditor(String macroName) {
- // If this plugin has preferences and editing is enabled, instantiate a
- // plugin preferences editor and put it in the PAGE context
String pluginPreferenceName = macroName + "Preferences";
Boolean showPluginPreferences = (Boolean) Component.getInstance("showPluginPreferences");
Object existingEditor = Contexts.getConversationContext()
More information about the jboss-cvs-commits
mailing list