Author: sohil.shah(a)jboss.com
Date: 2007-11-13 11:55:45 -0500 (Tue, 13 Nov 2007)
New Revision: 8905
Added:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestFlexibleGrid.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestRegionLayoutManager.java
Removed:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestFlexibleGrid.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestRegionLayoutManager.java
branches/UIServer/uiserver/src/main/org/jboss/portal/test/
Modified:
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/MainProcessor.java
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/PortalObjectReaderImpl.java
Log:
refactoring
Modified:
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/MainProcessor.java
===================================================================
---
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/MainProcessor.java 2007-11-13
16:51:35 UTC (rev 8904)
+++
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/MainProcessor.java 2007-11-13
16:55:45 UTC (rev 8905)
@@ -46,11 +46,11 @@
import org.jboss.portal.theme.page.WindowResult;
import org.jboss.portal.presentation.RequestContext;
+import org.jboss.portal.presentation.model.Page;
+import org.jboss.portal.presentation.model.Window;
import org.jboss.portal.presentation.server.Processor;
import org.jboss.portal.presentation.server.ProcessorRequest;
import org.jboss.portal.presentation.server.ProcessorResponse;
-import org.jboss.portal.uiserver.protocol.Page;
-import org.jboss.portal.uiserver.protocol.Window;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
Modified:
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/PortalObjectReaderImpl.java
===================================================================
---
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/PortalObjectReaderImpl.java 2007-11-13
16:51:35 UTC (rev 8904)
+++
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/PortalObjectReaderImpl.java 2007-11-13
16:55:45 UTC (rev 8905)
@@ -31,10 +31,10 @@
import org.jboss.portal.core.model.portal.PortalObjectContainer;
import org.jboss.portal.core.model.portal.PortalContainer;
-import org.jboss.portal.uiserver.protocol.Portal;
-import org.jboss.portal.uiserver.protocol.PortalObject;
-import org.jboss.portal.uiserver.protocol.Page;
-import org.jboss.portal.uiserver.protocol.Window;
+import org.jboss.portal.presentation.model.Page;
+import org.jboss.portal.presentation.model.Portal;
+import org.jboss.portal.presentation.model.PortalObject;
+import org.jboss.portal.presentation.model.Window;
import org.jboss.portal.presentation.server.PortalObjectReader;
/**
Copied: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout
(from rev 8903,
branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout)
Deleted:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestFlexibleGrid.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestFlexibleGrid.java 2007-11-13
16:25:06 UTC (rev 8903)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestFlexibleGrid.java 2007-11-13
16:55:45 UTC (rev 8905)
@@ -1,205 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.jboss.portal.test.uiserver.layout;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-
-import java.io.FileOutputStream;
-
-import org.jboss.portal.uiserver.protocol.Container;
-import org.jboss.portal.uiserver.protocol.Window;
-import org.jboss.portal.uiserver.protocol.Page;
-import org.jboss.portal.uiserver.layout.classic.FlexibleGrid;
-import org.jboss.portal.uiserver.layout.classic.FlexibleGridConstraints;
-import org.jboss.portal.uiserver.layout.classic.FlexibleGridLayoutManager;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- *
- */
-public class TestFlexibleGrid extends TestCase
-{
- /**
- *
- */
- private static Logger log = Logger.getLogger(TestFlexibleGrid.class);
-
- /**
- *
- */
- protected void setUp() throws Exception
- {
- }
-
- /**
- *
- */
- protected void tearDown() throws Exception
- {
- }
-
- /**
- *
- * @throws Exception
- */
- public void testDoLayout() throws Exception
- {
- // Setup a Page and a container with two portlet windows...
- // This part is generic with no decoupling to anything layout specific
- String htmlContent = this.getHtmlContent();
- Page page = new Page();
- Container container = new Container("container-1");
- Window window1 = new Window("window-1", htmlContent);
- Window window2 = new Window("window-2", htmlContent);
- container.addComponent(window1);
- container.addComponent(window2);
- page.addContainer(container);
-
- Container container2 = new Container("container-2");
- container2.addComponent(window1);
- container2.addComponent(window2);
- page.addContainer(container2);
-
-
- // Setup a Flexible Grid for laying out a container of portlet windows
- FlexibleGrid grid1 = this.getGrid("container-1", 1, 2);
- FlexibleGridConstraints constraints = this.getConstraints("window-1",
"50", 0, 0, 25, 0, 0, 0);
- FlexibleGridConstraints constraints2 = this.getConstraints("window-1",
"50", 0, 0, 25, 0, 0, 1);
- FlexibleGridConstraints[] firstGridConstraints = { constraints, constraints2 };
- grid1.setConstraints(firstGridConstraints);
-
-
- //Setup another Grid to be added right next to the previous grid
- FlexibleGrid grid2 = this.getGrid("container-2", 1, 2);
- constraints = this.getConstraints("window-1", "50", 0, 0, 25,
0, 0, 0);
- constraints2 = this.getConstraints("window-1", "50", 0, 0, 25,
0, 0, 1);
- FlexibleGridConstraints[] secondGridConstraints = { constraints, constraints2 };
- grid2.setConstraints(secondGridConstraints);
-
-
- // Setup the FlexibleGridLayoutManager for doing a layout and apply it
- // to the Page
- FlexibleGrid[] row1 = { grid1 };
- FlexibleGrid[] row2 = { grid2 };
- FlexibleGridLayoutManager layoutManager = new FlexibleGridLayoutManager();
- layoutManager.addRowOfGrids(row1);
- layoutManager.addRowOfGrids(row2);
-
- // Perform the actual layout of the Page using the
- // FlexibleGridLayoutManager
- String output = layoutManager.doLayout(page);
-
- log.info("--------------------------------------");
- log.info(output);
- log.info("--------------------------------------");
-
- // Write this output to local file to test in a browser
- FileOutputStream fos = new FileOutputStream(
- "/home/soshah/html/layout/flexibleGrid.html");
-
- StringBuffer buffer = new StringBuffer();
-
- buffer
- .append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...
xmlns=\"http://www.w3.org/1999/xhtml\"><head><base
href=\"http://localhost/\"/><title>CSS Layout
Strategies</title><link rel=\"stylesheet\" type=\"text/css\"
href=\"file:///home/soshah/html/layout/unitTest.css\"/></head><body
id=\"body\">\n");
- buffer.append(output);
- buffer.append("</body></html>\n");
-
- fos.write(buffer.toString().getBytes());
- fos.flush();
- fos.close();
- }
-
- /**
- *
- * @return
- */
- private String getHtmlContent()
- {
- String markup = null;
-
- try
- {
- java.io.FileInputStream fis = new java.io.FileInputStream(
- "/home/soshah/html/layout/greetings.html");
-
- StringBuffer buffer = new StringBuffer();
- int read = 0;
- byte[] data = new byte[1000];
- while ((read = fis.read(data)) != -1)
- {
- byte[] bufferData = new byte[read];
- System.arraycopy(data, 0, bufferData, 0, read);
- buffer.append(new String(bufferData));
- }
-
- markup = buffer.toString();
- fis.close();
- }
- catch (Exception e)
- {
-
- }
-
- return markup;
- }
-
- /**
- *
- * @param containerId
- * @param rows
- * @param columns
- * @return
- */
- private FlexibleGrid getGrid(String containerId,int rows, int columns)
- {
- FlexibleGrid grid = new FlexibleGrid(containerId);
- grid.setRows(rows);
- grid.setColumns(columns);
- return grid;
- }
-
- /**
- *
- * @param componentId
- * @param widthPercentage
- * @param top
- * @param bottom
- * @param left
- * @param right
- */
- private FlexibleGridConstraints getConstraints(String componentId, String
widthPercentage, int top, int bottom, int left, int right, int row, int column)
- {
- FlexibleGridConstraints constraints = new FlexibleGridConstraints();
- constraints.setComponentId(componentId);
- constraints.setWidthPercentage(widthPercentage);
- constraints.setRow(row);
- constraints.setColumn(column);
- constraints.setTop(top);
- constraints.setBottom(bottom);
- constraints.setLeft(left);
- constraints.setRight(right);
- return constraints;
- }
-}
Copied:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestFlexibleGrid.java
(from rev 8904,
branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestFlexibleGrid.java)
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestFlexibleGrid.java
(rev 0)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestFlexibleGrid.java 2007-11-13
16:55:45 UTC (rev 8905)
@@ -0,0 +1,205 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.jboss.portal.presentation.test.layout;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+
+import java.io.FileOutputStream;
+
+import org.jboss.portal.presentation.model.Container;
+import org.jboss.portal.presentation.model.Page;
+import org.jboss.portal.presentation.model.Window;
+import org.jboss.portal.uiserver.layout.classic.FlexibleGrid;
+import org.jboss.portal.uiserver.layout.classic.FlexibleGridConstraints;
+import org.jboss.portal.uiserver.layout.classic.FlexibleGridLayoutManager;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class TestFlexibleGrid extends TestCase
+{
+ /**
+ *
+ */
+ private static Logger log = Logger.getLogger(TestFlexibleGrid.class);
+
+ /**
+ *
+ */
+ protected void setUp() throws Exception
+ {
+ }
+
+ /**
+ *
+ */
+ protected void tearDown() throws Exception
+ {
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testDoLayout() throws Exception
+ {
+ // Setup a Page and a container with two portlet windows...
+ // This part is generic with no decoupling to anything layout specific
+ String htmlContent = this.getHtmlContent();
+ Page page = new Page();
+ Container container = new Container("container-1");
+ Window window1 = new Window("window-1", htmlContent);
+ Window window2 = new Window("window-2", htmlContent);
+ container.addComponent(window1);
+ container.addComponent(window2);
+ page.addContainer(container);
+
+ Container container2 = new Container("container-2");
+ container2.addComponent(window1);
+ container2.addComponent(window2);
+ page.addContainer(container2);
+
+
+ // Setup a Flexible Grid for laying out a container of portlet windows
+ FlexibleGrid grid1 = this.getGrid("container-1", 1, 2);
+ FlexibleGridConstraints constraints = this.getConstraints("window-1",
"50", 0, 0, 25, 0, 0, 0);
+ FlexibleGridConstraints constraints2 = this.getConstraints("window-1",
"50", 0, 0, 25, 0, 0, 1);
+ FlexibleGridConstraints[] firstGridConstraints = { constraints, constraints2 };
+ grid1.setConstraints(firstGridConstraints);
+
+
+ //Setup another Grid to be added right next to the previous grid
+ FlexibleGrid grid2 = this.getGrid("container-2", 1, 2);
+ constraints = this.getConstraints("window-1", "50", 0, 0, 25,
0, 0, 0);
+ constraints2 = this.getConstraints("window-1", "50", 0, 0, 25,
0, 0, 1);
+ FlexibleGridConstraints[] secondGridConstraints = { constraints, constraints2 };
+ grid2.setConstraints(secondGridConstraints);
+
+
+ // Setup the FlexibleGridLayoutManager for doing a layout and apply it
+ // to the Page
+ FlexibleGrid[] row1 = { grid1 };
+ FlexibleGrid[] row2 = { grid2 };
+ FlexibleGridLayoutManager layoutManager = new FlexibleGridLayoutManager();
+ layoutManager.addRowOfGrids(row1);
+ layoutManager.addRowOfGrids(row2);
+
+ // Perform the actual layout of the Page using the
+ // FlexibleGridLayoutManager
+ String output = layoutManager.doLayout(page);
+
+ log.info("--------------------------------------");
+ log.info(output);
+ log.info("--------------------------------------");
+
+ // Write this output to local file to test in a browser
+ FileOutputStream fos = new FileOutputStream(
+ "/home/soshah/html/layout/flexibleGrid.html");
+
+ StringBuffer buffer = new StringBuffer();
+
+ buffer
+ .append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...
xmlns=\"http://www.w3.org/1999/xhtml\"><head><base
href=\"http://localhost/\"/><title>CSS Layout
Strategies</title><link rel=\"stylesheet\" type=\"text/css\"
href=\"file:///home/soshah/html/layout/unitTest.css\"/></head><body
id=\"body\">\n");
+ buffer.append(output);
+ buffer.append("</body></html>\n");
+
+ fos.write(buffer.toString().getBytes());
+ fos.flush();
+ fos.close();
+ }
+
+ /**
+ *
+ * @return
+ */
+ private String getHtmlContent()
+ {
+ String markup = null;
+
+ try
+ {
+ java.io.FileInputStream fis = new java.io.FileInputStream(
+ "/home/soshah/html/layout/greetings.html");
+
+ StringBuffer buffer = new StringBuffer();
+ int read = 0;
+ byte[] data = new byte[1000];
+ while ((read = fis.read(data)) != -1)
+ {
+ byte[] bufferData = new byte[read];
+ System.arraycopy(data, 0, bufferData, 0, read);
+ buffer.append(new String(bufferData));
+ }
+
+ markup = buffer.toString();
+ fis.close();
+ }
+ catch (Exception e)
+ {
+
+ }
+
+ return markup;
+ }
+
+ /**
+ *
+ * @param containerId
+ * @param rows
+ * @param columns
+ * @return
+ */
+ private FlexibleGrid getGrid(String containerId,int rows, int columns)
+ {
+ FlexibleGrid grid = new FlexibleGrid(containerId);
+ grid.setRows(rows);
+ grid.setColumns(columns);
+ return grid;
+ }
+
+ /**
+ *
+ * @param componentId
+ * @param widthPercentage
+ * @param top
+ * @param bottom
+ * @param left
+ * @param right
+ */
+ private FlexibleGridConstraints getConstraints(String componentId, String
widthPercentage, int top, int bottom, int left, int right, int row, int column)
+ {
+ FlexibleGridConstraints constraints = new FlexibleGridConstraints();
+ constraints.setComponentId(componentId);
+ constraints.setWidthPercentage(widthPercentage);
+ constraints.setRow(row);
+ constraints.setColumn(column);
+ constraints.setTop(top);
+ constraints.setBottom(bottom);
+ constraints.setLeft(left);
+ constraints.setRight(right);
+ return constraints;
+ }
+}
Deleted:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestRegionLayoutManager.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestRegionLayoutManager.java 2007-11-13
16:25:06 UTC (rev 8903)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestRegionLayoutManager.java 2007-11-13
16:55:45 UTC (rev 8905)
@@ -1,151 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.jboss.portal.test.uiserver.layout;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-
-import java.io.FileOutputStream;
-
-import org.jboss.portal.uiserver.protocol.Container;
-import org.jboss.portal.uiserver.protocol.Window;
-import org.jboss.portal.uiserver.protocol.Page;
-import org.jboss.portal.uiserver.layout.classic.RegionConstraints;
-import org.jboss.portal.uiserver.layout.classic.RegionLayoutManager;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- *
- */
-public class TestRegionLayoutManager extends TestCase
-{
- /**
- *
- */
- private static Logger log = Logger.getLogger(TestRegionLayoutManager.class);
-
- /**
- *
- */
- protected void setUp() throws Exception
- {
- }
-
- /**
- *
- */
- protected void tearDown() throws Exception
- {
- }
-
- /**
- *
- * @throws Exception
- */
- public void testDoLayout() throws Exception
- {
- // Setup a Page and a container with two portlet windows...
- // This part is generic with no decoupling to anything layout specific
- String htmlContent = this.getHtmlContent();
- Page page = new Page();
- Container container = new Container("container-1");
- Window window1 = new Window("window-1", htmlContent);
- Window window2 = new Window("window-2", htmlContent);
- container.addComponent(window1);
- container.addComponent(window2);
- page.addContainer(container);
-
- Container container2 = new Container("container-2");
- Window window3 = new Window("window-3", htmlContent);
- Window window4 = new Window("window-4", htmlContent);
- container2.addComponent(window3);
- container2.addComponent(window4);
- page.addContainer(container2);
-
-
- // Setup a two RegionConstraints for laying out using RegionLayoutManager
- RegionConstraints leftRegion = new
RegionConstraints("container-1",RegionConstraints.LEFT);
- RegionConstraints centerRegion = new
RegionConstraints("container-2",RegionConstraints.CENTER);
- RegionLayoutManager layoutManager = new RegionLayoutManager();
- layoutManager.addRegionConstraints(leftRegion);
- layoutManager.addRegionConstraints(centerRegion);
-
- // Perform the actual layout of the Page using the
- // RegionLayoutManager
- String output = layoutManager.doLayout(page);
-
- log.info("--------------------------------------");
- log.info(output);
- log.info("--------------------------------------");
-
- // Write this output to local file to test in a browser
- FileOutputStream fos = new FileOutputStream(
- "/home/soshah/html/layout/regionLayout.html");
-
- StringBuffer buffer = new StringBuffer();
-
- buffer
- .append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...
xmlns=\"http://www.w3.org/1999/xhtml\"><head><base
href=\"http://localhost/\"/><title>CSS Layout
Strategies</title><link rel=\"stylesheet\" type=\"text/css\"
href=\"file:///home/soshah/html/layout/unitTest.css\"/></head><body
id=\"body\">\n");
- buffer.append(output);
- buffer.append("</body></html>\n");
-
- fos.write(buffer.toString().getBytes());
- fos.flush();
- fos.close();
- }
-
- /**
- *
- * @return
- */
- private String getHtmlContent()
- {
- String markup = null;
-
- try
- {
- java.io.FileInputStream fis = new java.io.FileInputStream(
- "/home/soshah/html/layout/greetings2.html");
-
- StringBuffer buffer = new StringBuffer();
- int read = 0;
- byte[] data = new byte[1000];
- while ((read = fis.read(data)) != -1)
- {
- byte[] bufferData = new byte[read];
- System.arraycopy(data, 0, bufferData, 0, read);
- buffer.append(new String(bufferData));
- }
-
- markup = buffer.toString();
- fis.close();
- }
- catch (Exception e)
- {
-
- }
-
- return markup;
- }
-}
Copied:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestRegionLayoutManager.java
(from rev 8904,
branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestRegionLayoutManager.java)
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestRegionLayoutManager.java
(rev 0)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/layout/TestRegionLayoutManager.java 2007-11-13
16:55:45 UTC (rev 8905)
@@ -0,0 +1,151 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.jboss.portal.presentation.test.layout;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+
+import java.io.FileOutputStream;
+
+import org.jboss.portal.presentation.model.Container;
+import org.jboss.portal.presentation.model.Page;
+import org.jboss.portal.presentation.model.Window;
+import org.jboss.portal.uiserver.layout.classic.RegionConstraints;
+import org.jboss.portal.uiserver.layout.classic.RegionLayoutManager;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class TestRegionLayoutManager extends TestCase
+{
+ /**
+ *
+ */
+ private static Logger log = Logger.getLogger(TestRegionLayoutManager.class);
+
+ /**
+ *
+ */
+ protected void setUp() throws Exception
+ {
+ }
+
+ /**
+ *
+ */
+ protected void tearDown() throws Exception
+ {
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testDoLayout() throws Exception
+ {
+ // Setup a Page and a container with two portlet windows...
+ // This part is generic with no decoupling to anything layout specific
+ String htmlContent = this.getHtmlContent();
+ Page page = new Page();
+ Container container = new Container("container-1");
+ Window window1 = new Window("window-1", htmlContent);
+ Window window2 = new Window("window-2", htmlContent);
+ container.addComponent(window1);
+ container.addComponent(window2);
+ page.addContainer(container);
+
+ Container container2 = new Container("container-2");
+ Window window3 = new Window("window-3", htmlContent);
+ Window window4 = new Window("window-4", htmlContent);
+ container2.addComponent(window3);
+ container2.addComponent(window4);
+ page.addContainer(container2);
+
+
+ // Setup a two RegionConstraints for laying out using RegionLayoutManager
+ RegionConstraints leftRegion = new
RegionConstraints("container-1",RegionConstraints.LEFT);
+ RegionConstraints centerRegion = new
RegionConstraints("container-2",RegionConstraints.CENTER);
+ RegionLayoutManager layoutManager = new RegionLayoutManager();
+ layoutManager.addRegionConstraints(leftRegion);
+ layoutManager.addRegionConstraints(centerRegion);
+
+ // Perform the actual layout of the Page using the
+ // RegionLayoutManager
+ String output = layoutManager.doLayout(page);
+
+ log.info("--------------------------------------");
+ log.info(output);
+ log.info("--------------------------------------");
+
+ // Write this output to local file to test in a browser
+ FileOutputStream fos = new FileOutputStream(
+ "/home/soshah/html/layout/regionLayout.html");
+
+ StringBuffer buffer = new StringBuffer();
+
+ buffer
+ .append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...
xmlns=\"http://www.w3.org/1999/xhtml\"><head><base
href=\"http://localhost/\"/><title>CSS Layout
Strategies</title><link rel=\"stylesheet\" type=\"text/css\"
href=\"file:///home/soshah/html/layout/unitTest.css\"/></head><body
id=\"body\">\n");
+ buffer.append(output);
+ buffer.append("</body></html>\n");
+
+ fos.write(buffer.toString().getBytes());
+ fos.flush();
+ fos.close();
+ }
+
+ /**
+ *
+ * @return
+ */
+ private String getHtmlContent()
+ {
+ String markup = null;
+
+ try
+ {
+ java.io.FileInputStream fis = new java.io.FileInputStream(
+ "/home/soshah/html/layout/greetings2.html");
+
+ StringBuffer buffer = new StringBuffer();
+ int read = 0;
+ byte[] data = new byte[1000];
+ while ((read = fis.read(data)) != -1)
+ {
+ byte[] bufferData = new byte[read];
+ System.arraycopy(data, 0, bufferData, 0, read);
+ buffer.append(new String(bufferData));
+ }
+
+ markup = buffer.toString();
+ fis.close();
+ }
+ catch (Exception e)
+ {
+
+ }
+
+ return markup;
+ }
+}