Add new demonstration module for client-side key-value store (backend:

triplestore): /DemoServletInteraction.html

Conflicts:
	source/net/yacy/interaction/Interaction.java
pull/1/head
cominch 13 years ago committed by Michael Peter Christen
parent c9dc6cda02
commit b0bc0b4572

@ -0,0 +1,58 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>YaCy '#[clientname]#': Demo-Servlet</title>
<!-- This element contains the jQuery libraries and interaction routines -->
#%env/templates/metas.template%#
</head>
<body id="index">
<p>
JavaScript example: Permanent storage of value
</p>
<br/>
<p>
<input id="SliderSingle" type="slider" name="price" value="0" />
<script type="text/javascript" charset="utf-8">
var oldvalue = loadvalue ('http://virtual.x/document/uniquenameDemo123', 'http://virtual.x/hasvalue');
if (oldvalue == "") {
oldvalue = "0";
}
document.getElementById('SliderSingle').value = oldvalue;
$("#SliderSingle").slider(
{
from: 0,
to: 100,
step: 2.5,
round: 1,
format: { format: '##.0', locale: 'de'},
dimension: '&nbsp; points',
skin: 'round',
onstatechange: function(value) {
storevalue ('http://virtual.x/document/uniquenameDemo123', 'http://virtual.x/hasvalue', value);
}
}
);
</script>
</p>
</body>
</html>

@ -0,0 +1,19 @@
import net.yacy.cora.protocol.RequestHeader;
import de.anomic.data.BookmarkHelper;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
public final class DemoServletInteraction {
public static serverObjects respond(final RequestHeader header,
final serverObjects post, final serverSwitch env) {
// return variable that accumulates replacements
final serverObjects prop = new serverObjects();
prop.put("temperature", "-10°C");
// return rewrite properties
return prop;
}
}

@ -73,17 +73,18 @@ public class Triple {
}
if (post.containsKey("url")) {
if (post.containsKey("load")) {
Interaction.Triple(url, s, p, o, from);
o = Interaction.TripleGet(s, p);
} else {
prop.putHTML("url", url);
Interaction.Triple(url, s, p, o, from);
}
prop.put("result", o);
return prop;
}

@ -1,4 +1,4 @@
{
"url": "#[url]#"
"comment": "#[comment]#"
"url": "#[url]#",
"result": "#[result]#"
}

@ -32,3 +32,29 @@ function triple (url, s, p, o, username) {
});
}
function storevalue (s, p, o) {
$.getJSON('/currentyacypeer/interaction/Triple.json?url='+document.location.href+'&s='+s+'&p='+p+'&o='+o, function(data) {
});
}
function loadvalue (s, p) {
var res = {result: "no result"};
$.ajaxSetup({async: false});
$.getJSON('/currentyacypeer/interaction/Triple.json?s='+s+'&p='+p+'&load=true', function (data) {
res = data;
});
return res.result;
}

@ -7,18 +7,17 @@ import java.util.Map;
import net.yacy.cora.document.UTF8;
import net.yacy.cora.protocol.http.HTTPClient;
import net.yacy.kelondro.blob.Tables;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.peers.Seed;
import net.yacy.search.Switchboard;
import java.util.UUID;
import org.apache.http.entity.mime.content.ContentBody;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.StmtIterator;
public class Interaction {
@ -459,11 +458,12 @@ public static String Triple(String url, String s, String p, String o, String fro
r.addProperty(pr, o);
Log.logInfo ("TRIPLESTORE", "PUT "+s+"-"+p+"-"+o);
return "";
}
public static String getTriple(String s, String p) {
public static String TripleGet(String s, String p) {
final Switchboard sb = Switchboard.getSwitchboard();
@ -472,7 +472,10 @@ public static String getTriple(String s, String p) {
StmtIterator iter = TripleStore.model.listStatements(r, pr, (Resource) null);
Log.logInfo ("TRIPLESTORE", "GET "+s+" - "+p);
while (iter.hasNext()) {
return (iter.nextStatement().getObject().toString());
}

Loading…
Cancel
Save