Updated Demo Servlet

Conflicts:
	htroot/About.html
	htroot/DemoServlet.html
	htroot/DemoServlet.java
	htroot/interaction/interaction.js
	source/net/yacy/interaction/Interaction.java
pull/1/head
cominch 13 years ago committed by Michael Peter Christen
parent 90512640bf
commit 300b235ce8

@ -0,0 +1,70 @@
<!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>
<script type="text/javascript" src="js/html.js"></script>
<script src="/yacy/ui/js/jquery-1.3.2.min.js" type="text/javascript"></script>
</head>
<body id="index">
<div>
Hello world!
</div>
<br/>
<br/>
<div>
Your user name: #[username]#
</div>
<div>
<p>A list of all users on this system:</p>
#{users}#
- #[user]#<br/>
#{/users}#
</div>
<br/>
<br/>
<br/>
<div>
Temperature: #[temperature]#
</div>
<form action="DemoServlet.html" method="post">
<input type="text" name="textthing" value=""/>
<input type="submit" name="submit" value="submit">
</form>
#{localimg}#
<img src="#[path]#">
#(checked)#no::yes::maybe#(/checked)#
#{/localimg}#
<br/>
<br/>
<br/>
<div>
<p>Upload a file (will be stored in HTDOCS/upload/username/):</p>
<form action="/interaction/UploadSingleFile.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
<input type="file" name="uploadfile">
<input type="submit">
</form>
</div>
</body>
</html>

@ -0,0 +1,68 @@
import java.util.Iterator;
import net.yacy.yacy;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.interaction.Interaction;
import net.yacy.search.Switchboard;
import de.anomic.data.BookmarkHelper;
import de.anomic.data.UserDB;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
public final class DemoServlet {
public static serverObjects respond(final RequestHeader header,
final serverObjects post, final serverSwitch env) {
// return variable that accumulates replacements
final serverObjects prop = new serverObjects();
final Switchboard sb = Switchboard.getSwitchboard();
prop.put("temperature", "-10°C");
// Display currently logged on user
prop.put("username", Interaction.GetLoggedOnUser(header));
//Generate Userlist
int numUsers = 0;
for (String user : Interaction.GetUsers()) {
prop.putHTML("users_"+numUsers+"_user", user);
numUsers++;
}
prop.put("users", numUsers);
if (post != null) {
if (post.containsKey("submit")) {
prop.put("temperature", post.get("textthing"));
String filename= post.get("textthing");
int counter = 0;
while (counter < 10) {
prop.put("localimg_"+counter+"_path","/"+filename);
prop.put("localimg_"+counter+"_checked", "2");
counter++;
}
prop.put("localimg", counter);
prop.put("temperature", yacy.homedir+"/DATA/HTDOCS/"+filename);
}
}
// return rewrite properties
return prop;
}
}

