Author: julien(a)jboss.com
Date: 2008-04-03 20:14:10 -0400 (Thu, 03 Apr 2008)
New Revision: 10500
Added:
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/PresentationServerImpl.java
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/ClassicPresentationClient.java
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/ClassicUINode.java
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/ClassicViewPortContext.java
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/DefaultPageViewPortScope.java
Log:
preliminary code for the classic ui impl
Added:
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/PresentationServerImpl.java
===================================================================
---
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/PresentationServerImpl.java
(rev 0)
+++
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/PresentationServerImpl.java 2008-04-04
00:14:10 UTC (rev 10500)
@@ -0,0 +1,75 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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;
+
+import org.jboss.portal.presentation.server2.PresentationServer;
+import org.jboss.portal.presentation.server2.PresentationServerException;
+import org.jboss.portal.presentation.server2.PresentationResponse;
+import org.jboss.portal.presentation.server2.PresentationRequest;
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.protocol.ProtocolAction;
+import org.jboss.portal.presentation.model.content.WindowContent;
+import org.jboss.portal.presentation.client2.PresentationClient;
+import org.jboss.portal.presentation.impl.state.structural.StructuralStateContextImpl;
+import org.jboss.portal.presentation.impl.state.structural.ContextNode;
+import org.jboss.portal.presentation.impl.state.structural.PageNode;
+import org.jboss.portal.presentation.impl.state.structural.WindowNode;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PresentationServerImpl implements PresentationServer
+{
+
+ /** . */
+ private StructuralStateContextImpl structuralStateContext = new
StructuralStateContextImpl();
+
+ public PresentationServerImpl()
+ {
+ ContextNode root = structuralStateContext.getRoot();
+ PageNode page = root.addChild("default", PageNode.class);
+ page.addChild("foo", WindowNode.class);
+ page.addChild("bar", WindowNode.class);
+ }
+
+ public StructuralStateContext getStructuralStateContext()
+ {
+ return structuralStateContext;
+ }
+
+ public String render(ProtocolAction action) throws IllegalArgumentException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public WindowContent renderWindow(PresentationClient client, String windowId) throws
PresentationServerException
+ {
+ return new WindowContent(0, "Window " + windowId, "Some markup for
window " + windowId);
+ }
+
+ public PresentationResponse process(PresentationClient client, PresentationRequest
request) throws PresentationServerException
+ {
+ throw new UnsupportedOperationException();
+ }
+}
Added:
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/ClassicPresentationClient.java
===================================================================
---
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/ClassicPresentationClient.java
(rev 0)
+++
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/ClassicPresentationClient.java 2008-04-04
00:14:10 UTC (rev 10500)
@@ -0,0 +1,158 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.classic;
+
+import org.jboss.portal.presentation.client2.PresentationClient;
+import org.jboss.portal.presentation.state.navigational.NavigationalStateContext;
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.classic.model.DefaultPageViewPortScope;
+import org.jboss.portal.presentation.classic.model.ClassicViewPortContext;
+import org.jboss.portal.presentation.classic.model.ClassicUINode;
+import org.jboss.portal.presentation.server2.PresentationServer;
+import org.jboss.portal.presentation.server2.PresentationServerException;
+import org.jboss.portal.presentation.model2.UIModel;
+import org.jboss.portal.presentation.model2.ViewPort;
+import org.jboss.portal.presentation.model2.UIObject;
+import org.jboss.portal.presentation.model2.ui.UIContext;
+import org.jboss.portal.presentation.model2.ui.UIPage;
+import org.jboss.portal.presentation.model2.ui.UIWindow;
+import org.jboss.portal.presentation.impl.model2.UIModelImpl;
+import org.jboss.portal.presentation.model.content.WindowContent;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.PrintWriter;
+import java.io.IOException;
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ClassicPresentationClient implements PresentationClient
+{
+
+ /** . */
+ private final HttpServletRequest req;
+
+ /** . */
+ private final HttpServletResponse resp;
+
+ /** . */
+ private final PresentationServer server;
+
+ public ClassicPresentationClient(
+ HttpServletRequest req,
+ HttpServletResponse resp,
+ PresentationServer server)
+ {
+ this.req = req;
+ this.resp = resp;
+ this.server = server;
+ }
+
+ public NavigationalStateContext getNavigationalStateContext()
+ {
+ return null;
+ }
+
+ public void process() throws IOException
+ {
+
+ StructuralStateContext ssc = server.getStructuralStateContext();
+
+ DefaultPageViewPortScope scope = new DefaultPageViewPortScope(ssc.getRootId());
+
+ ClassicViewPortContext context = new ClassicViewPortContext();
+
+ UIModel model = new UIModelImpl(null, ssc);
+
+ ViewPort viewPort = model.createViewPort(context, scope);
+
+ viewPort.refresh();
+
+ ClassicUINode root = context.getNode(ssc.getRootId());
+
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ render(root, writer);
+ }
+
+ private void render(ClassicUINode node, PrintWriter writer)
+ {
+ UIObject object = node.getObject();
+
+ //
+ if (object instanceof UIContext)
+ {
+ writer.print("<html><body>");
+
+ //
+ renderChildren(node, writer);
+
+ //
+ writer.print("</body></html>");
+ }
+ else if (object instanceof UIPage)
+ {
+ writer.print("<div>");
+
+ //
+ renderChildren(node, writer);
+
+ //
+ writer.print("</div>");
+ }
+ else if (object instanceof UIWindow)
+ {
+ try
+ {
+ WindowContent content = server.renderWindow(this, object.getId());
+
+ //
+ writer.print("<div>");
+ writer.print(content.getMarkup());
+ writer.print("</div>");
+ }
+ catch (PresentationServerException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void renderChildren(ClassicUINode node, PrintWriter writer)
+ {
+ Collection<ClassicUINode> children = node.getChildren();
+
+ //
+ if (children != null)
+ {
+ for (ClassicUINode child : children)
+ {
+ render(child, writer);
+ }
+ }
+ }
+
+}
Added:
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/ClassicUINode.java
===================================================================
---
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/ClassicUINode.java
(rev 0)
+++
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/ClassicUINode.java 2008-04-04
00:14:10 UTC (rev 10500)
@@ -0,0 +1,76 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.classic.model;
+
+import org.jboss.portal.presentation.model2.UIObject;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ClassicUINode
+{
+
+ /** . */
+ private final UIObject object;
+
+ /** . */
+ ClassicUINode parent;
+
+ /** . */
+ Map<String, ClassicUINode> children;
+
+ public ClassicUINode(UIObject object)
+ {
+ this.object = object;
+ }
+
+ public ClassicUINode getParent()
+ {
+ return parent;
+ }
+
+ public String getId()
+ {
+ return object.getId();
+ }
+
+ public String getName()
+ {
+ return object.getName();
+ }
+
+ public UIObject getObject()
+ {
+ return object;
+ }
+
+ public Collection<ClassicUINode> getChildren()
+ {
+ return children == null ? null : children.values();
+ }
+}
Added:
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/ClassicViewPortContext.java
===================================================================
---
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/ClassicViewPortContext.java
(rev 0)
+++
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/ClassicViewPortContext.java 2008-04-04
00:14:10 UTC (rev 10500)
@@ -0,0 +1,103 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.classic.model;
+
+import org.jboss.portal.presentation.model2.ViewPortContext;
+import org.jboss.portal.presentation.model2.UIObject;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ClassicViewPortContext implements ViewPortContext
+{
+
+ /** . */
+ final Map<String, ClassicUINode> nodes = new HashMap<String,
ClassicUINode>();
+
+ public ClassicUINode getNode(String nodeId)
+ {
+ return nodes.get(nodeId);
+ }
+
+ public UIObject getObject(String objectId)
+ {
+ ClassicUINode node = nodes.get(objectId);
+
+ //
+ if (node == null)
+ {
+ return null;
+ }
+ else
+ {
+ return node.getObject();
+ }
+ }
+
+ public void addObject(UIObject object)
+ {
+ ClassicUINode node = new ClassicUINode(object);
+
+ //
+ nodes.put(node.getId(), node);
+ }
+
+ public void updateObject(String objectId)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeObject(String objectId)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void createChildren(String parentId)
+ {
+ nodes.get(parentId).children = new HashMap<String, ClassicUINode>();
+ }
+
+ public void destroyChildren(String parentId)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addChild(String parentId, String childId)
+ {
+ ClassicUINode parent = nodes.get(parentId);
+ ClassicUINode child = nodes.get(childId);
+
+ //
+ parent.children.put(child.getName(), child);
+ child.parent = parent;
+ }
+
+ public void removeChild(String parentId, String childId)
+ {
+ throw new UnsupportedOperationException();
+ }
+}
Added:
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/DefaultPageViewPortScope.java
===================================================================
---
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/DefaultPageViewPortScope.java
(rev 0)
+++
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/model/DefaultPageViewPortScope.java 2008-04-04
00:14:10 UTC (rev 10500)
@@ -0,0 +1,133 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.classic.model;
+
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+import org.jboss.portal.presentation.model2.UIObject;
+import org.jboss.portal.presentation.model2.ui.UIPage;
+import org.jboss.portal.presentation.model2.ui.UIWindow;
+import org.jboss.portal.presentation.model2.ui.UIContext;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class DefaultPageViewPortScope implements ViewPortScope
+{
+
+ /** . */
+ private static final int NO_PAGE = 0;
+
+ /** . */
+ private static final int DEFAULT_PAGE = 1;
+
+ /** . */
+ private static final int DEFAULT_PAGE_CHILD = 2;
+
+ /** . */
+ private static final int DEFAULT_PAGE_SIBLING = 3;
+
+ /** . */
+ private final String rootId;
+
+ /** . */
+ private int pageStatus;
+
+ public DefaultPageViewPortScope(String rootId)
+ {
+ this.rootId = rootId;
+ this.pageStatus = 0;
+ }
+
+ public String getRootId()
+ {
+ return rootId;
+ }
+
+ public ObjectTraversalType enterObject(UIObject object)
+ {
+ if (object instanceof UIPage)
+ {
+ switch (pageStatus)
+ {
+ case NO_PAGE:
+ if ("default".equals(object.getName()))
+ {
+ pageStatus = DEFAULT_PAGE;
+
+ // We want to traverse the children of the default page
+ return ObjectTraversalType.RECURSIVE;
+ }
+ else
+ {
+ pageStatus = DEFAULT_PAGE_SIBLING;
+
+ // We want to see the sibbling pages of the default page
+ return ObjectTraversalType.SINGLE;
+ }
+ case DEFAULT_PAGE:
+ pageStatus = DEFAULT_PAGE_CHILD;
+
+ // We want to see the children pages of the default page
+ return ObjectTraversalType.SINGLE;
+ case DEFAULT_PAGE_CHILD:
+ case DEFAULT_PAGE_SIBLING:
+ return ObjectTraversalType.SKIP;
+ default:
+ throw new AssertionError();
+ }
+ }
+ else if (object instanceof UIWindow)
+ {
+ // We don't traverse windows (for now as they are supposed to be leaves)
+ return ObjectTraversalType.SINGLE;
+ }
+ else if (object instanceof UIContext)
+ {
+ return ObjectTraversalType.RECURSIVE;
+ }
+ else
+ {
+ return ObjectTraversalType.SKIP;
+ }
+ }
+
+ public void leaveObject(UIObject object)
+ {
+ switch (pageStatus)
+ {
+ case NO_PAGE:
+ throw new AssertionError();
+ case DEFAULT_PAGE:
+ pageStatus = NO_PAGE;
+ break;
+ case DEFAULT_PAGE_SIBLING:
+ pageStatus = DEFAULT_PAGE;
+ break;
+ case DEFAULT_PAGE_CHILD:
+ pageStatus = DEFAULT_PAGE;
+ break;
+ }
+ }
+}