Author: bblfish
Date: Sun Mar 20 14:38:44 2011
New Revision: 1083451
URL: http://svn.apache.org/viewvc?rev=1083451&view=rev
Log:
refactored profile_panel to make structure easier to understand. Also changed
person_panel output so that one can only add agents whose URI has been
dereferenced (to avoid adding URIs as people that may not be agents, or whose
URIs are no longer valid).
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/person_panel.scala
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala?rev=1083451&r1=1083450&r2=1083451&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala
(original)
+++
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala
Sun Mar 20 14:38:44 2011
@@ -121,7 +121,7 @@ class ProfilePanel {
* @param webId
* @param profile
* @return A graph containing some information from the system graph,
the published profile cache if available, and
- * the local graph. Local changes can be written to a buffer
graph, that will have not be saved.
+ * the definedHere graph. Local changes can be written to a
buffer graph, that will have not be saved.
*/
private def getProfileInUserGraph(webId: UriRef, profile: UriRef):
GraphNode = {
var webIDInfo = webIdGraphsService.getWebIDInfo(webId)
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/person_panel.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/person_panel.scala?rev=1083451&r1=1083450&r2=1083451&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/person_panel.scala
(original)
+++
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/person_panel.scala
Sun Mar 20 14:38:44 2011
@@ -31,8 +31,11 @@ import org.apache.clerezza.rdf.ontologie
import org.apache.clerezza.rdf.web.proxy.WebProxy
import javax.ws.rs.core.MediaType
+/**
+ * static methods used by person panel and that could possibly be moved to a
library
+ */
object person_panel {
- final val emptyText = new Text("")
+ val emptyText = new Text("")
def ifE[T](arg:T)(template: T=>Node ):NodeSeq = {
def isEmpty(arg: Any): Boolean = {
@@ -75,7 +78,7 @@ object person_panel {
def encode(url: String): String = URLEncoder.encode(url,"UTF8")
/**
- * get a useable name from the properties available including nick
+ * get a usable name from the properties available including nick
*/
def getName(p: RichGraphNode): String = {
val name = p/FOAF.name*;
@@ -87,10 +90,150 @@ object person_panel {
}
+ def agentHtml(agent: RichGraphNode) = {<table>{
+ ifE({agent/FOAF.name}){ case
(f)=>(<tr><td>Name:</td><td>{f}</td></tr>)}++
+ ifE(agent/FOAF.logo*){f=>(<tr><td>Logo:</td><td><img
src={f} /></td></tr>)}
+ }</table> }
+
+
+ def linkNlabel(res: RichGraphNode): Node = {
+ var label: String = res/RDFS.label! match {
+ case uri: UriRef => uri.toString
+ case _ => res*
+ }
+ return <a href={res*}>{label}</a>
+ }
+
+
+}
+
+/**
+ * Metadata class for the person panel
+ */
+class person_panel extends SRenderlet {
+ def getRdfType() = CONTROLPANEL.ProfileViewerPage
+ import person_panel._
+
+
+ override def renderedPage(arguments: XmlResult.Arguments) = new
XmlPerson(arguments)
+}
+
+/**
+ * Content class for the Person Panel
+ */
+class XmlPerson(args: XmlResult.Arguments) extends XmlResult(args) {
+ import person_panel._
+
+ //
+ // Some initial constants
+ //
+
+ // either we use the rdf data on this as commented out here,
+ // val it: CollectedIter[RichGraphNode] = res /
FOAF.primaryTopic
+ // val primeTpc: RichGraphNode = it.apply(0)
+ // or we can get that information from URL, as shown here
+ lazy val webIdStr = uriInfo.getQueryParameters(true).getFirst("uri")
+ lazy val webIdUri= new UriRef(webIdStr)
+
+ lazy val webIdInfo = $[WebProxy].getResourceInfo(webIdUri)
+ lazy val agent : RichGraphNode= $[WebProxy].fetchSemantics(webIdUri)
match { case Some(grph) => grph; case None => res};
+
+ //
+ // the content itself.
+ // This is the piece that is closest to a pure ssp, though there is
still too much code in it
+ //
+
+ override def content = {
+ resultDocModifier.addStyleSheet("profile/style/profile.css");
+ resultDocModifier.setTitle("Profile Viewer");
+ resultDocModifier.addNodes2Elem("tx-module", <h1>Account
Control Panel</h1>);
+ resultDocModifier.addNodes2Elem("tx-module-tabs-ol", <li
class="tx-active"><a href="#">Profile Viewer</a></li>);
+ resultDocModifier.addNodes2Elem("tx-module-tabs-ol", <li><a
href="control-panel">Settings</a></li>);
+ resultDocModifier.addNodes2Elem("tx-module-tabs-ol", <li><a
href="profile">Profile</a></li>);
+
+
+ <div id="tx-content">
+ <h2>Profile Viewer</h2>
+ <form action="profile/addContact" method="POST">
+ <table>
+ {val typ: Resource = (agent / RDF.`type`).!
+ typ match {
+ case FOAF.Person => personHtml(agent)
+ case FOAF.Group => groupHtml(agent)
+ case FOAF.Agent => agentHtml(agent)
+ case _ => allAgentsHtml(agent.getGraph)
+ }}
+ </table>
+ <input type="submit" value="add contacts"/>
+ </form>
+ <code>
+ <pre>{val s =
org.apache.clerezza.rdf.core.serializedform.Serializer.getInstance();
+ import java.io._
+ val bout = new ByteArrayOutputStream()
+ s.serialize(bout, agent.getGraph(), "text/rdf+n3");
+ bout.toString("UTF-8")
+ }</pre>
+ </code>
+ </div>
+ }
+
+ //
+ // Methods called by the content
+ //
+
+
+ def relations() = {
+ <table>{for (friend <- agent/FOAF.knows) {
+ <tr><td>{friend*}</td></tr>
+ }
+ <tr><td><form id="addContact" method="post"
action="profile/people">
+ <input type="text" name="webId" size="80"/>
+ <input type="submit" value="add contact" />
+ </form></td></tr>
+ }</table>
+ }
+
+
+ def allAgentsHtml(tc: TripleCollection): Node = {<span>
+ <th><tr colspan="2">All agents found</tr></th>
+ { import collection.JavaConversions._
+ //todo: change
+ val base = new
URL(agent.getNode.asInstanceOf[UriRef].getUnicodeString());
+ val lclPrson = for (tr: Triple <- tc.filter(null, RDF.`type`,
FOAF.Person);
+ subjUrl = try { new
URL(tr.getSubject.asInstanceOf[UriRef].getUnicodeString) } catch { case _ =>
null }
+ if (subjUrl != null && base.sameFile(subjUrl))
+ ) yield tr.getSubject
+ for (p <- lclPrson) yield
+ <tbody>{personHtml(new GraphNode(p,tc))}</tbody>
+ }
+ </span>}
+
+ /**
+ * Is the uri defined here on the page from which the WebID comes?
+ * The point of this function is not to give the user a choice of
adding a person to his list
+ * of friends, until that page has been at least once properly
de-referenced. (People can link
+ * to non existent foaf files, things that are not persons, etc...)
+ *
+ * For pages with multiple #uris
+ * This will always return false for URIs that are redirected (as the
foaf vocab is)
+ *
+ * If that is the reasoning then should we also extend this method to
return true for pages already
+ * in the cache?
+ *
+ */
+ def definedHere(uri: UriRef):Boolean =
uri.getUnicodeString.startsWith(webIdInfo.representationUri)
+
+
def personHtml(p: RichGraphNode): NodeSeq = {
+ //note: img is a sub-relation of depiction, so an inference
engine would add both, and one would end up with repetition
+ //todo: only first image is shown
{<tr><td colspan="2">Person</td></tr>}++
- ifE(p!){case f:UriRef=>(<tr><td><input type="checkbox"
name="webId" value={p*}/>Add as contact</td><td><a
href={p*}>{p*}</a></td></tr>);
- case _ => emptyText;}++
+ ifE(p!){ case u:UriRef=> if (definedHere(u))
+ <tr><td><input type="checkbox" name="webId"
value={p*}/>Add as contact</td><td><a href={p*}>{p*}</a></td></tr>
+ else
+ <tr><td><a href=""/>Explore</td><td><a
href={"people?uri="+encode(u.getUnicodeString)}>{p*}</a></td></tr>
+ case _ => emptyText;
+ }++
ifE(p/FOAF.name){f=>(<tr><td>Name:</td><td>{f*}</td></tr>)}++
ifE(p/FOAF.firstName){f=>(<tr><td>First
Name:</td><td>{f}</td></tr>)} ++
ifE(firstOf(p,FOAF.family_name,FOAF.familyName)){f=>(<tr><td>Family
Name:</td><td>{f*}</td></tr>)} ++
@@ -98,8 +241,9 @@ object person_panel {
ifE(p/FOAF.homepage){f =>(<tr><td>Homepage:</td><td><ul>{for
(x<-f)yield <li><a href={x*}>{x*}</a></li>}</ul></td></tr>)}++
ifE(p/FOAF.currentProject){f =>(<tr><td>Current
Project(s):</td><td><ul>{for (x<-f) yield
<li>{linkNlabel(x)}</li>}</ul></td></tr>)}++
ifE(p/FOAF.depiction){f=>(<tr><td>Depictions:</td><td><img
src={f*} /></td></tr>)}++
+ ifE(p/FOAF.img){f=>(<tr><td>Depictions:</td><td><img src={f*}
/></td></tr>)}++
ifE(p/FOAF.logo){f=>(<tr><td>Logo:</td><td><img src={f*}
/></td></tr>)}++
- ifE(p/FOAF.knows){k=>(<tr><td>claims to
know</td><td><table>{for (fr<-k) yield displayAgent(fr)}</table></td></tr>)}
+ ifE(p/FOAF.knows){k=>(<tr><td>claims to
know</td><td><table>{for (fr<-k) yield displayAgent(fr)}</table></td></tr>)}
}
@@ -119,102 +263,6 @@ object person_panel {
}
}
- def linkNlabel(res: RichGraphNode): Node = {
- var label: String = res/RDFS.label! match {
- case uri: UriRef => uri.toString
- case _ => res*
- }
- return <a href={res*}>{label}</a>
- }
-
- def agentHtml(agent: RichGraphNode) = {<table>{
- ifE({agent/FOAF.name}){ case
(f)=>(<tr><td>Name:</td><td>{f}</td></tr>)}++
- ifE(agent/FOAF.logo*){f=>(<tr><td>Logo:</td><td><img
src={f} /></td></tr>)}
- }</table> }
-
-}
-
-class person_panel extends SRenderlet {
- def getRdfType() = CONTROLPANEL.ProfileViewerPage
- import person_panel._
-
-
- override def renderedPage(arguments: XmlResult.Arguments) = {
- new XmlResult(arguments) {
-
- override def content = {
- def cp(s: Any) = new
UriRef("http://clerezza.org/2009/03/controlpanel#" + s)
- def platform(s: Any) = new
UriRef("http://clerezza.org/2009/08/platform#" + s)
- resultDocModifier.addStyleSheet("profile/style/profile.css");
- resultDocModifier.setTitle("Profile Viewer");
- resultDocModifier.addNodes2Elem("tx-module", <h1>Account
Control Panel</h1>);
- resultDocModifier.addNodes2Elem("tx-module-tabs-ol", <li
class="tx-active"><a href="#">Profile Viewer</a></li>);
- resultDocModifier.addNodes2Elem("tx-module-tabs-ol", <li><a
href="control-panel">Settings</a></li>);
- resultDocModifier.addNodes2Elem("tx-module-tabs-ol", <li><a
href="profile">Profile</a></li>);
-
- val webIdUri= new
UriRef(uriInfo.getQueryParameters(true).getFirst("uri"))
-// val it: CollectedIter[RichGraphNode] = res / FOAF.primaryTopic
-// val primeTpc: RichGraphNode = it.apply(0)
- val agent : RichGraphNode=
$[WebProxy].fetchSemantics(webIdUri) match { case Some(grph) => grph; case None
=> res};
-
-// primeTpc! match {
-// case uri : UriRef => $[WebProxy].fetchSemantics(uri)
match { case Some(grph) => grph; case None => res};
-// case _ => res
-// }
-
- def relations() = {
- <table>{for (friend <- agent/FOAF.knows) {
- <tr><td>{friend*}</td></tr>
- }
- <tr><td><form id="addContact" method="post"
action="profile/people">
- <input type="text" name="webId" size="80"/>
- <input type="submit" value="add contact" />
- </form></td></tr>
- }</table>
- }
-
- def allAgentsHtml(tc: TripleCollection): Node = {<span>
- <th><tr colspan="2">All agents found</tr></th>
- { import collection.JavaConversions._
- //todo: change
- val base = new
URL(agent.getNode.asInstanceOf[UriRef].getUnicodeString());
- val lclPrson = for (tr: Triple <- tc.filter(null,
RDF.`type`, FOAF.Person);
- subjUrl = try { new
URL(tr.getSubject.asInstanceOf[UriRef].getUnicodeString) } catch { case _ =>
null }
- if (subjUrl != null &&
base.sameFile(subjUrl))
- ) yield tr.getSubject
- for (p <- lclPrson) yield
- <tbody>{personHtml(new
GraphNode(p,tc))}</tbody>
- }
- </span>}
-
- <div id="tx-content">
- <h2>Profile Viewer</h2>
- <form action="profile/addContact" method="POST">
- <table>
- { val typ: Resource = (agent/RDF.`type`).!
- typ match {
- case FOAF.Person => personHtml(agent)
- case FOAF.Group => groupHtml(agent)
- case FOAF.Agent => agentHtml(agent)
- case _ => allAgentsHtml(agent.getGraph)
- }
- }
- </table>
- <input type="submit" value="add contacts"/>
- </form>
- <code><pre>{
- val s
=org.apache.clerezza.rdf.core.serializedform.Serializer.getInstance();
- import java.io._
- val bout = new ByteArrayOutputStream()
- s.serialize(bout,agent.getGraph(),"text/rdf+n3");
- bout.toString("UTF-8")
- }</pre></code>
- </div>
- }
-
- }
- }
}
-