[jboss-svn-commits] JBL Code SVN: r18704 - in labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates: service and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Mar 5 09:59:39 EST 2008
Author: unibrew
Date: 2008-03-05 09:59:39 -0500 (Wed, 05 Mar 2008)
New Revision: 18704
Added:
labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesNotInitializedException.java
Modified:
labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesDescriptor.java
labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesPortlet.java
labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesTools.java
labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/service/PrimatesServiceImpl.java
Log:
[JBLAB] Bug fix/improvement for primates.
Modified: labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesDescriptor.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesDescriptor.java 2008-03-05 14:43:39 UTC (rev 18703)
+++ labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesDescriptor.java 2008-03-05 14:59:39 UTC (rev 18704)
@@ -22,16 +22,17 @@
package org.jbosslabs.portlets.primates;
-import org.apache.xerces.parsers.DOMParser;
+import org.jboss.logging.Logger;
import org.jboss.portal.core.servlet.jsp.taglib.context.DelegateContext;
+
import org.jboss.shotoku.ContentManager;
-
import org.w3c.dom.Document;
import org.w3c.dom.Node;
-
import org.xml.sax.InputSource;
+import com.sun.org.apache.xerces.internal.parsers.DOMParser;
+
/**
* @author Damon Sicore
* @author adamw
@@ -41,6 +42,7 @@
public class PrimatesDescriptor
{
private Primates primates;
+ private static final Logger log = Logger.getLogger(PrimatesDescriptor.class);
public PrimatesDescriptor(String portalName, ContentManager cm)
{
@@ -61,15 +63,16 @@
}
catch (Exception e)
{
- e.printStackTrace();
+ log.error("I could not parse primates.xml.",e);
}
}
/**
* Returns DelegateContext object containing all primates.
*/
- public void getContext(DelegateContext context, String portalName)
+ public void getContext(DelegateContext context, String portalName) throws PrimatesNotInitializedException
{
+ if (primates==null) throw new PrimatesNotInitializedException();
primates.getPrimatesContext(context, portalName);
}
@@ -77,8 +80,9 @@
* Returns DelegateContext objcet containing one random primate.
*/
public void getRandomPrimateCtx(DelegateContext context,
- String portalName)
+ String portalName) throws PrimatesNotInitializedException
{
+ if (primates==null) throw new PrimatesNotInitializedException();
primates.getRandomPrimateCtx(context, portalName);
}
Added: labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesNotInitializedException.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesNotInitializedException.java (rev 0)
+++ labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesNotInitializedException.java 2008-03-05 14:59:39 UTC (rev 18704)
@@ -0,0 +1,38 @@
+ /*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jbosslabs.portlets.primates;
+
+/**
+ *
+ * @author <a href="ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
+ *
+ */
+public class PrimatesNotInitializedException extends Exception
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+}
Modified: labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesPortlet.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesPortlet.java 2008-03-05 14:43:39 UTC (rev 18703)
+++ labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesPortlet.java 2008-03-05 14:59:39 UTC (rev 18704)
@@ -24,6 +24,8 @@
import java.io.IOException;
+import org.jboss.logging.Logger;
+
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletURL;
@@ -44,6 +46,9 @@
public class PrimatesPortlet
extends JBossPortlet
{
+
+ private static final Logger log = Logger.getLogger(PrimatesPortlet.class);
+
public void doView(JBossRenderRequest request,
JBossRenderResponse response)
throws IOException, PortletException
@@ -75,16 +80,24 @@
renderType= PrimatesTools.MUGSHOT_VIEW;
}
}
- if (renderType != null && renderType.compareTo(PrimatesTools.ALL_VIEW) == 0)
- {
- // Getting the context containing all primates.
- PrimatesTools.getDesc(portalName).getContext(mainContext,
- portalName);
- } else
- {
- // Getting the context containing random primate.
- PrimatesTools.getDesc(portalName).getRandomPrimateCtx(mainContext,
- portalName);
+ try {
+ if (renderType != null && renderType.compareTo(PrimatesTools.ALL_VIEW) == 0)
+ {
+ // Getting the context containing all primates.
+ PrimatesTools.getDesc(portalName).getContext(mainContext,
+ portalName);
+ } else
+ {
+ // Getting the context containing random primate.
+ PrimatesTools.getDesc(portalName).getRandomPrimateCtx(mainContext,
+ portalName);
+ }
+ } catch (PrimatesNotInitializedException e) {
+ log.error("Primates were not initialized properly. Probably primates.xml is missing or contains errors.",e);
+ PortletRequestDispatcher rd =getPortletContext().getRequestDispatcher(
+ ForgeHelper.createRepoAccessPath(portalName,PrimatesTools.getErrorHtmlCmPath()));
+ rd.include(request,response);
+ return;
}
if ((buttonsRenderFromPref==null || buttonsRenderFromPref.equals("yes"))) {
Modified: labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesTools.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesTools.java 2008-03-05 14:43:39 UTC (rev 18703)
+++ labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/PrimatesTools.java 2008-03-05 14:59:39 UTC (rev 18704)
@@ -43,6 +43,8 @@
public final static String PRIMATES_MUGSHOT_JSP = "mugshot.jsp";
+ public final static String PRIMATES_ERROR_HTML = "error.htm";
+
public final static String PRIMATES_DIR = "primates";
public final static String BIOS_DIR = "html";
@@ -83,6 +85,15 @@
public static String getMugshotJspCmPath() {
return PRIMATES_DIR + File.separator + PRIMATES_MUGSHOT_JSP;
}
+
+ /**
+ * Method returns path to the error HTML file.
+ *
+ * @return
+ */
+ public static String getErrorHtmlCmPath() {
+ return PRIMATES_DIR + File.separator + PRIMATES_ERROR_HTML;
+ }
/**
* Method returns images directory path.
Modified: labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/service/PrimatesServiceImpl.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/service/PrimatesServiceImpl.java 2008-03-05 14:43:39 UTC (rev 18703)
+++ labs/jbosslabs/trunk/portal-extensions/primates/src/java/org/jbosslabs/portlets/primates/service/PrimatesServiceImpl.java 2008-03-05 14:59:39 UTC (rev 18704)
@@ -40,6 +40,7 @@
import org.jbosslabs.portlets.primates.Primate;
import org.jbosslabs.portlets.primates.PrimatesDescriptor;
import org.jbosslabs.portlets.primates.PrimatesTools;
+import org.jbosslabs.portlets.primates.PrimatesNotInitializedException;
/**
* @author <a href="mailto:tomasz.szymanski at jboss.com">Tomasz Szymanski</a>
@@ -65,8 +66,13 @@
DelegateContext context = new DelegateContext();
- desc.getContext(context, portalName);
-
+ try {
+ desc.getContext(context, portalName);
+ } catch (PrimatesNotInitializedException e) {
+ log.error("Primates were not initialized properly. Probably primates.xml is missing or contains errors.",e);
+ return null;
+ }
+
Iterator<DelegateContext> iterator = context.childIterator("primate");
while (iterator.hasNext()) {
@@ -100,7 +106,12 @@
DelegateContext context = new DelegateContext();
PrimatesDescriptor desc = PrimatesTools.getDesc(portalName);
- desc.getContext(context, portalName);
+ try {
+ desc.getContext(context, portalName);
+ } catch (PrimatesNotInitializedException e) {
+ log.error("Primates were not initialized properly. Probably primates.xml is missing or contains errors.",e);
+ return null;
+ }
Iterator<DelegateContext> iterator = context.childIterator("primate");
while (iterator.hasNext()) {
More information about the jboss-svn-commits
mailing list