[jboss-cvs] JBossBlog SVN: r57 - in trunk/blog-core/src/java/org/jboss/blog: tools and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 12 20:00:11 EDT 2007
Author: adamw
Date: 2007-03-12 20:00:11 -0400 (Mon, 12 Mar 2007)
New Revision: 57
Added:
trunk/blog-core/src/java/org/jboss/blog/tools/
trunk/blog-core/src/java/org/jboss/blog/tools/BlogTools.java
trunk/blog-core/src/java/org/jboss/blog/tools/UITools.java
Log:
Build enhancement
Added: trunk/blog-core/src/java/org/jboss/blog/tools/BlogTools.java
===================================================================
--- trunk/blog-core/src/java/org/jboss/blog/tools/BlogTools.java (rev 0)
+++ trunk/blog-core/src/java/org/jboss/blog/tools/BlogTools.java 2007-03-13 00:00:11 UTC (rev 57)
@@ -0,0 +1,92 @@
+package org.jboss.blog.tools;
+
+import org.jboss.blog.service.BlogService;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.MBeanServerLocator;
+
+import javax.portlet.PortletRequest;
+import javax.faces.context.FacesContext;
+
+/**
+ * Various common and usefull functions.
+ * @author Adam Warski (adamw at aster.pl)
+ */
+public class BlogTools {
+ /**
+ * Using the given request object, tries to read a given portlet preference.
+ * @param req Request from which to read.
+ * @param prefName Name of the preference to read.
+ * @return Value of the given portlet preference or null, if the preference
+ * is not set.
+ */
+ public static String getPortletPreference(PortletRequest req, String prefName) {
+ return req.getPreferences().getValue(prefName, null);
+ }
+
+ /**
+ * Reads the given init parameter value..
+ * @param initParamName Name of the init parameter to read.
+ * @return Value of the given init parameter or null, if the init parameter
+ * is not set.
+ */
+ public static String getInitParam(String initParamName) {
+ return FacesContext.getCurrentInstance().getExternalContext().
+ getInitParameter(initParamName);
+ }
+
+ /**
+ * Checks if the given request object is of class PortletRequest and if not,
+ * throws an IllegalArgumentException.
+ * @param caller Caller of this function, which class's name will be
+ * included in the exception message.
+ * @param request Request object to cast.
+ * @return The given request object cast to PortletRequest.
+ * @throws IllegalArgumentException When the given request object is not of
+ * class PortletRequest.
+ */
+ public static PortletRequest castToPortletRequest(Object caller, Object request) {
+ if (!(request instanceof PortletRequest)) {
+ throw new IllegalArgumentException(caller.getClass().getName() +
+ " accepts only PortletRequest parameters, not of class: " +
+ (request == null ? "NULL" : request.getClass().getName()));
+ }
+
+ return (PortletRequest) request;
+ }
+
+ private static BlogService instance;
+
+ /**
+ *
+ * @return An instance of the blog service.
+ */
+ public static synchronized BlogService getBlogService() {
+ try {
+ if (instance == null) {
+ instance = (BlogService) MBeanProxyExt.create(
+ BlogService.class,
+ "blog:service=Main",
+ MBeanServerLocator.locate());
+ }
+
+ return instance;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Checks if the link is an outside link.
+ * @param link Link to check.
+ * @return True iff the given link is an outside link.
+ */
+ public static boolean isExternalLink(String link) {
+ if (link == null) {
+ return false;
+ }
+
+ link = link.trim();
+ return link.startsWith("http:") || link.startsWith("ftp:")
+ || link.startsWith("https:") || link.startsWith("file:");
+ }
+}
Added: trunk/blog-core/src/java/org/jboss/blog/tools/UITools.java
===================================================================
--- trunk/blog-core/src/java/org/jboss/blog/tools/UITools.java (rev 0)
+++ trunk/blog-core/src/java/org/jboss/blog/tools/UITools.java 2007-03-13 00:00:11 UTC (rev 57)
@@ -0,0 +1,49 @@
+package org.jboss.blog.tools;
+
+import org.jboss.blog.BlogName;
+
+import javax.faces.context.FacesContext;
+import javax.faces.application.FacesMessage;
+
+/**
+ * @author <a href="mailto:adamw at aster.pl">Adam Warski</a>
+ */
+public class UITools {
+ public static final String BLOG_VIEW = "blog_view";
+ public static final String POST_VIEW = "post_view";
+
+ public static final String BLOG_EDIT = "blog_edit";
+ public static final String BLOG_NEW = "blog_new";
+ public static final String BLOG_DEL = "blog_del";
+
+ public static final String POST_EDIT = "post_edit";
+ public static final String POST_NEW = "post_new";
+ public static final String POST_DEL = "post_del";
+
+ public static final String COMMENT_DEL = "comment_del";
+
+ public static final String ADMIN_PANEL = "admin_panel";
+ public static final String ID_EDIT = "id_edit";
+
+ public static void addInfoMessage(String message) {
+ FacesContext.getCurrentInstance().addMessage(null,
+ new FacesMessage(FacesMessage.SEVERITY_INFO, message, ""));
+ }
+
+ public static void addErrorMessage(String message) {
+ FacesContext.getCurrentInstance().addMessage(null,
+ new FacesMessage(FacesMessage.SEVERITY_ERROR, message, ""));
+ }
+
+ public static void addMessageBlogDoesntExist(BlogName blogName) {
+ addErrorMessage("The blog you requested does not exist: " + blogName.toString() + ".");
+ }
+
+ public static void addMessagePostDoesntExist(String id) {
+ addErrorMessage("The post you requested: " + id + " does not exist.");
+ }
+
+ public static void addMessageCommentDoesntExist() {
+ addErrorMessage("The comment you requested does not exist.");
+ }
+}
More information about the jboss-cvs-commits
mailing list