String parentIssuer = null;
//we want to delete all the resources of somebody and we know his mbox
if(parent.startsWith("mailto:")) {
Person person = PersonFactory.findPerson(parent);
if(person!=null) parentIssuer = person.getURI().toString();
}
else if(parentRes.getIssuedBy()!=null) {
parentIssuer = parentRes.getIssuedBy().getStringURI();
}
String resIssuer = res.getIssuedBy()!=null?res.getIssuedBy().getStringURI():loggedPerson;
if(loggedPerson!=null&&loggedPerson.equals(parentIssuer)&&
resIssuer.equals(parentIssuer))
{
try {
if(parentRes!= null)
{
ResourceRemover rm = new ResourceRemover();
rm.removeAll(res, parentRes);
sendJSONResponse(response,OK);
}
else
sendJSONResponse(response,ERROR);
} catch (IOException e) {
e.printStackTrace();
}
}
}
else if(type.equals("addBookmark"))
{
String result = insertResource(request);
try {
if(result!=null)
sendJSONResponse(response,result);
else sendJSONResponse(response,ERROR);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if(type.equals("directoryDescription"))
{
String uri = request.getParameter("uri");
String sioc = request.getParameter("sioc");
String webBookmark = request.getParameter("webBookmark");
if(uri!=null&&!"".equals(uri))
{
String result;
if(sioc!=null)
result = SscfHelper2.getInstance().getSiocResourceDescription(uri, sioc);
else if(webBookmark!=null) {
result = SscfHelper2.getInstance().getWebBookmarkDescription(uri);
}
else result = SscfHelper2.getInstance().getDirectoryDescription(uri);
try {
if(result!=null)
{
//System.out.println(result);
sendJSONResponse(response,result);
}
else sendJSONResponse(response,ERROR);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else if(type.equals("importNode"))
{
String result = importSuggestedResource(request);
try {
if(result!=null)
sendJSONResponse(response,result);
else sendJSONResponse(response,ERROR);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if(type.equals("directoryPolicy"))
{
String uri = request.getParameter("uri");
//add new policy if parameter set.
String policy = request.getParameter("policy");
String remove = request.getParameter("remove");
if(policy!=null&&!"".equals(policy))
{
XfoafSscfResource resource = XfoafSscfResource.getXfoafSscfResource(uri);
if(resource!=null)
{
if(remove!=null&&!"".equals(remove)&&"1".equals(remove))
{
resource.deleteAccessibleTo(policy);
}
else
resource.addAccessibleTo(policy);
}
}
if(uri!=null&&!"".equals(uri))
{
String result = SscfHelper2.getInstance().getDirectoryPolicies(uri);
try {
if(result!=null)
sendJSONResponse(response,result);
else sendJSONResponse(response,ERROR);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else if(type.equals("generateWordnet"))
{
String name = request.getParameter("name");
String desc = request.getParameter("desc");
String thesUri = request.getParameter("thesUri");
if(name!=null&&!"".equals(name.trim()) )
{
String result = SscfHelper2.getInstance().getWordNetValues(name,desc,thesUri);
try {
if(result!=null)
sendJSONResponse(response,result);
else sendJSONResponse(response,EMPTY);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else if(type.equals("createDirectory"))
{
String bookmarks = createDirectory(request);
try {
if(bookmarks == null||"".equals(bookmarks.trim()))
sendJSONResponse(response,EMPTY);
else
sendJSONResponse(response,bookmarks);
} catch (IOException e) {
e.printStackTrace();
}
}
else if(type.equals("sendClick"))
{
String uri = request.getParameter("item");
String resType = request.getParameter("resourceType");
try {
if(uri == null||"".equals(uri.trim()))
response.getWriter().write(EMPTY);
else
{
System.out.println("I received a click to: "+uri);
if(resType!=null&&!"".equals(resType)&&resType.equals("web"))
{
WebBookmarkResource wbr = WebBookmarkResource.getWebBookmarkResource(uri);
if(wbr != null)
wbr.increaseResourceHits();
}
else
{
XfoafSscfResource xfsr = XfoafSscfResource.getXfoafSscfResource(uri);
if(xfsr != null)
xfsr.increaseResourceHits();
}
sendJSONResponse(response,OK);
}
} catch (IOException e) {
e.printStackTrace();
}
}
else if(type.equals("importBookmarks"))
{
String username = request.getParameter("username");
String password = request.getParameter("password");
String importType = request.getParameter("importType");
String viewer = request.getParameter("viewer");
String check = request.getParameter("check");
String[] result = null;
StringBuilder responseResult = new StringBuilder();
if(username.contains("@yahoo.com")){ //fix username for flickr account
username = username.substring(0,username.indexOf("@yahoo.com"));
}
if(username!=null&&password!=null&&importType!=null&&viewer!=null&&
!"".equals(username)&&!"".equals(password)&&!"".equals(importType)&&!"".equals(viewer)) {
result = importBookmarks(importType, username, password,check,viewer,getServiceAddr(request));
}
try {
if(username != null && !"".equals(username)){
request.getSession().setAttribute("username", username);
}else if ( username == null && request.getSession().getAttribute("username") != null){
username = (String)request.getSession().getAttribute("username");
}
if(result!=null&&result[0]!=null&&!result[0].equals(TaskStatusInfo.ERROR.getMessage())
&&!result[0].equals(TaskStatusInfo.DONE.getMessage())
&&!result[0].equals(TaskStatusInfo.REMOTEERROR.getMessage())
&&!result[0].equals(TaskStatusInfo.REDIRECTING.getMessage()))
{
responseResult.append("{stat:\"").append(result[0]).append("\"");
if(result[1]!=null)
responseResult.append(",message:\"").append(result[1]).append("\"");
else responseResult.append(",message:\"\"");
sendJSONResponse(response, responseResult.append("}").toString());
}
else if(result!=null&&result[0].equals(TaskStatusInfo.DONE.getMessage()))
{
responseResult.append("{stat:\"").append(result[0]).append("\"");
Person view = PersonFactory.findPerson(viewer);
if(view!=null)
{
String dir = getBookmarks(result[1], view.getURI().toString(), request.getSession(), 1,true, true, getServiceAddr(request),null);
responseResult.append(",message:").append(dir);
}
else responseResult.append(",message:\"\"");
sendJSONResponse(response, responseResult.append("}").toString());