clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject svn commit: r898803 - in /incubator/clerezza/issues/CLEREZZA-72: ./ org.apache.clerezza.platform.language/ org.apache.clerezza.platform.language/src/main/java/org/apache/clerezza/platform/language/ org.apache.clerezza.platform.language/src/main/resourc...
Date Wed, 13 Jan 2010 15:42:22 GMT
Author: ito
Date: Wed Jan 13 15:42:21 2010
New Revision: 898803

URL: http://svn.apache.org/viewvc?rev=898803&view=rev
Log:
CLEREZZA-72: language widget implemented (renders a dropdown box containing available languages)

Added:
    incubator/clerezza/issues/CLEREZZA-72/
    incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/
      - copied from r898370, incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.language/
    incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/java/org/apache/clerezza/platform/language/LanguageWidget.java
    incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/language-list.ssp
    incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/staticweb/
    incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/staticweb/scripts/
    incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/staticweb/scripts/language-list.js
    incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.rdf.ontologies/
      - copied from r898791, incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.ontologies/
Modified:
    incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/pom.xml
    incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.rdf.ontologies/src/main/resources/org/apache/clerezza/rdf/ontologies/platform.rdf

Modified: incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/pom.xml?rev=898803&r1=898370&r2=898803&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/pom.xml (original)
+++ incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/pom.xml Wed
Jan 13 15:42:21 2010
@@ -36,11 +36,23 @@
 		</dependency>
 		<dependency>
 			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.platform.typerendering.core</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.platform.typerendering.scalaserverpages</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
 			<artifactId>org.apache.clerezza.platform.config</artifactId>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.felix</groupId>
 			<artifactId>org.apache.felix.scr.annotations</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.web.fileserver</artifactId>
+		</dependency>
 	</dependencies>
 </project>
\ No newline at end of file

Added: incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/java/org/apache/clerezza/platform/language/LanguageWidget.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/java/org/apache/clerezza/platform/language/LanguageWidget.java?rev=898803&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/java/org/apache/clerezza/platform/language/LanguageWidget.java
(added)
+++ incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/java/org/apache/clerezza/platform/language/LanguageWidget.java
Wed Jan 13 15:42:21 2010
@@ -0,0 +1,129 @@
+/*
+ * 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.language;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.MediaType;
+
+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.osgi.service.component.ComponentContext;
+import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
+import org.apache.clerezza.platform.typerendering.RenderletManager;
+import org.apache.clerezza.platform.typerendering.scalaserverpages.ScalaServerPagesRenderlet;
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.PLATFORM;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.utils.RdfList;
+import org.apache.clerezza.web.fileserver.BundlePathNode;
+import org.apache.clerezza.web.fileserver.FileServer;
+import org.apache.felix.scr.annotations.Services;
+import org.osgi.framework.Bundle;
+import org.wymiwyg.commons.util.dirbrowser.PathNode;
+
+/**
+ * Use the LanguageWidget service to store an RDF list of
+ * languages in a triple collection and retrieve the root node of the list. The widget
+ * can be rendered by using the render method. Via javascript function
+ * LanguageList.getLanguage() the currently selected language can be retrieved.
+ *
+ * @author tio
+ */
+@Component
+@Services({
+	@Service(Object.class),
+	@Service(LanguageWidget.class)
+})
+@Property(name = "javax.ws.rs", boolValue = true)
+
+@Path("/language-widget")
+public class LanguageWidget {
+
+	private FileServer fileServer;
+
+	@Reference
+	protected ContentGraphProvider cgProvider;
+	@Reference
+	private RenderletManager renderletManager;
+	@Reference
+	private LanguageService languageService;
+	
+	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());
+
+		fileServer = new FileServer(pathNode);
+
+		URL template = getClass().getResource("language-list.ssp");
+		renderletManager.registerRenderlet(ScalaServerPagesRenderlet.class.getName(),
+				new UriRef(template.toURI().toString()),
+				PLATFORM.LanguageList, "naked",
+				MediaType.APPLICATION_XHTML_XML_TYPE, true);
+
+	}
+
+	/**
+	 * Stores a list of available languages in a triple collection and returns the
+	 * root node of the list.
+	 *
+	 * @param graph specifies the graph to store the language list
+	 *
+	 * @return BNode
+	 *
+	 */
+	public BNode getLanguagesList(TripleCollection graph) {
+		BNode listNode = new BNode();
+		RdfList list = new RdfList(listNode, graph);
+		List<LanguageDescription> languages = languageService.getLanguages();
+		for (LanguageDescription languageDescription : languages) {
+			list.add(languageDescription.getResource().getNode());
+		}
+		graph.add(new TripleImpl(listNode, RDF.type, PLATFORM.LanguageList));
+		return listNode;
+	}
+
+	/**
+	 * Returns a PathNode of a static file from the staticweb folder.
+	 *
+	 * @param path specifies the path param of a URI
+	 *
+	 * @return {@link PathNode}
+	 */
+	@GET
+	@Path("{path:.+}")
+	public PathNode getStaticFile(@PathParam("path") String path) {
+		return fileServer.getNode(path);
+	}
+}

