Conflicts: htroot/About.html htroot/DemoServlet.html htroot/DemoServlet.java htroot/interaction/interaction.js source/net/yacy/interaction/Interaction.javapull/1/head
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 @@
|
||||
thanks
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue