{
if(resourceType!=null&&!"".equals(resourceType))
{
if(resourceType.equals("webBookmark"))
{
WebBookmarkResource web = WebBookmarkResource.getWebBookmarkResource(item);
web.remove();
}
//TODO: other types ...
//TODO: use &&userOwnsRes
}
else
res.remove();
}
}
sendJSONResponse(response,OK);
}
else
sendJSONResponse(response,ERROR);
} catch (IOException e) {
e.printStackTrace();
}
}
else if(type.equals("removeAll"))
{
String item;
String parent;
item = request.getParameter("item");
parent = request.getParameter("parent");
XfoafSscfResource res = XfoafSscfResource.getXfoafSscfResource(item);
XfoafSscfResource parentRes = XfoafSscfResource.getXfoafSscfResource(parent);
String loggedPerson = null;
if(request.getUserPrincipal()!=null) {
try {
TomcatPerson person = ((FOAFPrincipal)request.getUserPrincipal()).getPerson();
loggedPerson = person.getURI().toString();
}
catch (Exception e){/*ignore viewerLogged will stay null*/}
}
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)