Added: incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/language-list.ssp
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/language-list.ssp?rev=898803&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/language-list.ssp
(added)
+++ incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/language-list.ssp
Wed Jan 13 15:42:21 2010
@@ -0,0 +1,29 @@
+import org.apache.clerezza.rdf.scala.utils.RichGraphNode
+def lingvoj(s: Any) = new UriRef("http://www.lingvoj.org/ontology#"+s)
+def rdfs(s: Any) = new UriRef("http://www.w3.org/2000/01/rdf-schema#"+s)
+def getLabel(language:Language, node:RichGraphNode) : String = {
+	val matchingLabels = for (label <- node/rdfs("label");
+		val labelLiteral = label.getNode.asInstanceOf[PlainLiteral];
+		if (labelLiteral.getLanguage.equals(language))
+	) yield {
+		label*
+	}
+	if (matchingLabels.length == 0) {
+		"no label"
+	} else {
+		matchingLabels.apply(0)
+	}
+}
+resultDocModifier.addScriptReference("/language-widget/scripts/language-list.js")
+val defaultLanguage:Language = new Language(res%!!(0)/lingvoj("iso1")*)
+
+<select name="availablelanguages" id="availablelanguages">
+	<option value={defaultLanguage.toString} selected="selected">{getLabel(defaultLanguage,
res%!!(0))}</option>
+	{
+		for(language <- res!!;
+			val iso1 = language/lingvoj("iso1")*;
+			if (!iso1.equals(defaultLanguage.toString))) yield {
+			<option value={iso1}>{getLabel(defaultLanguage,language)}</option>
+		}
+	}
+</select>
\ No newline at end of file

Added: incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/staticweb/scripts/language-list.js
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/staticweb/scripts/language-list.js?rev=898803&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/staticweb/scripts/language-list.js
(added)
+++ incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.platform.language/src/main/resources/org/apache/clerezza/platform/language/staticweb/scripts/language-list.js
Wed Jan 13 15:42:21 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+/**
+ * The LanguageList is a global object which provides a function to retrieve
+ * the language selected in the language list widget.
+ * 
+ */
+
+LanguageList = new Object();
+
+
+LanguageList.getLanguage = function() {
+	var language = "";
+	$('#availablelanguages option:selected').each(function() {
+			language =  $(this).val();
+	});
+	return language;
+}

Modified: incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.rdf.ontologies/src/main/resources/org/apache/clerezza/rdf/ontologies/platform.rdf
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.rdf.ontologies/src/main/resources/org/apache/clerezza/rdf/ontologies/platform.rdf?rev=898803&r1=898791&r2=898803&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.rdf.ontologies/src/main/resources/org/apache/clerezza/rdf/ontologies/platform.rdf
(original)
+++ incubator/clerezza/issues/CLEREZZA-72/org.apache.clerezza.rdf.ontologies/src/main/resources/org/apache/clerezza/rdf/ontologies/platform.rdf
Wed Jan 13 15:42:21 2010
@@ -33,8 +33,25 @@
 	<rdfs:isDefinedBy rdf:resource="http://clerezza.org/2009/08/platform#" />
 </rdfs:Class>
 
+<rdfs:Class rdf:about="http://clerezza.org/2009/08/platform#LanguageList">
+     <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
+     <rdfs:label xml:lang="en">Language List</rdfs:label>
+     <skos:definition xml:lang="en">A list containing Lingvoj language uris</skos:definition>
+     <rdfs:isDefinedBy rdf:resource="http://clerezza.org/2009/08/platform#"/>
+</rdfs:Class>
+
 <!-- Properties -->
 
+<rdf:Property rdf:about="http://clerezza.org/2009/08/platform#languages">
+	<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty" />
+	<rdfs:label xml:lang="en">languages</rdfs:label>
+	<skos:definition xml:lang="en">Points to a rdf list containing the languages
+		of the subject. The first langague in the list is the default language.
+		</skos:definition>
+	<rdfs:isDefinedBy rdf:resource="http://clerezza.org/2009/08/platform#" />
+	<rdfs:range rdf:resource="http://clerezza.org/2009/08/platform#LanguageList"/>
+</rdf:Property>
+
 <rdf:Property rdf:about="http://clerezza.org/2009/08/platform#defaultBaseUri">
 	<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty" />
 	<rdfs:label xml:lang="en">defaultBaseUri</rdfs:label>



Mime
View raw message