rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zh...@apache.org
Subject svn commit: r1087520 [5/35] - in /incubator/rave/donations/ogce-gadget-container: ./ config/ config/shindig-1.1-BETA5/ config/shindig-2.0.0/ db-cleaner/ examples/ examples/src/ examples/src/main/ examples/src/main/java/ examples/src/main/java/cgl/ exam...
Date Fri, 01 Apr 2011 00:29:38 GMT
Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/PortalConfig.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/PortalConfig.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/PortalConfig.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/PortalConfig.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,164 @@
+package cgl.shindig.config;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.Properties;
+
+import org.apache.commons.io.IOUtils; 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import cgl.shindig.config.ConfigurationException;
+import cgl.shindig.usermanage.util.ResourceLoader;
+
+public class PortalConfig {
+
+    /** the default logger */
+    private static Logger log = LoggerFactory.getLogger(PortalConfig.class);
+
+    /** Name of the default configuration file. */
+    private static final String PORTAL_CONFIG_XML = "portal.xml";
+
+    public static PortalConfig install(File dir)
+            throws IOException, ConfigurationException {
+        return install(new File(dir, PORTAL_CONFIG_XML), dir);
+    }
+
+    public static PortalConfig install(File xml, File dir)
+            throws IOException, ConfigurationException {
+        if (!dir.exists()) {
+            log.info("Creating directory {}", dir);
+            dir.mkdirs();
+        }
+
+        if (!xml.exists()) {
+            log.info("Installing default configuration to {}", xml);
+            OutputStream output = new FileOutputStream(xml);
+            try {
+                InputStream input = ResourceLoader.open("res://"+PORTAL_CONFIG_XML);
+                // log.error("classloader is:" + PortalConfig.class.getClassLoader().toString());
+                // InputStream input = PortalConfig.class.getResourceAsStream(PORTAL_CONFIG_XML);
+                try {
+                    IOUtils.copy(input, output);
+                } finally {
+                    input.close();
+                }
+            } finally {
+                output.close();
+            }
+        }
+        return create(xml, dir);
+    }
+
+    public static PortalConfig create(File dir)
+            throws ConfigurationException {
+        return create(new File(dir, PORTAL_CONFIG_XML), dir);
+    }
+
+    public static PortalConfig create(File xml, File dir)
+            throws ConfigurationException {
+        if (!dir.isDirectory()) {
+            throw new ConfigurationException(
+                    "directory " + dir + " does not exist");
+        }
+
+        if (!xml.isFile()) {
+            throw new ConfigurationException(
+                    "configuration file " + xml + " does not exist");
+        }
+
+        try {
+            return create(new FileInputStream(xml), dir.getPath());
+        } catch(FileNotFoundException ex) {
+            throw new ConfigurationException("File " + xml + 
+                " cannot be found. ", ex);
+        }
+    }
+
+    public static PortalConfig create(String file, String home)
+            throws ConfigurationException {
+        // URI uri = new File(file).toURI();
+        try {
+            return create(new FileInputStream(file), home);
+        } catch(FileNotFoundException ex) {
+            throw new ConfigurationException("File " + file + 
+                " cannot be found. ", ex);
+        }
+    }
+
+    public static PortalConfig create(URI uri, String home)
+            throws ConfigurationException {
+        return create(new File(uri), new File(home));
+    }
+
+    public static PortalConfig create(InputStream input, String home)
+      throws ConfigurationException {
+      try {
+          Properties variables = new Properties(System.getProperties());
+          PortalConfigParser parser = new PortalConfigParser(variables);
+          PortalConfig config = parser.parsePortalConfig(input);
+          config.init();
+          return config;
+      } catch(Exception ex) {
+          throw new ConfigurationException("apache common configuration exception",
+              ex);
+      }
+    }
+
+
+    private final SecurityConfig sec;
+
+    private final PortalConfigParser parser;
+
+    public PortalConfig(SecurityConfig sec, PortalConfigParser parser) {
+        this.sec = sec;
+        this.parser = parser;
+    }
+
+    public void init() throws ConfigurationException, IllegalStateException {
+    }
+
+    public String getAppName() {
+        return sec.getAppName();
+    }
+
+    public AccessManagerConfig getAccessManagerConfig() {
+        return sec.getAccessManagerConfig();
+    }
+
+    public LoginModuleConfig getLoginModuleConfig() {
+        return sec.getLoginModuleConfig();
+    }
+
+    public SecurityConfig getSecurityConfig() {
+        return sec;
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/PortalConfigParser.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/PortalConfigParser.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/PortalConfigParser.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/PortalConfigParser.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,143 @@
+package cgl.shindig.config;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+
+import java.util.Properties;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import java.io.InputStream;
+
+public class PortalConfigParser extends ConfigurationParser {
+
+    /** Name of the security configuration element. */
+    public static final String SECURITY_ELEMENT = "Security";
+
+    /** Name of the security manager configuration element. */
+    public static final String SECURITY_MANAGER_ELEMENT = "SecurityManager";
+
+    /** Name of the access manager configuration element. */
+    public static final String ACCESS_MANAGER_ELEMENT = "AccessManager";
+
+    /** Name of the login module configuration element. */
+    public static final String LOGIN_MODULE_ELEMENT = "LoginModule";
+
+    /**
+     * Name of the optional UserManagerConfig element that defines the
+     * configuration options for the user manager.
+     */
+    private static final String USER_MANAGER_ELEMENT = "UserManager";
+
+    /** Name of the application name configuration attribute. */
+    public static final String APP_NAME_ATTRIBUTE = "appName";
+
+    /** Name of the id configuration attribute. */
+    public static final String ID_ATTRIBUTE = "id";
+
+    /**
+     * Name of the optional AccessControlProvider element defining which
+     * implementation of AccessControlProvider should be used.
+     */
+    private static final String AC_PROVIDER_ELEMENT = "AccessControlProvider";
+
+
+    /**
+     * Creates a new configuration parser with the given parser variables.
+     *
+     * @param variables parser variables
+     */
+    public PortalConfigParser(Properties variables) {
+        super(variables);
+    }
+
+    public PortalConfig parsePortalConfig(InputStream xml)
+            throws ConfigurationException {
+        // HierarchicalConfiguration root = parseXML(xml, true);
+        HierarchicalConfiguration root = parseXML(xml, false);
+
+        // Security configuration and access manager implementation
+        HierarchicalConfiguration security = getSubConfig(root, SECURITY_ELEMENT);
+        SecurityConfig securityConfig = parseSecurityConfig(security);
+
+        return new PortalConfig(securityConfig, this);
+    }
+
+    public SecurityConfig parseSecurityConfig(HierarchicalConfiguration security)
+            throws ConfigurationException {
+        String appName = getAttribute(security, APP_NAME_ATTRIBUTE);
+
+        SecurityManagerConfig smc = parseSecurityManagerConfig(security);
+        AccessManagerConfig amc = parseAccessManagerConfig(security);
+        LoginModuleConfig lmc = parseLoginModuleConfig(security);
+
+        return new SecurityConfig(appName, smc, amc, lmc);
+    }
+
+    public SecurityManagerConfig parseSecurityManagerConfig(HierarchicalConfiguration security)
+            throws ConfigurationException {
+        // Optional security manager config entry
+        HierarchicalConfiguration smElement = getSubConfig(security, SECURITY_MANAGER_ELEMENT, false);
+        if (smElement != null) {
+            BeanConfig bc = parseBeanConfig(smElement);
+
+            BeanConfig umc = null;
+            HierarchicalConfiguration element = getSubConfig(smElement, USER_MANAGER_ELEMENT, false);
+            if (element != null) {
+                umc = parseBeanConfig(smElement, USER_MANAGER_ELEMENT);
+            }
+            return new SecurityManagerConfig(bc, umc);
+        } else {
+            return null;
+        }
+    }
+
+    public AccessManagerConfig parseAccessManagerConfig(HierarchicalConfiguration security)
+            throws ConfigurationException {
+        // Optional access manager config entry
+        HierarchicalConfiguration accessMgr = getSubConfig(security, ACCESS_MANAGER_ELEMENT, false);
+        if (accessMgr != null) {
+            return new AccessManagerConfig(parseBeanConfig(accessMgr));
+        } else {
+            return null;
+        }
+    }
+
+    public LoginModuleConfig parseLoginModuleConfig(HierarchicalConfiguration security)
+            throws ConfigurationException {
+        // Optional login module
+        HierarchicalConfiguration loginModule = getSubConfig(security, LOGIN_MODULE_ELEMENT, false);
+
+        if (loginModule != null) {
+            return new LoginModuleConfig(parseBeanConfig(security, LOGIN_MODULE_ELEMENT));
+        } else {
+            return null;
+        }
+    }
+    protected PortalConfigParser createSubParser(Properties variables) {
+        // overlay the properties
+        Properties props = new Properties(getVariables());
+        props.putAll(variables);
+        return new PortalConfigParser(props);
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/SecurityConfig.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/SecurityConfig.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/SecurityConfig.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/SecurityConfig.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,100 @@
+package cgl.shindig.config;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+/**
+ * Security configuration. This encapsulates the security related sub
+ * configurations {@link AccessManagerConfig} and {@link LoginModuleConfig}.
+ */
+public class SecurityConfig {
+
+    /**
+     * name for a JAAS app-entry configuration.
+     */
+    private final String name;
+
+    /**
+     * security manager configuration;
+     */
+    private final SecurityManagerConfig smc;
+
+    private final AccessManagerConfig amc;
+
+    private final LoginModuleConfig lmc;
+
+    /**
+     * Creates a new security configuration.
+     *
+     * @param name name for a JAAS app-entry configuration
+     * @param smc security manager configuration
+     * @param amc access manager configuration
+     * @param lmc login module configuration (can be <code>null</code>)
+     */
+    public SecurityConfig(
+            String name,
+            SecurityManagerConfig smc,
+            AccessManagerConfig amc, LoginModuleConfig lmc) {
+        this.name = name;
+        this.smc = smc;
+        this.amc = amc;
+        this.lmc = lmc;
+    }
+
+    /**
+     * Returns the name. The name can be used for
+     * JAAS app-entry configuration.
+     *
+     * @return name
+     */
+    public String getAppName() {
+        return name;
+    }
+
+    /**
+     * Returns the security manager configuration.
+     *
+     * @return access manager configuration
+     */
+    public SecurityManagerConfig getSecurityManagerConfig() {
+        return smc;
+    }
+
+    /**
+     * Returns the access manager configuration.
+     *
+     * @return access manager configuration
+     */
+    public AccessManagerConfig getAccessManagerConfig() {
+        return amc;
+    }
+
+    /**
+     * Returns the login module configuration.
+     *
+     * @return login module configuration, or <code>null</code> if standard
+     *         JAAS mechanism should be used.
+     */
+    public LoginModuleConfig getLoginModuleConfig() {
+        return lmc;
+    }
+
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/SecurityManagerConfig.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/SecurityManagerConfig.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/SecurityManagerConfig.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/SecurityManagerConfig.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,72 @@
+package cgl.shindig.config;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Security manager configuration. This bean configuration class
+ * is used to create configured security manager objects.
+ * <p>
+ * This class is currently only used to assign a static type to
+ * more generic bean configuration information.
+ *
+ * @see SecurityConfig#getSecurityManagerConfig()
+ */
+public class SecurityManagerConfig extends BeanConfig {
+    private Logger logger =
+      LoggerFactory.getLogger(SecurityManagerConfig.class.getName());
+
+    private final BeanConfig userManagerConfig;
+
+    public SecurityManagerConfig(BeanConfig config) {
+        this(config, null);
+    }
+
+    public SecurityManagerConfig(BeanConfig config,
+                                 BeanConfig userManagerConfig) {
+        super(config);
+        this.userManagerConfig = userManagerConfig;
+    }
+
+    public BeanConfig getUserManagerConfig() {
+        return userManagerConfig;
+    }
+    
+    public Properties getUserManagerConfigProps() {
+        BeanConfig umc = getUserManagerConfig();
+        Properties config = null;
+        if (umc != null) {
+            String clName = umc.getClassName();
+            //FIXME: need to check validity of clName
+            if (clName != null && clName.length() == 0) {
+                logger.warn("Unsupported custom UserManager implementation: '" + clName + "' -> Ignored.");
+            }
+            config = umc.getParameters();
+        }
+        return config;
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/portal.xml
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/portal.xml?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/portal.xml (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/config/portal.xml Fri Apr  1 00:29:22 2011
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+<config>
+  <Security appName="ogce_portal">
+    <SecurityManager class=""> <!--bean-->
+      <UserManager class="">
+        <param name="subsystem" value=""/>
+      </UserManager>
+    </SecurityManager>
+    <AccessManager class="">
+      <param name="name" value="value"/>
+    </AccessManager>
+    <LoginModule class="cgl.shindig.security.DefaultLoginModule">
+      <param name="anonymousId" value="anonymous"/>
+      <param name="adminId" value="admin"/>
+    </LoginModule>
+  </Security>
+</config>

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Description.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Description.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Description.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Description.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,78 @@
+package cgl.shindig.gram5.bean;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.util.Date;
+
+public class Description {
+	private String submissionId;
+	private Date submissionTime;
+	private String concurrency;
+	private int batches;
+	private String endPoint;
+	private String userId;
+	private String status;
+	public String getSubmissionId() {
+		return submissionId;
+	}
+	public void setSubmissionId(String submissionId) {
+		this.submissionId = submissionId;
+	}
+	public Date getSubmissionTime() {
+		return submissionTime;
+	}
+	public void setSubmissionTime(Date submissionTime) {
+		this.submissionTime = submissionTime;
+	}
+	public String getConcurrency() {
+		return concurrency;
+	}
+	public void setConcurrency(String concurrency) {
+		this.concurrency = concurrency;
+	}
+	public int getBatches() {
+		return batches;
+	}
+	public void setBatches(int batches) {
+		this.batches = batches;
+	}
+	public String getEndPoint() {
+		return endPoint;
+	}
+	public void setEndPoint(String endPoint) {
+		this.endPoint = endPoint;
+	}
+	public String getUserId() {
+		return userId;
+	}
+	public void setUserId(String userId) {
+		this.userId = userId;
+	}
+	public String getStatus() {
+		return status;
+	}
+	public void setStatus(String status) {
+		this.status = status;
+	}
+	
+	
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Detail.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Detail.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Detail.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Detail.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,83 @@
+package cgl.shindig.gram5.bean;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+public class Detail {
+	private String submissionId;
+	private String jobId;
+	private String status;
+	private long initTime;
+	private long queueTime;
+	private long runTime;
+	private long totalTime;
+	private String failReason;
+	public String getSubmissionId() {
+		return submissionId;
+	}
+	public void setSubmissionId(String submissionId) {
+		this.submissionId = submissionId;
+	}
+	public String getJobId() {
+		return jobId;
+	}
+	public void setJobId(String jobId) {
+		this.jobId = jobId;
+	}
+	public String getStatus() {
+		return status;
+	}
+	public void setStatus(String status) {
+		this.status = status;
+	}
+	public long getInitTime() {
+		return initTime;
+	}
+	public void setInitTime(long initTime) {
+		this.initTime = initTime;
+	}
+	public long getQueueTime() {
+		return queueTime;
+	}
+	public void setQueueTime(long queueTime) {
+		this.queueTime = queueTime;
+	}
+	public long getRunTime() {
+		return runTime;
+	}
+	public void setRunTime(long runTime) {
+		this.runTime = runTime;
+	}
+	public long getTotalTime() {
+		return totalTime;
+	}
+	public void setTotalTime(long totalTime) {
+		this.totalTime = totalTime;
+	}
+	public String getFailReason() {
+		return failReason;
+	}
+	public void setFailReason(String failReason) {
+		this.failReason = failReason;
+	}
+	
+	
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Summation.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Summation.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Summation.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/bean/Summation.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,82 @@
+package cgl.shindig.gram5.bean;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+public class Summation {
+	private String submissionId;
+	private int concurrency;
+	private int batchNumber;
+	private double avgInitTime;
+	private double avgQueueTime;
+	private double avgRunTime;
+	private double avgTotalTime;
+	private int failJob;
+	public String getSubmissionId() {
+		return submissionId;
+	}
+	public void setSubmissionId(String submissionId) {
+		this.submissionId = submissionId;
+	}
+	public int getConcurrency() {
+		return concurrency;
+	}
+	public void setConcurrency(int concurrency) {
+		this.concurrency = concurrency;
+	}
+	public int getBatchNumber() {
+		return batchNumber;
+	}
+	public void setBatchNumber(int batchNumber) {
+		this.batchNumber = batchNumber;
+	}
+	public double getAvgInitTime() {
+		return avgInitTime;
+	}
+	public void setAvgInitTime(double avgInitTime) {
+		this.avgInitTime = avgInitTime;
+	}
+	public double getAvgQueueTime() {
+		return avgQueueTime;
+	}
+	public void setAvgQueueTime(double avgQueueTime) {
+		this.avgQueueTime = avgQueueTime;
+	}
+	public double getAvgRunTime() {
+		return avgRunTime;
+	}
+	public void setAvgRunTime(double avgRunTime) {
+		this.avgRunTime = avgRunTime;
+	}
+	public double getAvgTotalTime() {
+		return avgTotalTime;
+	}
+	public void setAvgTotalTime(double avgTotalTime) {
+		this.avgTotalTime = avgTotalTime;
+	}
+	public int getFailJob() {
+		return failJob;
+	}
+	public void setFailJob(int failJob) {
+		this.failJob = failJob;
+	}
+	
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/servlet/MySqlAdapter.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/servlet/MySqlAdapter.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/servlet/MySqlAdapter.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/servlet/MySqlAdapter.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,188 @@
+package cgl.shindig.gram5.servlet;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import cgl.shindig.gram5.bean.Description;
+import cgl.shindig.gram5.bean.Summation;
+
+public class MySqlAdapter {
+
+	private static final Logger log = Logger.getLogger(MySqlAdapter.class.getName());
+	private Connection conn;
+
+	private static MySqlAdapter instance;
+
+	private static final String PROPERTY_FILE = "gram5.properties";
+
+	private static final String MYSQL_URL_PROP = "mysql.url";
+	private static final String MYSQL_USERNAME_PROP = "mysql.username";
+	private static final String MYSQL_PASSWORD_PROP = "mysql.password";
+
+	private String mySqlUrl;
+	private String mySqlUsername;
+	private String mySqlPassword;
+
+	private MySqlAdapter() {
+		try {
+
+			ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+			InputStream inputStream = classLoader.getResourceAsStream(PROPERTY_FILE);
+			if (inputStream == null) {
+				throw new FileNotFoundException(PROPERTY_FILE + " cannot be found");
+			}
+			Properties properties = new Properties();
+			properties.load(inputStream);
+
+			/*
+			 * my sql parameters
+			 */
+			mySqlUrl = properties.getProperty(MYSQL_URL_PROP);
+			mySqlUsername = properties.getProperty(MYSQL_USERNAME_PROP);
+			mySqlPassword = properties.getProperty(MYSQL_PASSWORD_PROP);
+
+		} catch (Exception e) {
+			e.printStackTrace();
+			log.severe(e.getLocalizedMessage());
+			System.exit(-1);
+		}
+	}
+
+	private Connection createConnection() throws Exception {
+		if (conn == null) {
+			Class.forName("com.mysql.jdbc.Driver");
+
+			conn = DriverManager.getConnection(mySqlUrl, mySqlUsername, mySqlPassword);
+
+			// Display URL and connection information
+			log.info("URL: " + mySqlUrl);
+			log.info("Connection: " + conn);
+		}
+		return conn;
+	}
+
+	private void closeConnection(){
+		try{
+			if(conn != null){
+				conn.close();
+				conn = null;
+			}
+		}catch (Exception e) {
+			e.printStackTrace();
+		}
+	}	
+	
+	public static MySqlAdapter getInstance() {
+		if (instance == null) {
+			instance = new MySqlAdapter();
+		}
+		return instance;
+	}
+	
+	public ArrayList<Description> getDescription(String userId) {
+		Statement stmt = null;
+		ArrayList<Description> result = new ArrayList<Description>();
+		try {
+
+			String sql = "SELECT * FROM Description WHERE user_id = '" + userId + "' ORDER BY submission_time DESC";
+
+			Connection con = createConnection();
+			stmt = con.createStatement();
+			ResultSet resultSet = stmt.executeQuery(sql);
+			
+			while(resultSet.next()){
+				Description d = new Description();
+				d.setSubmissionId(resultSet.getString("submission_id"));
+				d.setSubmissionTime(resultSet.getTimestamp("submission_time"));
+				d.setStatus(resultSet.getString("status"));
+				d.setConcurrency(resultSet.getString("concurrency"));				
+				d.setBatches(resultSet.getInt("batches"));
+				d.setEndPoint(resultSet.getString("server_endpoint"));
+				d.setUserId(resultSet.getString("user_id"));
+				
+				result.add(d);
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			if (stmt != null) {
+				try {
+					stmt.close();
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+			closeConnection();
+		}
+		return result;
+	}
+	
+	public ArrayList<Summation> getSummation(String submissionId) {
+		Statement stmt = null;
+		ArrayList<Summation> result = new ArrayList<Summation>();
+		try {
+
+			String sql = "SELECT * FROM Summation WHERE submission_id = '" + submissionId + "' ORDER BY batch_number";
+
+			Connection con = createConnection();
+			stmt = con.createStatement();
+			ResultSet resultSet = stmt.executeQuery(sql);
+			
+			while(resultSet.next()){
+				Summation s = new Summation();
+				s.setSubmissionId(resultSet.getString("submission_id"));
+				s.setBatchNumber(resultSet.getInt("batch_number"));
+				s.setConcurrency(resultSet.getInt("concurrency"));
+				s.setAvgInitTime(resultSet.getDouble("avg_init_time"));
+				s.setAvgQueueTime(resultSet.getDouble("avg_queue_time"));
+				s.setAvgRunTime(resultSet.getDouble("avg_run_time"));
+				s.setAvgTotalTime(resultSet.getDouble("avg_total_time"));
+				s.setFailJob(resultSet.getInt("fail_jobs"));
+				
+				result.add(s);
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			if (stmt != null) {
+				try {
+					stmt.close();
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+			closeConnection();
+		}
+		return result;
+	}	
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/servlet/ResultQueryServlet.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/servlet/ResultQueryServlet.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/servlet/ResultQueryServlet.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/gram5/servlet/ResultQueryServlet.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,150 @@
+package cgl.shindig.gram5.servlet;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import cgl.shindig.InjectedServlet;
+import cgl.shindig.gram5.bean.Description;
+import cgl.shindig.gram5.bean.Summation;
+
+public class ResultQueryServlet extends InjectedServlet {
+
+	private static final Logger log = Logger.getLogger(ResultQueryServlet.class.getName());
+
+	private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+	private static final DecimalFormat NUMBER_FORMAT = new DecimalFormat("0.###");
+
+	public static final String ACTION = "action";
+	public static final String USER_ID = "userid";
+	public static final String JOB_ID = "jobid";
+
+	public static final String ACTION_GET_JOBS = "get-all-jobs";
+	public static final String ACTION_GET_RESULT = "get-job";
+
+	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		process(request, response);
+	}
+
+	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		process(request, response);
+	}
+
+	private void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		String action = request.getParameter(ACTION);
+		if (action == null) {
+			response.getWriter().print("Please specify action.");
+			return;
+		}
+
+		if (action.equals(ACTION_GET_JOBS)) {
+			String user = request.getParameter(USER_ID);
+			if (user == null) {
+				response.getWriter().print("Please specify user.");
+				return;
+			}
+			getJobSumissions(user, response);
+		} else if (action.equals(ACTION_GET_RESULT)) {
+			String job = request.getParameter(JOB_ID);
+			if (job == null) {
+				response.getWriter().print("Please specify submission id.");
+				return;
+			}
+			getJob(job, response);
+		} else {
+			response.getWriter().print("Invalid action.");
+		}
+
+	}
+
+	public void getJobSumissions(String userId, HttpServletResponse response) throws ServletException, IOException {
+		StringBuilder sb = new StringBuilder();
+		String[] result = null;
+		try {
+			ArrayList<Description> list = MySqlAdapter.getInstance().getDescription(userId);
+			result = new String[list.size()];
+			int count = 0;
+			for (Iterator<Description> iterator = list.iterator(); iterator.hasNext();) {
+				Description description = iterator.next();
+				sb.append(description.getSubmissionId());
+				sb.append(",");
+				sb.append(DATE_FORMAT.format(description.getSubmissionTime()));
+				sb.append(",");
+				sb.append(description.getStatus());
+				sb.append(",");
+				sb.append(description.getConcurrency());
+				sb.append(",");
+				sb.append(description.getBatches());
+				sb.append(",");
+				sb.append(description.getEndPoint());
+
+				result[count++] = sb.toString();
+				sb.delete(0, sb.length());
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		for (String string : result) {
+			response.getWriter().println(string);
+		}
+
+	}
+
+	public void getJob(String submissionId, HttpServletResponse response) throws ServletException, IOException {
+		StringBuilder sb = new StringBuilder();
+		String[] result = null;
+		try {
+			ArrayList<Summation> list = MySqlAdapter.getInstance().getSummation(submissionId);
+			result = new String[list.size()];
+			int count = 0;
+			for (Iterator<Summation> iterator = list.iterator(); iterator.hasNext();) {
+				Summation summation = iterator.next();
+				sb.append(NUMBER_FORMAT.format(summation.getAvgInitTime() / (double) 1000));
+				sb.append(",");
+				sb.append(NUMBER_FORMAT.format(summation.getAvgQueueTime() / (double) 1000));
+				sb.append(",");
+				sb.append(NUMBER_FORMAT.format(summation.getAvgRunTime() / (double) 1000));
+				sb.append(",");
+				sb.append(NUMBER_FORMAT.format(summation.getAvgTotalTime() / (double) 1000));
+				sb.append(",");
+				sb.append(summation.getFailJob());
+
+				result[count++] = sb.toString();
+				sb.delete(0, sb.length());
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		for (String string : result) {
+			response.getWriter().println(string);
+		}
+	}
+}

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/heartbeat/servlet/HeartBeatServlet.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/heartbeat/servlet/HeartBeatServlet.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/heartbeat/servlet/HeartBeatServlet.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/heartbeat/servlet/HeartBeatServlet.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,78 @@
+package cgl.shindig.heartbeat.servlet;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.io.*;
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import cgl.shindig.usermanage.*;
+
+/** 
+ * Above comment is correct?  I'm not sure why this serlvet is needed. Seems to be there
+ * to make sure the session hasn't (or doesn't expire) as long as the gadget container (HTML
+ * and JavaScript) are alive.
+ */
+/**
+ * Yes, you are right.
+ * I just removed the old comment.
+ * This script is used to keep the session alive. I wrote this class based on
+ * our prior discussion long time ago. We assumed that it is helpful to
+ * maintain the session even if the user has been idle for long time.
+ */
+public class HeartBeatServlet extends HttpServlet{
+ 
+    public void doPost(HttpServletRequest request, HttpServletResponse response)
+            throws javax.servlet.ServletException, java.io.IOException{
+        response.setContentType("application/json");
+        try {
+            heartbeatMaintain(request, response);
+        } catch(Exception ex) {
+            PrintWriter out = response.getWriter();
+            out.write("{\"error\": \"" + ex.toString() + "\"}");
+        }
+    }
+
+    /* only POST request is accepted */
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws javax.servlet.ServletException, java.io.IOException{
+        response.setContentType("application/json");
+        try {
+            heartbeatMaintain(request, response);
+        } catch(Exception ex) {
+            PrintWriter out = response.getWriter();
+            out.write("{\"error\": \"" + ex.toString() + "\"}");
+        }
+    }
+
+    public void heartbeatMaintain(HttpServletRequest request, HttpServletResponse response) 
+            throws ServletException, IOException {
+        HttpSession session = request.getSession(false);
+        if (session == null) {
+            throw new ServletException("Cannot find session");
+        }
+        PrintWriter out = response.getWriter();
+        out.write("{}");
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/LayoutRESTOPException.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/LayoutRESTOPException.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/LayoutRESTOPException.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/LayoutRESTOPException.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,38 @@
+package cgl.shindig.layoutmanager;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+public class LayoutRESTOPException extends Exception {
+    public LayoutRESTOPException () {
+        super();
+    }
+    public LayoutRESTOPException (String message) {
+        super(message);
+    }
+    public LayoutRESTOPException (String message, Throwable cause) {
+        super(message, cause);
+    }
+    public LayoutRESTOPException (Throwable cause) {
+        super(cause);
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/JSONSerializer.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/JSONSerializer.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/JSONSerializer.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/JSONSerializer.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,30 @@
+package cgl.shindig.layoutmanager.data;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import org.json.JSONObject;
+
+public interface JSONSerializer <T> {
+    String convertToString(T t) throws Exception;
+    JSONObject convertToObj(T t) throws Exception;
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/Layout.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/Layout.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/Layout.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/Layout.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,194 @@
+package cgl.shindig.layoutmanager.data;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import cgl.shindig.layoutmanager.LayoutRESTOPException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+public class Layout {
+    private List<LayoutTab> layoutTabs = new ArrayList<LayoutTab>();
+    private static final String errorTxtNonExist =
+        "The tab you specified does not exist";
+    private static final String errorTxtAddIndex =
+        "The index of the new tab is not correct. \n" +
+        "If you want to append it, use -1;\n" +
+        "If you want to insert it, use value bewteen 0 (inclusive) and " +
+        "# of existing tabs (inclusive) within its containing layout.";
+
+    private String name = "";
+    private int activeTabIdx = -1;  //FIXME: check whether -1 is appropriate
+    private String layoutType;      //FIXME: should be an enum?
+    private Map properties = new HashMap<String, Object>();
+
+    /**
+     * get the value of properties
+     * @return the value of properties
+     */
+    public Map getProperties(){
+        return this.properties;
+    }
+    /**
+     * set a new value to properties
+     * @param properties the new value to be used
+     */
+    public void setProperties(Map properties) {
+        this.properties=properties;
+    }
+
+    public void setProperty(String name, Object value) {
+        properties.put(name, value);
+    }
+    public Object getProperty(String name) {
+        return properties.get(name);
+    }
+
+    /**
+     * get the value of layoutType
+     * @return the value of layoutType
+     */
+    public String getLayoutType(){
+        return this.layoutType;
+    }
+    /**
+     * set a new value to layoutType
+     * @param layoutType the new value to be used
+     */
+    public void setLayoutType(String layoutType) {
+        this.layoutType=layoutType;
+    }
+
+    /**
+     * get the value of activeTabIdx
+     * @return the value of activeTabIdx
+     */
+    public int getActiveTabIdx(){
+        return this.activeTabIdx;
+    }
+    /**
+     * set a new value to activeTabIdx
+     * @param activeTabIdx the new value to be used
+     */
+    public void setActiveTabIdx(int activeTabIdx) {
+        this.activeTabIdx=activeTabIdx;
+    }
+
+    /**
+     * get the value of name
+     * @return the value of name
+     */
+    public String getName(){
+        return this.name;
+    }
+    /**
+     * set a new value to name
+     * @param name the new value to be used
+     */
+    public void setName(String name) {
+        this.name=name;
+    }
+
+    // create
+    //
+    public void addATab(LayoutTab tab) {
+        layoutTabs.add(tab);
+    }
+    public void addATab(int index, LayoutTab tab) throws LayoutRESTOPException {
+        if (index >= 0 && index <= layoutTabs.size()) {
+            layoutTabs.add(index, tab);
+        } else {
+            throw new LayoutRESTOPException(errorTxtAddIndex);
+        }
+    }
+
+    // delete
+    //
+    public LayoutTab removeATabByIdx(int index) throws LayoutRESTOPException {
+        if (index >=0 && index < layoutTabs.size()) {
+            return layoutTabs.remove(index);
+        } else {
+            throw new LayoutRESTOPException(errorTxtNonExist);
+        }
+    }
+    public LayoutTab removeATabByName(String tabname) throws LayoutRESTOPException {
+        for (Iterator<LayoutTab> it = layoutTabs.iterator(); it.hasNext();) {
+            LayoutTab tab = it.next();
+            if (tab.getTabName() != null && tab.getTabName().equals(tabname)) {
+                it.remove();
+                return tab;
+            }
+        }
+        throw new LayoutRESTOPException(errorTxtNonExist);
+    }
+
+    // retrieval
+    //
+    public LayoutTab getATabByIdx(int index) throws LayoutRESTOPException {
+        if (index >=0 && index < layoutTabs.size()) {
+            return layoutTabs.get(index);
+        } else {
+            throw new LayoutRESTOPException(errorTxtNonExist);
+        }
+    }
+
+    public LayoutTab getATabByName(String tabname) throws LayoutRESTOPException {
+        for (Iterator<LayoutTab> it = layoutTabs.iterator(); it.hasNext();) {
+            LayoutTab tab = it.next();
+            if (tab.getTabName() != null && tab.getTabName().equals(tabname)) {
+                return tab;
+            }
+        }
+        throw new LayoutRESTOPException(errorTxtNonExist);
+    }
+
+    public Collection<LayoutTab> getTabs() {
+        return layoutTabs;
+    }
+
+    // update
+    //
+    public LayoutTab updateATabByIdx(int index, LayoutTab tab)
+            throws LayoutRESTOPException {
+        if (index >=0 && index < layoutTabs.size()) {
+            return layoutTabs.set(index, tab);
+        } else {
+            throw new LayoutRESTOPException(errorTxtNonExist);
+        }
+    }
+
+    public LayoutTab updateATabByName(String tabname, LayoutTab newTab)
+            throws LayoutRESTOPException {
+        for (int i = 0; i < layoutTabs.size(); ++i) {
+            LayoutTab tab = layoutTabs.get(i);
+            if (tab.getTabName() != null && tab.getTabName().equals(tabname)) {
+                return layoutTabs.set(i, newTab);
+            }
+        }
+        throw new LayoutRESTOPException(errorTxtNonExist);
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutBuilder.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutBuilder.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutBuilder.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutBuilder.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,139 @@
+package cgl.shindig.layoutmanager.data;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import cgl.shindig.common.JSONHelper;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/** 
+ * This class builds LayoutSuite instance from data in DB.
+ * 
+ * @author 
+ * @version 
+ */
+@Singleton
+public class LayoutBuilder {
+
+    private boolean restrict = false;
+    
+    private static final String errorTxtLSNonExist =
+        "The layout of the user cannot be retrieved. Make sure the parameters are correct";
+
+    private LayoutTabBuilder layoutTabBuilder;
+
+    @Inject
+    public void setLayoutTabBuilder(LayoutTabBuilder layoutTabBuilder) {
+        this.layoutTabBuilder = layoutTabBuilder;
+    }
+
+    /**
+    Sample raw data:
+    {
+      "layouttype":"js-tab-layout",
+      "activetabidx":9,
+      "properties":{
+         sync:"auto",
+         theme:"default_theme"
+      },
+      "layoutdata":[
+         {
+            "tabname":"My Gadgets",
+            "tabid":"_tab_0",
+            "column":3,
+            "content":[
+               {
+                  "columnname":"undefined",
+                  "columnid":"_tab_0_col_0",
+                  "content":[
+                     {
+                        "gadgetname":"RSS Feeds",
+                        "gadgetspecsrc":"https://gf18.ucs.indiana.edu:7443/gadgets-repo/rssreader.xml",
+                        "gadgetrendersrc":"undefined",
+                        "gadgetid":"_tab_0_col_0_gadget_0",
+                        "userpref":{
+
+                        },
+                        "status":"normal"
+                     }]
+               }, {
+                  "columnname":"undefined",
+                  "columnid":"_tab_0_col_1",
+                  "content":[ ]
+               }, {
+                  "columnname":"undefined",
+                  "columnid":"_tab_0_col_2",
+                  "content":[ ]
+               }
+            ]
+         }
+      ]
+    }
+    */
+    public static String keyLayoutType     = "layouttype";
+    public static String keyActiveTabIdx   = "activetabidx";
+    public static String keyProperties     = "properties";
+    public static String keyLayoutData     = "layoutdata";
+    public static String keyLayoutName     = "layoutname";
+
+    public Layout build(String wholeLayoutRawdata) throws JSONException {
+        JSONObject wholeLayoutObj = new JSONObject(wholeLayoutRawdata);
+        return build(wholeLayoutObj);
+    }
+
+    public Layout build(JSONObject wholeLayoutObj) throws JSONException {
+        Layout layout = new Layout();
+
+        // FIXME: default value
+        String layoutType = wholeLayoutObj.optString(keyLayoutType, "js-tab-layout");
+        layout.setLayoutType(layoutType);
+
+        // FIXME: default value
+        int activetabidx = wholeLayoutObj.optInt(keyActiveTabIdx, -1);
+        layout.setActiveTabIdx(activetabidx);
+
+        JSONObject propertiesObj = wholeLayoutObj.optJSONObject(keyProperties);
+        if (propertiesObj != null)
+            layout.setProperties(JSONHelper.jsonObj2Map(propertiesObj));
+
+        JSONArray tabArray = wholeLayoutObj.getJSONArray(keyLayoutData);
+        for (int i = 0; i < tabArray.length(); ++i) {
+            if (tabArray.isNull(i)) {
+                continue;
+            } else {
+                JSONObject tabObj = tabArray.getJSONObject(i);
+                LayoutTab tab = layoutTabBuilder.build(tabObj);
+                layout.addATab(tab);
+            }
+        }
+        return layout;
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumn.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumn.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumn.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumn.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,119 @@
+package cgl.shindig.layoutmanager.data;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import cgl.shindig.layoutmanager.LayoutRESTOPException;
+
+public class LayoutColumn {
+    private List<LayoutGadget> layoutGadgets = new ArrayList<LayoutGadget>();
+    private static final String errorTxtNonExist =
+        "The gadget you specified does not exist";
+    private static final String errorTxtAddIndex =
+        "The index of the new gadget is not correct. \n" +
+        "If you want to append it, use -1;\n" +
+        "If you want to insert it, use value bewteen 0 (inclusive) and " +
+        "# of existing gadgets (inclusive) within its containing column";
+
+    private String columnName;
+    private String columnId;
+
+    /**
+     * get the value of columnName
+     * @return the value of columnName
+     */
+    public String getColumnName(){
+        return this.columnName;
+    }
+    /**
+     * set a new value to columnName
+     * @param columnName the new value to be used
+     */
+    public void setColumnName(String columnName) {
+        this.columnName=columnName;
+    }
+    /**
+     * get the value of columnId
+     * @return the value of columnId
+     */
+    public String getColumnId(){
+        return this.columnId;
+    }
+    /**
+     * set a new value to columnId
+     * @param columnId the new value to be used
+     */
+    public void setColumnId(String columnId) {
+        this.columnId=columnId;
+    }
+    // create
+    //
+    public void addAGadget(LayoutGadget gadget) {
+        layoutGadgets.add(gadget);
+    }
+    public void addAGadget(int index, LayoutGadget gadget) throws LayoutRESTOPException {
+        if (index >= 0 && index <= layoutGadgets.size()) {
+            layoutGadgets.add(index, gadget);
+        } else {
+            throw new LayoutRESTOPException(errorTxtAddIndex);
+        }
+    }
+
+    // delete
+    //
+    public LayoutGadget removeAGadgetByIdx(int index) throws LayoutRESTOPException {
+        if (index >= 0 && index < layoutGadgets.size()) {
+            return layoutGadgets.remove(index);
+        } else {
+            throw new LayoutRESTOPException(errorTxtNonExist);
+        }
+    }
+
+    // retrieval
+    //
+    public LayoutGadget getAGadgetByIdx(int index) throws LayoutRESTOPException {
+        if (index >=0 && index < layoutGadgets.size()) {
+            return layoutGadgets.get(index);
+        } else {
+            throw new LayoutRESTOPException(errorTxtNonExist);
+        }
+    }
+
+    public Collection<LayoutGadget> getGadgets() {
+        return layoutGadgets;
+    }
+
+    // update
+    //
+    public LayoutGadget updateAGadgetByIdx(int index, LayoutGadget gadget)
+            throws LayoutRESTOPException {
+        if (index >=0 && index < layoutGadgets.size()) {
+            return layoutGadgets.set(index, gadget);
+        } else {
+            throw new LayoutRESTOPException(errorTxtNonExist);
+        }
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumnBuilder.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumnBuilder.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumnBuilder.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumnBuilder.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,92 @@
+package cgl.shindig.layoutmanager.data;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/** 
+ * This class builds LayoutSuite instance from data in DB.
+ * 
+ * @author 
+ * @version 
+ */
+@Singleton
+public class LayoutColumnBuilder {
+    
+    private static final String errorTxtLSNonExist =
+        "The layout of the user cannot be retrieved. Make sure the parameters are correct";
+
+    private LayoutGadgetBuilder layoutGadgetBuilder;
+
+    @Inject
+    public void setLayoutGadgetBuilder(LayoutGadgetBuilder layoutGadgetBuilder) {
+        this.layoutGadgetBuilder=layoutGadgetBuilder;
+    }
+
+    /**
+    Sample raw data:
+       {
+          "columnname":"undefined",
+          "columnid":"_tab_0_col_0",
+          "content":[ { }, { }]
+       }
+    */
+    public static String keyColumnName     = "columnname";
+    public static String keyColumnId       = "columnd";
+    public static String keyContent        = "content";
+
+    public LayoutColumn build(String layoutColumnRawdata) throws JSONException {
+        JSONObject layoutColumnObj = new JSONObject(layoutColumnRawdata);
+        return build(layoutColumnObj);
+    }
+
+    public LayoutColumn build(JSONObject layoutColumnObj) throws JSONException {
+        LayoutColumn layoutColumn = new LayoutColumn();
+
+        String columnname = layoutColumnObj.optString(keyColumnName);
+        layoutColumn.setColumnName(columnname);
+
+        String columnid = layoutColumnObj.optString(keyColumnId);
+        layoutColumn.setColumnId(columnid);
+
+        JSONArray gadgetArray = layoutColumnObj.getJSONArray(keyContent);
+        for (int i = 0; i < gadgetArray.length(); ++i) {
+            if (gadgetArray.isNull(i)) {
+                continue;
+            } else {
+                JSONObject gadgetObj = gadgetArray.getJSONObject(i);
+                LayoutGadget gadget = layoutGadgetBuilder.build(gadgetObj);
+                layoutColumn.addAGadget(gadget);
+            }
+        }
+        return layoutColumn;
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumnJSONSerializer.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumnJSONSerializer.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumnJSONSerializer.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutColumnJSONSerializer.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,58 @@
+package cgl.shindig.layoutmanager.data;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.util.Iterator;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class LayoutColumnJSONSerializer implements JSONSerializer<LayoutColumn> {
+
+    public String convertToString(LayoutColumn layoutColumn) throws Exception {
+        return convertToObj(layoutColumn).toString();
+    }
+
+    public JSONObject convertToObj(LayoutColumn layoutColumn) throws Exception {
+        LayoutGadgetJSONSerializer layoutGadgetSerializer = 
+            new LayoutGadgetJSONSerializer();
+
+        JSONObject layoutColumnObj = new JSONObject();
+
+        String name = layoutColumn.getColumnName();
+        String id = layoutColumn.getColumnId();
+
+        layoutColumnObj.put(LayoutColumnBuilder.keyColumnName, name);
+        layoutColumnObj.put(LayoutColumnBuilder.keyColumnId, id);
+
+        JSONArray gadgetArray = new JSONArray();
+        for (Iterator<LayoutGadget> it = layoutColumn.getGadgets().iterator(); it.hasNext();) {
+            LayoutGadget gadget = it.next();
+            gadgetArray.put(layoutGadgetSerializer.convertToObj(gadget));
+        }
+
+        layoutColumnObj.put(LayoutColumnBuilder.keyContent, gadgetArray);
+        return layoutColumnObj;
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadget.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadget.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadget.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadget.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,133 @@
+package cgl.shindig.layoutmanager.data;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import cgl.shindig.layoutmanager.LayoutRESTOPException;
+
+public class LayoutGadget {
+    private String gadgetName;
+    private String gadgetId;
+    private String gadgetSpecSrc;
+    private String gadgetRenderSrc;
+    private String gadgetStatus;
+    private Map    gadgetUserPrefs = new HashMap<String, Object>();
+
+    public void setUserPref(String name, String value) {
+        gadgetUserPrefs.put(name, value);
+    }
+    public Object getUserPref(String name) {
+        return gadgetUserPrefs.get(name);
+    }
+
+    /**
+     * get the value of gadgetUserPrefs
+     * @return the value of gadgetUserPrefs
+     */
+    public Map getGadgetUserPrefs(){
+        return this.gadgetUserPrefs;
+    }
+    /**
+     * set a new value to gadgetUserPrefs
+     * @param gadgetUserPrefs the new value to be used
+     */
+    public void setGadgetUserPrefs(Map gadgetUserPrefs) {
+        this.gadgetUserPrefs=gadgetUserPrefs;
+    }
+
+    /**
+     * get the value of gadgetStatus
+     * @return the value of gadgetStatus
+     */
+    public String getGadgetStatus(){
+        return this.gadgetStatus;
+    }
+    /**
+     * set a new value to gadgetStatus
+     * @param gadgetStatus the new value to be used
+     */
+    public void setGadgetStatus(String gadgetStatus) {
+        this.gadgetStatus=gadgetStatus;
+    }
+    /**
+     * get the value of gadgetRenderSrc
+     * @return the value of gadgetRenderSrc
+     */
+    public String getGadgetRenderSrc(){
+        return this.gadgetRenderSrc;
+    }
+    /**
+     * set a new value to gadgetRenderSrc
+     * @param gadgetRenderSrc the new value to be used
+     */
+    public void setGadgetRenderSrc(String gadgetRenderSrc) {
+        this.gadgetRenderSrc=gadgetRenderSrc;
+    }
+    /**
+     * get the value of gadgetSpecSrc
+     * @return the value of gadgetSpecSrc
+     */
+    public String getGadgetSpecSrc(){
+        return this.gadgetSpecSrc;
+    }
+    /**
+     * set a new value to gadgetSpecSrc
+     * @param gadgetSpecSrc the new value to be used
+     */
+    public void setGadgetSpecSrc(String gadgetSpecSrc) {
+        this.gadgetSpecSrc=gadgetSpecSrc;
+    }
+    /**
+     * get the value of gadgetId
+     * @return the value of gadgetId
+     */
+    public String getGadgetId(){
+        return this.gadgetId;
+    }
+    /**
+     * set a new value to gadgetId
+     * @param gadgetId the new value to be used
+     */
+    public void setGadgetId(String gadgetId) {
+        this.gadgetId=gadgetId;
+    }
+
+    /**
+     * get the value of gadgetName
+     * @return the value of gadgetName
+     */
+    public String getGadgetName(){
+        return this.gadgetName;
+    }
+    /**
+     * set a new value to gadgetName
+     * @param gadgetName the new value to be used
+     */
+    public void setGadgetName(String gadgetName) {
+        this.gadgetName=gadgetName;
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadgetBuilder.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadgetBuilder.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadgetBuilder.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadgetBuilder.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,93 @@
+package cgl.shindig.layoutmanager.data;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import cgl.shindig.common.JSONHelper;
+
+import com.google.inject.Singleton;
+
+/** 
+ * This class builds LayoutSuite instance from data in DB.
+ * 
+ * @author 
+ * @version 
+ */
+@Singleton
+public class LayoutGadgetBuilder {
+    
+    /**
+    Sample raw data:
+        {
+            "gadgetname":"RSS Feeds",
+            "gadgetspecsrc":"https://gf18.ucs.indiana.edu:7443/gadgets-repo/rssreader.xml",
+            "gadgetrendersrc":"undefined",
+            "gadgetid":"_tab_0_col_0_gadget_0",
+            "userpref":{ },
+            "status":"normal"
+        }
+    */
+    public static String keyGadgetName         = "gadgetname";
+    public static String keyGadgetId           = "gadgetid";
+    public static String keyGadgetSpecSrc      = "gadgetspecsrc";
+    public static String keyGadgetRenderSrc    = "gadgetrendersrc";
+    public static String keyGadgetUserPref     = "userpref";
+    public static String keyGadgetStatus       = "status";
+
+    public LayoutGadget build(String layoutGadgetRawdata) throws JSONException {
+        JSONObject layoutGadgetObj = new JSONObject(layoutGadgetRawdata);
+        return build(layoutGadgetObj);
+    }
+
+    public LayoutGadget build(JSONObject layoutGadgetObj) throws JSONException {
+        LayoutGadget layoutGadget = new LayoutGadget();
+
+        String gadgetname = layoutGadgetObj.getString(keyGadgetName);
+        layoutGadget.setGadgetName(gadgetname);
+
+        String gadgetid = layoutGadgetObj.optString(keyGadgetId);
+        layoutGadget.setGadgetId(gadgetid);
+
+        String gadgetspecsrc = layoutGadgetObj.getString(keyGadgetSpecSrc);
+        layoutGadget.setGadgetSpecSrc(gadgetspecsrc);
+
+        String gadgetrendersrc = layoutGadgetObj.optString(keyGadgetRenderSrc);
+        layoutGadget.setGadgetRenderSrc(gadgetrendersrc);
+
+        // FIXME: default value "normal"
+        String gadgetstatus = layoutGadgetObj.optString(keyGadgetStatus, "normal");
+        layoutGadget.setGadgetStatus(gadgetstatus);
+
+        JSONObject gadgetuserpref = layoutGadgetObj.optJSONObject(keyGadgetUserPref);
+        if (gadgetuserpref != null)
+            layoutGadget.setGadgetUserPrefs(JSONHelper.jsonObj2Map(gadgetuserpref));
+
+        return layoutGadget;
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadgetJSONSerializer.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadgetJSONSerializer.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadgetJSONSerializer.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutGadgetJSONSerializer.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,51 @@
+package cgl.shindig.layoutmanager.data;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+public class LayoutGadgetJSONSerializer implements JSONSerializer<LayoutGadget> {
+    public String convertToString(LayoutGadget layoutGadget) throws Exception {
+        return convertToObj(layoutGadget).toString();
+    }
+
+    public JSONObject convertToObj(LayoutGadget layoutGadget) throws Exception {
+        JSONObject layoutGadgetObj = new JSONObject();
+
+        layoutGadgetObj.put(LayoutGadgetBuilder.keyGadgetName, 
+                layoutGadget.getGadgetName());
+        layoutGadgetObj.put(LayoutGadgetBuilder.keyGadgetId,
+                layoutGadget.getGadgetId());
+        layoutGadgetObj.put(LayoutGadgetBuilder.keyGadgetSpecSrc,
+                layoutGadget.getGadgetSpecSrc());
+        layoutGadgetObj.put(LayoutGadgetBuilder.keyGadgetRenderSrc,
+                layoutGadget.getGadgetRenderSrc());
+        layoutGadgetObj.put(LayoutGadgetBuilder.keyGadgetStatus,
+                layoutGadget.getGadgetStatus());
+        layoutGadgetObj.put(LayoutGadgetBuilder.keyGadgetUserPref, 
+                new JSONObject(layoutGadget.getGadgetUserPrefs()));
+
+        return layoutGadgetObj;
+    }
+}
+

Added: incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutJSONSerializer.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutJSONSerializer.java?rev=1087520&view=auto
==============================================================================
--- incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutJSONSerializer.java (added)
+++ incubator/rave/donations/ogce-gadget-container/ishindig-webapp/src/main/java/cgl/shindig/layoutmanager/data/LayoutJSONSerializer.java Fri Apr  1 00:29:22 2011
@@ -0,0 +1,61 @@
+package cgl.shindig.layoutmanager.data;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class LayoutJSONSerializer implements JSONSerializer<Layout> {
+    public JSONObject convertToObj(Layout layout) throws Exception {
+        LayoutTabJSONSerializer layoutTabSerializer = new LayoutTabJSONSerializer();
+
+        JSONObject layoutObj = new JSONObject();
+
+        String name = layout.getName();
+        int activeTabIdx = layout.getActiveTabIdx();
+        String layoutType = layout.getLayoutType();
+        Map properties = layout.getProperties();
+
+        layoutObj.put(LayoutBuilder.keyLayoutType, layoutType);
+        layoutObj.put(LayoutBuilder.keyLayoutName, name);
+        layoutObj.put(LayoutBuilder.keyActiveTabIdx, activeTabIdx);
+        layoutObj.put(LayoutBuilder.keyProperties, new JSONObject(properties));
+
+        JSONArray tabArray = new JSONArray();
+        for (Iterator<LayoutTab> it = layout.getTabs().iterator(); it.hasNext();) {
+            LayoutTab tab = it.next();
+            tabArray.put(layoutTabSerializer.convertToObj(tab));
+        }
+
+        layoutObj.put(LayoutBuilder.keyLayoutData, tabArray);
+        return layoutObj;
+    }
+
+    public String convertToString(Layout layout) throws Exception {
+        return convertToObj(layout).toString();
+    }
+}
+



Mime
View raw message