You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2007/09/21 19:36:18 UTC

svn commit: r578208 - in /lenya/sandbox/modules/person: config/ config/cocoon-xconf/ java/ java/src/ java/src/org/ java/src/org/apache/ java/src/org/apache/lenya/ java/src/org/apache/lenya/modules/ java/src/org/apache/lenya/modules/person/ java/src/org...

Author: andreas
Date: Fri Sep 21 10:36:17 2007
New Revision: 578208

URL: http://svn.apache.org/viewvc?rev=578208&view=rev
Log:
Add addKnownPerson usecase

Added:
    lenya/sandbox/modules/person/config/cocoon-xconf/usecase-addKnownPerson.xconf
    lenya/sandbox/modules/person/java/
    lenya/sandbox/modules/person/java/src/
    lenya/sandbox/modules/person/java/src/org/
    lenya/sandbox/modules/person/java/src/org/apache/
    lenya/sandbox/modules/person/java/src/org/apache/lenya/
    lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/
    lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/
    lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/Person.java
    lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/usecases/
    lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/usecases/AddKnownPerson.java
    lenya/sandbox/modules/person/usecases/
    lenya/sandbox/modules/person/usecases/addKnownPerson.jx
Modified:
    lenya/sandbox/modules/person/config/menu.xsp

Added: lenya/sandbox/modules/person/config/cocoon-xconf/usecase-addKnownPerson.xconf
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/person/config/cocoon-xconf/usecase-addKnownPerson.xconf?rev=578208&view=auto
==============================================================================
--- lenya/sandbox/modules/person/config/cocoon-xconf/usecase-addKnownPerson.xconf (added)
+++ lenya/sandbox/modules/person/config/cocoon-xconf/usecase-addKnownPerson.xconf Fri Sep 21 10:36:17 2007
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+<!--
+    This file defines the publication specific use-cases
+-->
+
+<xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'person.addKnownPerson']">
+
+    <component-instance name="person.addKnownPerson" logger="lenya.modules.person"
+        class="org.apache.lenya.modules.person.usecases.AddKnownPerson">
+      <view template="modules/person/usecases/addKnownPerson.jx"/>
+    </component-instance>
+    
+  </xconf>

Modified: lenya/sandbox/modules/person/config/menu.xsp
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/person/config/menu.xsp?rev=578208&r1=578207&r2=578208&view=diff
==============================================================================
--- lenya/sandbox/modules/person/config/menu.xsp (original)
+++ lenya/sandbox/modules/person/config/menu.xsp Fri Sep 21 10:36:17 2007
@@ -40,6 +40,11 @@
                           <i18n:text>With one Form</i18n:text>
                         </item>
                       </block>
+                      <block areas="authoring">
+                        <item uc:usecase="person.addKnownPerson" href="?">
+                          <i18n:text>Add Known Person</i18n:text>
+                        </item>
+                      </block>
                   }
               }
           }

