use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.
the class FormUrlEncodedPropertyReader method readFrom.
@Override
public Property readFrom(Class<Property> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
ObjectFactory objectFactory = new ObjectFactory();
Property property = objectFactory.createProperty();
Representation representation = new InputRepresentation(entityStream, org.restlet.data.MediaType.APPLICATION_WWW_FORM);
Form form = new Form(representation);
/*
* If the form is empty then it might have happened that some filter has invalidated the entity stream. Try to
* read data using getParameter()
*/
if (form.getNames().isEmpty()) {
HttpServletRequest httpServletRequest = ServletUtils.getRequest(Request.getCurrent());
Enumeration<String> names = httpServletRequest.getParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
if (name.startsWith(PROPERTY_PREFIX)) {
property.setName(name.replace(PROPERTY_PREFIX, ""));
property.setValue(httpServletRequest.getParameter(name));
break;
}
}
} else {
for (String name : form.getNames()) if (name.startsWith(PROPERTY_PREFIX)) {
property.setName(name.replace(PROPERTY_PREFIX, ""));
property.setValue(form.getFirstValue(name));
break;
}
}
return property;
}
use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.
the class FormUrlEncodedPageReader method readFrom.
@Override
public Page readFrom(Class<Page> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
ObjectFactory objectFactory = new ObjectFactory();
Page page = objectFactory.createPage();
Representation representation = new InputRepresentation(entityStream, org.restlet.data.MediaType.APPLICATION_WWW_FORM);
Form form = new Form(representation);
/*
* If the form is empty then it might have happened that some filter has invalidated the entity stream. Try to
* read data using getParameter()
*/
if (form.getNames().isEmpty()) {
HttpServletRequest httpServletRequest = ServletUtils.getRequest(Request.getCurrent());
page.setTitle(httpServletRequest.getParameter(TITLE_FIELD_NAME));
page.setParent(httpServletRequest.getParameter(PARENT_FIELD_NAME));
page.setHidden(Boolean.valueOf(httpServletRequest.getParameter(HIDDEN_FIELD_NAME)));
page.setContent(httpServletRequest.getParameter(CONTENT_FIELD_NAME));
} else {
page.setTitle(form.getFirstValue(TITLE_FIELD_NAME));
page.setParent(form.getFirstValue(PARENT_FIELD_NAME));
page.setHidden(Boolean.valueOf(form.getFirstValue(HIDDEN_FIELD_NAME)));
page.setContent(form.getFirstValue(CONTENT_FIELD_NAME));
}
return page;
}
Aggregations