From: Julien V. <vi...@us...> - 2004-05-01 18:02:07
|
User: vietj Date: 04/05/01 11:02:01 Modified: nukes/src/main/org/jboss/nukes/core/modules/html/blocks HtmlContextualBlock.java Log: replaced the HtmlContextualBlock which was flawed Revision Changes Path 1.3 +40 -15 nukes/nukes/src/main/org/jboss/nukes/core/modules/html/blocks/HtmlContextualBlock.java Index: HtmlContextualBlock.java =================================================================== RCS file: /cvsroot/jboss/nukes/nukes/src/main/org/jboss/nukes/core/modules/html/blocks/HtmlContextualBlock.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HtmlContextualBlock.java 30 Apr 2004 21:54:14 -0000 1.2 +++ HtmlContextualBlock.java 1 May 2004 18:02:00 -0000 1.3 @@ -13,6 +13,10 @@ import org.jboss.nukes.core.modules.html.HtmlModule; import org.jboss.nukes.core.modules.html.File; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.ReflectionException; + /** * A block menu which displays content according to the current page being displayed. * @@ -22,7 +26,7 @@ * If the target menu is not defined it will display the string defaultContent. * * @author <a href="mailto:ju...@jb...">Julien Viet</a> - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ public class HtmlContextualBlock extends BlockSupport { @@ -45,30 +49,39 @@ public void render(Page page) { - String fileId = menuFileId; + // The displayed file + File file = null; + + // If we are in the HTML module and display something we try to load the relative menu if ("html".equals(page.getParameter("module")) && "display".equals(page.getParameter("op"))) { String id = page.getParameter("id"); if (id != null) { - fileId = guessMenuFileId(id); + String fileId = guessMenuFileId(id); + if (fileId != null) + { + // Try to get it the file + file = get(fileId); + } } } - try + + // If No file found, take the one from the root + if (file == null) { - File file = (File)server.invoke(HtmlModule.OBJECT_NAME, "getResource", new Object[]{fileId}, new String[]{String.class.getName()}); - if (file != null && file.getContentType().startsWith("text/")) - { - page.print(file.getContentAsString()); - } - else - { - page.print(defaultContent); - } + file = get(menuFileId); } - catch (Exception e) + + if (file != null && file.getContentType().startsWith("text/")) { - log.error("Cannot get content from html module", e); + // We have something to display + page.print(file.getContentAsString()); + } + else + { + // Fall back to the default content + page.print(defaultContent); } } @@ -93,6 +106,18 @@ this.menuFileId = "/" + menuName; } + private File get(String fileId) + { + try + { + return (File)server.invoke(HtmlModule.OBJECT_NAME, "getResource", new Object[]{fileId}, new String[]{String.class.getName()}); + } + catch (Exception e) + { + return null; + } + } + private String guessMenuFileId(String id) { int pos = id.indexOf('/', 1); |