Added: lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/Person.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/Person.java?rev=578208&view=auto
==============================================================================
--- lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/Person.java (added)
+++ lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/Person.java Fri Sep 21 10:36:17 2007
@@ -0,0 +1,186 @@
+/*
+ * 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.lenya.modules.person;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.lenya.cms.publication.Area;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.w3c.dom.Element;
+
+/**
+ * Wrapper for person documents.
+ */
+public class Person extends AbstractLogEnabled {
+
+    protected static final String FOAF_NAMESPACE = "http://xmlns.com/foaf/0.1/";
+    protected static final String FOAF_PREFIX = "foaf";
+    protected static final String RDF_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+    protected static final String RDF_PREFIX = "rdf";
+
+    private Document document;
+    private Map knownPersons;
+
+    private String title;
+    private String givenName;
+    private String familyName;
+    private String mbox;
+    private String phone;
+    private String workplaceHomepage;
+
+    /**
+     * @param doc The document which stores the person information.
+     */
+    public Person(Document doc) {
+        this.document = doc;
+    }
+
+    /**
+     * @return The people which this person knows.
+     */
+    public Person[] getKnownPeople() {
+        load();
+        Collection persons = this.knownPersons.values();
+        return (Person[]) persons.toArray(new Person[persons.size()]);
+    }
+
+    /**
+     * @param person The person to add to the known people.
+     */
+    public void addKnownPerson(Person person) {
+        load();
+        this.knownPersons.put(person.getDocument().getUUID(), person);
+        save();
+    }
+    
+    /**
+     * @return The full name of this person.
+     */
+    public String getName() {
+        load();
+        return this.givenName + " " + this.familyName;
+    }
+
+    /**
+     * @return The Lenya document which stores the person data.
+     */
+    public Document getDocument() {
+        return this.document;
+    }
+
+    protected void load() {
+
+        if (this.knownPersons != null) {
+            return;
+        }
+
+        try {
+            org.w3c.dom.Document xml = DocumentHelper.readDocument(getDocument().getInputStream());
+            NamespaceHelper helper = new NamespaceHelper(FOAF_NAMESPACE, FOAF_PREFIX, xml);
+
+            Element rdf = xml.getDocumentElement();
+            Element person = helper.getFirstChild(rdf, "Person");
+
+            Element title = helper.getFirstChild(person, "title");
+            this.title = DocumentHelper.getSimpleElementText(title);
+
+            Element givenName = helper.getFirstChild(person, "givenname");
+            this.givenName = DocumentHelper.getSimpleElementText(givenName);
+
+            Element familyName = helper.getFirstChild(person, "family_name");
+            this.familyName = DocumentHelper.getSimpleElementText(familyName);
+
+            Element mbox = helper.getFirstChild(person, "mbox");
+            this.mbox = mbox.getAttributeNS(RDF_NAMESPACE, "resource");
+
+            Element phone = helper.getFirstChild(person, "phone");
+            this.phone = phone.getAttributeNS(RDF_NAMESPACE, "resource");
+
+            Element homepage = helper.getFirstChild(person, "workplaceHomepage");
+            this.workplaceHomepage = homepage.getAttributeNS(RDF_NAMESPACE, "resource");
+
+            Element[] knows = helper.getChildren(person, "knows");
+            String language = getDocument().getLanguage();
+            Area area = getDocument().area();
+            this.knownPersons = new HashMap();
+            for (int i = 0; i < knows.length; i++) {
+                String uri = knows[i].getAttributeNS(RDF_NAMESPACE, "resource");
+                String uuid = uri.substring("lenya-document".length());
+                Document doc = area.getDocument(uuid, language);
+                Person knownPerson = new Person(doc);
+                this.knownPersons.put(uuid, knownPerson);
+            }
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected void save() {
+        load();
+        try {
+            NamespaceHelper rdfHelper = new NamespaceHelper(RDF_NAMESPACE, RDF_PREFIX, "RDF");
+            org.w3c.dom.Document xml = rdfHelper.getDocument();
+            NamespaceHelper helper = new NamespaceHelper(FOAF_NAMESPACE, FOAF_PREFIX, xml);
+
+            Element person = helper.createElement("Person");
+            xml.getDocumentElement().appendChild(person);
+
+            Element title = helper.createElement("title", this.title);
+            person.appendChild(title);
+
+            Element givenName = helper.createElement("givenname", this.givenName);
+            person.appendChild(givenName);
+
+            Element familyName = helper.createElement("family_name", this.familyName);
+            person.appendChild(familyName);
+
+            Element mbox = helper.createElement("mbox");
+            mbox.setAttributeNS(RDF_NAMESPACE, "rdf:resource", this.mbox);
+            person.appendChild(mbox);
+
+            Element phone = helper.createElement("phone");
+            phone.setAttributeNS(RDF_NAMESPACE, "rdf:resource", this.phone);
+            person.appendChild(phone);
+
+            Element homepage = helper.createElement("workplaceHomepage");
+            homepage.setAttributeNS(RDF_NAMESPACE, "rdf:resource", this.workplaceHomepage);
+            person.appendChild(homepage);
+
+            Collection uuids = this.knownPersons.keySet();
+            for (Iterator i = uuids.iterator(); i.hasNext();) {
+                String uuid = (String) i.next();
+                Element knows = helper.createElement("knows");
+                knows.setAttributeNS(RDF_NAMESPACE, "rdf:resource", "lenya-document:" + uuid);
+                person.appendChild(knows);
+            }
+
+            DocumentHelper.writeDocument(xml, getDocument().getOutputStream());
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}

Added: lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/usecases/AddKnownPerson.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/usecases/AddKnownPerson.java?rev=578208&view=auto
==============================================================================
--- lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/usecases/AddKnownPerson.java (added)
+++ lenya/sandbox/modules/person/java/src/org/apache/lenya/modules/person/usecases/AddKnownPerson.java Fri Sep 21 10:36:17 2007
@@ -0,0 +1,65 @@
+/*
+ * 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.lenya.modules.person.usecases;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.modules.person.Person;
+
+/**
+ * Adds a "knows" relation to a person document.
+ */
+public class AddKnownPerson extends DocumentUsecase {
+
+    protected void initParameters() {
+        super.initParameters();
+
+        Document doc = getSourceDocument();
+        Document[] allDocs = doc.area().getDocuments();
+
+        try {
+            Set peopleDocs = new HashSet();
+            for (int i = 0; i < allDocs.length; i++) {
+                if (allDocs[i].getResourceType().getName().equals("person")) {
+                    Person person = new Person(allDocs[i]);
+                    peopleDocs.add(person);
+                }
+            }
+            setParameter("people", peopleDocs);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected void doExecute() throws Exception {
+        super.doExecute();
+
+        String uuid = getParameterAsString("uuid");
+        Document doc = getSourceDocument();
+        Person person = new Person(doc);
+
+        Document knownDoc = doc.area().getDocument(uuid, doc.getLanguage());
+        Person knownPerson = new Person(knownDoc);
+
+        person.addKnownPerson(knownPerson);
+    }
+
+}

Added: lenya/sandbox/modules/person/usecases/addKnownPerson.jx
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/person/usecases/addKnownPerson.jx?rev=578208&view=auto
==============================================================================
--- lenya/sandbox/modules/person/usecases/addKnownPerson.jx (added)
+++ lenya/sandbox/modules/person/usecases/addKnownPerson.jx Fri Sep 21 10:36:17 2007
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<!-- $Id: login.jx 529195 2007-04-16 10:45:27Z andreas $ -->
+
+<page:page xmlns:jx="http://apache.org/cocoon/templates/jx/1.0" 
+           xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" 
+           xmlns="http://www.w3.org/1999/xhtml" 
+           xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
+
+  <page:title>
+    <i18n:text>Add Known Person</i18n:text>
+  </page:title>
+  <page:body>
+    
+    <jx:import uri="fallback://lenya/modules/usecase/templates/messages.jx"/>
+    
+    <form method="POST">
+    
+      <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+      <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
+      <p>
+        <i18n:text>Select a person you know:</i18n:text>
+      </p>
+      <p>
+        <select name="uuid">
+          <jx:forEach var="person" items="${usecase.getParameter('people')}">
+            <option value="${person.getDocument().getUUID()}">
+              <jx:out value="${person.getName()}"/>
+            </option>
+          </jx:forEach>
+        </select>
+      </p>
+  
+      <p>
+        <input i18n:attr="value" name="submit" type="submit" value="Submit"/>
+        <i18n:text> </i18n:text>
+        <input i18n:attr="value" name="cancel" type="submit" value="Cancel"/>
+      </p>
+      
+    </form>
+  </page:body>
+</page:page>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org