getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("XML error while parsing document: "+ex.getMessage());
}
}
User user = (User)getRequest().getAttributes().get(App.USER_ATTR);
try {
Entry entry = app.createEntry(user,feed,doc);
getResponse().setStatus(Status.SUCCESS_CREATED);
Form headers = new Form();
getResponse().getAttributes().put("org.restlet.http.headers",headers);
Reference ref = new Reference(myself+"_/"+entry.getUUID().toString());
getResponse().setLocationRef(ref);
Representation rep = new InfosetRepresentation(MediaType.APPLICATION_ATOM,doc);
rep.setCharacterSet(CharacterSet.UTF_8);
rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
MediaType entryType = new MediaType(rep.getMediaType().getName(),rep.getMediaType().getParameters().createSeries(EntryResource.entryParameters));
rep.setMediaType(entryType);
return rep;
} catch (AppException ex) {
getContext().getLogger().log(Level.SEVERE,ex.getMessage(),ex.getCause());
getResponse().setStatus(ex.getStatus());
return new StringRepresentation(ex.getMessage());
}
} else {
// Get the slug for the resource & entry
Form headers = (Form)getRequest().getAttributes().get("org.restlet.http.headers");
String slug = headers.getValues("slug");
if (slug==null) {
slug = headers.getValues("Slug");
}
if (slug!=null) {
try {
// Decode the precent encoding of the UTF-8 values
slug = URLDecoder.decode(slug,"UTF-8");
// Encode the slug as a URL encoding
slug = URLEncoder.encode(slug,"UTF-8");
} catch (UnsupportedEncodingException ex) {
getLogger().log(Level.SEVERE,"Cannot decode slug value: "+slug,ex);
}
getContext().getLogger().info("Slug="+slug);
}
String idS = headers.getValues("id");
UUID id = null;
if (idS!=null) {
try {
id = UUID.fromString(idS);
} catch (Exception ex) {
}
} else {
id = UUID.randomUUID();
}
try {
// Get author name for identity
User user = (User)getRequest().getAttributes().get(App.USER_ATTR);
Entry entry = app.createMediaEntry(user,feed,entity,slug,id);
getResponse().setStatus(Status.SUCCESS_CREATED);
headers = new Form();
getResponse().getAttributes().put("org.restlet.http.headers",headers);