You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2010/04/06 11:08:58 UTC

svn commit: r931057 - in /incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/clerezza/ src/main/java/org/ap...

Author: reto
Date: Tue Apr  6 09:08:57 2010
New Revision: 931057

URL: http://svn.apache.org/viewvc?rev=931057&view=rev
Log:
CLEREZZA-184: separate config gui

Added:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/   (with props)
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/NOTICE.txt
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/pom.xml
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/apache/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/apache/clerezza/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/apache/clerezza/platform/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/apache/clerezza/platform/config/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/apache/clerezza/platform/config/gui/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/apache/clerezza/platform/config/gui/PlatformConfigGui.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/META-INF/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/config.ssp
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/staticweb/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/staticweb/js/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/staticweb/js/platformconfig.js

Propchange: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Apr  6 09:08:57 2010
@@ -0,0 +1 @@
+target

Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/NOTICE.txt
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/NOTICE.txt?rev=931057&view=auto
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/NOTICE.txt (added)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/NOTICE.txt Tue Apr  6 09:08:57 2010
@@ -0,0 +1 @@
+

Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/pom.xml?rev=931057&view=auto
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/pom.xml (added)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/pom.xml Tue Apr  6 09:08:57 2010
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.clerezza</groupId>
+		<artifactId>org.apache.clerezza.parent</artifactId>
+		<version>0.2-incubating-SNAPSHOT</version>
+	</parent>
+	<groupId>org.apache.clerezza</groupId>
+	<artifactId>org.apache.clerezza.platform.config.gui</artifactId>
+	<version>0.1-incubating-SNAPSHOT</version>
+	<packaging>bundle</packaging>
+	<name>Clerezza - Platform Configuration GUI</name>
+	<description>This bundles initializes a GUI to
+		edit configuration options.
+	</description>
+	<dependencies>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.core</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.ontologies</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.utils</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.scr.annotations</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>javax.ws.rs</groupId>
+			<artifactId>jsr311-api</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.platform.dashboard.core</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.platform.graphprovider.content</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.web.fileserver</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.platform.config</artifactId>
+		</dependency>
+	</dependencies>
+</project>
+

Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/apache/clerezza/platform/config/gui/PlatformConfigGui.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/apache/clerezza/platform/config/gui/PlatformConfigGui.java?rev=931057&view=auto
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/apache/clerezza/platform/config/gui/PlatformConfigGui.java (added)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/java/org/apache/clerezza/platform/config/gui/PlatformConfigGui.java Tue Apr  6 09:08:57 2010
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+package org.apache.clerezza.platform.config.gui;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.AccessControlException;
+import java.security.AccessController;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.apache.clerezza.platform.config.PlatformConfig;
+import org.apache.clerezza.platform.config.SystemConfig;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Services;
+import org.apache.clerezza.platform.dashboard.GlobalMenuItem;
+import org.osgi.framework.Bundle;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.clerezza.platform.dashboard.GlobalMenuItemsProvider;
+import org.apache.clerezza.platform.typerendering.RenderletManager;
+import org.apache.clerezza.platform.typerendering.scalaserverpages.ScalaServerPagesRenderlet;
+import org.apache.clerezza.rdf.core.UriRef;
+
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.utils.GraphNode;
+
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
+import org.apache.clerezza.rdf.core.access.security.TcPermission;
+
+import org.apache.clerezza.rdf.ontologies.*;
+import org.apache.clerezza.web.fileserver.BundlePathNode;
+import org.apache.clerezza.web.fileserver.FileServer;
+import org.wymiwyg.commons.util.dirbrowser.PathNode;
+
+/**
+ * Provides a GUI to change platform default values.
+ *
+ * @author osr
+ */
+@Component
+@Services({
+	@Service(value = Object.class),
+	@Service(value = GlobalMenuItemsProvider.class)
+})
+@Property(name = "javax.ws.rs", boolValue = true)
+@Path("/admin/configuration")
+public class PlatformConfigGui implements GlobalMenuItemsProvider {
+
+	private final static char SLASH = '/';
+	@Reference
+	private PlatformConfig platformConfig;
+	@Reference
+	private RenderletManager renderletManager;
+	private final Logger logger = LoggerFactory.getLogger(getClass());
+	private final UriRef CONFIG_PAGE = new UriRef("http://clerezza.org/2009/08/platform#ConfigPage");
+	private FileServer fileServer;
+
+	protected void activate(ComponentContext context) throws IOException,
+			URISyntaxException {
+		Bundle bundle = context.getBundleContext().getBundle();
+		URL resourceDir = getClass().getResource("staticweb");
+		PathNode pathNode = new BundlePathNode(bundle, resourceDir.getPath());
+
+		logger.debug("Initializing file server for {} ({})", resourceDir,
+				resourceDir.getFile());
+
+		fileServer = new FileServer(pathNode);
+
+		URL template = getClass().getResource(
+				"config.ssp");
+		renderletManager.registerRenderlet(ScalaServerPagesRenderlet.class.getName(),
+				new UriRef(template.toURI().toString()),
+				CONFIG_PAGE, "naked",
+				MediaType.APPLICATION_XHTML_XML_TYPE, true);
+
+	}
+
+	protected void deactivate(ComponentContext context) {
+		fileServer = null;
+	}
+
+	/**
+	 * Returns a headed page listing RSS Feeds. The optional parameter query is a
+	 * search term, which tests if the term is contained in thee title or uri
+	 * of the feed.
+	 *
+	 * @param query an optional parameter which specifies a search term criteria.
+	 * The search term will be tested if contained in the title or the uri of the feed.
+	 *
+	 * @return {@link GraphNode}
+	 *
+	 */
+	@GET
+	public GraphNode getConfig() {
+		GraphNode node = new GraphNode(new BNode(), new SimpleMGraph());
+		node.addProperty(RDF.type, CONFIG_PAGE);
+		node.addProperty(RDF.type, PLATFORM.HeadedPage);
+		node.addProperty(PLATFORM.defaultBaseUri, platformConfig.getDefaultBaseUri());
+		return node;
+
+	}
+
+	@POST
+	public Response setConfig(@FormParam(value = "defaultBaseUri") String defaultBaseUri,
+			@Context UriInfo uriInfo) {
+		logger.debug("Setting base-uri to {}", defaultBaseUri);
+		if (defaultBaseUri.charAt(defaultBaseUri.length() - 1) != SLASH) {
+			defaultBaseUri += SLASH;
+		}
+		UriRef uri = new UriRef(defaultBaseUri);
+		GraphNode node = platformConfig.getPlatformInstance();
+		LockableMGraph sysGraph = (LockableMGraph) node.getGraph();
+		Lock writeLock = sysGraph.getLock().writeLock();
+		writeLock.lock();
+		try {
+			node.deleteProperties(PLATFORM.defaultBaseUri);
+			node.addProperty(PLATFORM.defaultBaseUri, uri);
+		} finally {
+			writeLock.unlock();
+		}
+		return Response.status(Response.Status.ACCEPTED).build();
+	}
+
+	@Override
+	public Set<GlobalMenuItem> getMenuItems() {
+		Set<GlobalMenuItem> items = new HashSet<GlobalMenuItem>();
+		try {
+			AccessController.checkPermission(
+					new TcPermission(SystemConfig.SYSTEM_GRAPH_URI.toString(),
+					TcPermission.READWRITE));
+		} catch (AccessControlException e) {
+			return items;
+		}
+		items.add(new GlobalMenuItem("/admin/configuration", "Configuration", "Configuration", 2,
+				"System Tools"));
+		return items;
+	}
+
+	/**
+	 * Returns a PathNode of a static file from the staticweb folder.
+	 *
+	 * @param path specifies the path parameter
+	 * @return {@link PathNode}
+	 */
+	@GET
+	@Path("{path:.+}")
+	public PathNode getStaticFile(
+			@PathParam("path") String path) {
+		return fileServer.getNode(path);
+
+
+	}
+}

Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/config.ssp
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/config.ssp?rev=931057&view=auto
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/config.ssp (added)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/config.ssp Tue Apr  6 09:08:57 2010
@@ -0,0 +1,28 @@
+def platform(s: Any) = new UriRef("http://clerezza.org/2009/08/platform#"+s)
+resultDocModifier.addStyleSheet("style/form.css");
+resultDocModifier.addScriptReference("/jquery/jquery-1.3.2.min.js");
+resultDocModifier.addScriptReference("/admin/configuration/js/platformconfig.js");
+resultDocModifier.addStyleSheet("/yui/2/container/assets/container-core.css");
+resultDocModifier.addScriptReference("/yui/2/yahoo-dom-event/yahoo-dom-event.js");
+resultDocModifier.addScriptReference("/yui/2/element/element-min.js");
+resultDocModifier.addScriptReference("/yui/2/container/container-min.js");
+resultDocModifier.addScriptReference("/scripts/alert-message.js");
+resultDocModifier.addScriptReference("/scripts/ajax-options.js");
+resultDocModifier.addScriptReference("/scripts/modification-status.js");
+resultDocModifier.addScripts("ModificationStatus.watchElements(\"input\");");
+
+resultDocModifier.setTitle("Apache Clerezza Configuration");
+resultDocModifier.addNodes2Elem("tx-module", <h1>Apache Clerezza Configuration</h1>);
+resultDocModifier.addNodes2Elem("tx-contextual-buttons-ol", <li><a class="tx-button tx-button-create " id="saveButton" href="#">Save</a></li>);
+<div id="tx-content">
+	<fieldset>
+		<legend></legend>
+		<ol>
+			<li class="tx-line">
+				<label for="defaultBaseUri">Default Base URI</label>
+				<input id="defaultBaseUri" name="defaultBaseUri" value={res/platform("defaultBaseUri")*}/>
+
+			</li>
+		</ol>
+	</fieldset>
+</div>

Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/staticweb/js/platformconfig.js
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/staticweb/js/platformconfig.js?rev=931057&view=auto
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/staticweb/js/platformconfig.js (added)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.config.gui/src/main/resources/org/apache/clerezza/platform/config/gui/staticweb/js/platformconfig.js Tue Apr  6 09:08:57 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+$(document).ready(function() {
+    $('#saveButton').click(function(){
+
+        if(isUrl($('#defaultBaseUri').val())){
+            var q = "Are you sure you want to change the URI to "+$('#defaultBaseUri').val();
+            AlertMessage.show(function(){
+
+                var data = "defaultBaseUri=" + encodeURIComponent($("#defaultBaseUri").val());
+                var options = new AjaxOptions("platform-config", "Save Config", function() {
+					ModificationStatus.isModified = false;
+				});
+                options.type = "POST";
+                options.url = "/admin/configuration/";
+                options.data = data;
+                $.ajax(options);
+            }, q , "Change Config?");
+            
+        }else {
+            AlertMessage.show(function(){}, " No valid URL ", "Error", "OK");
+        }
+
+
+
+
+    })
+})
+
+
+
+function isUrl(s) {
+    var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
+    return regexp.test(s);
+}
+