@ -0,0 +1,132 @@
package interaction;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import net.yacy.yacy;
import net.yacy.cora.document.UTF8;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.document.content.SurrogateReader;
import net.yacy.interaction.Interaction;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Digest;
import net.yacy.search.Switchboard;
import de.anomic.data.UserDB;
import de.anomic.data.UserDB.AccessRight;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
public class UploadSingleFile {
public static serverObjects respond(final RequestHeader header,
final serverObjects post, final serverSwitch env) {
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
if (post != null){
if (post.containsKey("uploadfile") && !post.get("uploadfile").isEmpty()) {
UserDB.Entry entry = sb.userDB.getEntry(Interaction.GetLoggedOnUser(header));
if (entry != null) {
if (entry.hasRight(UserDB.AccessRight.UPLOAD_RIGHT)) {
// the user has the upload right
}
}
String targetfilename = post.get("uploadfile", "target.file");
String targetfolder = "/upload/"+Interaction.GetLoggedOnUser(header);
if (post.containsKey("targetfilename")) {
targetfilename = post.get("targetfilename");
}
if (post.containsKey("targetfolder")) {
targetfolder = post.get("targetfolder");
if (!targetfolder.startsWith("/")) {
targetfolder = "/" + targetfolder;
}
}
File f = new File(yacy.dataHome_g, "DATA/HTDOCS"+targetfolder+"/");
yacy.mkdirsIfNeseccary (f);
f = new File(f, targetfilename);
Log.logInfo ("FILEUPLOAD", f.toString());
try {
ByteArrayInputStream stream = new ByteArrayInputStream(post
.get("uploadfile$file").getBytes());
if (stream != null) {
OutputStream out;
out = new FileOutputStream(f.toString());
byte[] buf = new byte[1024];
int len;
while ((len = stream.read(buf)) > 0) {
out.write(buf, 0, len);
}
stream.close();
out.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// return rewrite properties
return prop;
}
}

@ -1,3 +1,48 @@
function newload (name, div) {
$.get(name, function(data) {
$('#'+div).html(data);
});
}
function xmlToString (xmlData) {
var xmlString;
if (window.ActiveXObject) {
xmlString = xmlData.xml;
}
else {
xmlString = (new XMLSerializer()).serializeToString(xmlData);
}
return xmlString;
}
function rdfload (datastore) {
$.ajax({
type : "GET",
url: "/currentyacypeer/interaction/GetRDF.xml?global=true",
dataType: "xml",
success: function(xml) {
datastore.load(xml);
}
});
}
function feedback (url, comment, from) {
$.getJSON('/currentyacypeer/interaction/Feedback.json?url='+url+'&comment='+comment+'&from='+from, function(data) {

File diff suppressed because it is too large Load Diff

@ -2,30 +2,40 @@
package net.yacy.interaction;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.FileManager;
import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import net.yacy.kelondro.logging.Log;
import net.yacy.search.Switchboard;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
public class TripleStore {
public static Model model = ModelFactory.createDefaultModel();
public static ConcurrentHashMap<String, Model> privatestorage = null;
public static String file;
public static void Load (String filename) {
Model tmp = ModelFactory.createDefaultModel();
Log.logInfo("TRIPLESTORE", "Loading from " + filename);
try {
InputStream in = FileManager.get().open(filename);
// read the RDF/XML file
tmp.read(in, null);
}
@ -33,19 +43,20 @@ public class TripleStore {
{
model = model.union(tmp);
}
}
public static void Add (String rdffile) {
Model tmp = ModelFactory.createDefaultModel();
try {
@SuppressWarnings("deprecation")
InputStream in = new StringBufferInputStream(rdffile);
// read the RDF/XML file
tmp.read(in, null);
}
@ -53,26 +64,99 @@ public class TripleStore {
{
model = model.union(tmp);
}
}
public static void Save (String filename) {
FileOutputStream fout;
try {
fout = new FileOutputStream(filename);
model.write(fout);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.logWarning("TRIPLESTORE", "Saving to " + filename+" failed");
}
}
public static void initPrivateStores(Switchboard switchboard) {
Log.logInfo("TRIPLESTORE", "Init private stores");
if (privatestorage != null) privatestorage.clear();
try {
Iterator<de.anomic.data.UserDB.Entry> it = switchboard.userDB.iterator(true);
while (it.hasNext()) {
de.anomic.data.UserDB.Entry e = it.next();
String username = e.getUserName();
Log.logInfo("TRIPLESTORE", "Init " + username);
String filename = new File(switchboard.getConfig("dataRoot", ""), "DATA/TRIPLESTORE").toString()+"/"+username+"_triplestore.rdf";
Model tmp = ModelFactory.createDefaultModel();
Log.logInfo("TRIPLESTORE", "Loading from " + filename);
try {
InputStream in = FileManager.get().open(filename);
// read the RDF/XML file
tmp.read(in, null);
}
finally
{
privatestorage.put(username, tmp);
}
}
}
catch (Exception anyex) {
}
// create separate model
}
public static void savePrivateStores(Switchboard switchboard) {
if (privatestorage == null) return;
for (Entry<String, Model> s : privatestorage.entrySet()) {
String filename = new File(switchboard.getConfig("dataRoot", ""), "DATA/TRIPLESTORE").toString()+"/"+s.getKey()+"_triplestore.rdf";
FileOutputStream fout;
try {
fout = new FileOutputStream(filename);
s.getValue().write(fout);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.logWarning("TRIPLESTORE", "Saving to " + filename+" failed");
}
}
}
}

@ -138,6 +138,7 @@ public final class yacy {
*/
private static Switchboard sb = null;
public static String homedir;
public static File dataHome_g;
/**
* Starts up the whole application. Sets up all datastructures and starts
@ -163,6 +164,7 @@ public final class yacy {
// ensure that there is a DATA directory, if not, create one and if that fails warn and die
mkdirsIfNeseccary(dataHome);
dataHome_g = dataHome;
mkdirsIfNeseccary(appHome);
File f = new File(dataHome, "DATA/");
mkdirsIfNeseccary(f);
@ -462,7 +464,7 @@ public final class yacy {
* @see File#mkdirs()
* @param path
*/
private static void mkdirsIfNeseccary(final File path) {
public static void mkdirsIfNeseccary(final File path) {
if (!(path.exists()))
if(!path.mkdirs())
Log.logWarning("STARTUP", "could not create directories "+ path.toString());

Loading…
Cancel
Save