use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.
the class XWikiResource method initialize.
/**
* Resource initialization.
*/
@Override
public void initialize() throws InitializationException {
logger = java.util.logging.Logger.getLogger(this.getClass().getName());
objectFactory = new ObjectFactory();
this.slf4Jlogger.trace("Resource {} initialized. Serving user: '{}'\n", getClass().getName(), Utils.getXWikiUser(componentManager));
}
use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.
the class TextPlainPageReader 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();
String content = getEntityAsString(entityStream);
page.setContent(content);
return page;
}
use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.
the class FormUrlEncodedTagsReader method readFrom.
@Override
public Tags readFrom(Class<Tags> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
ObjectFactory objectFactory = new ObjectFactory();
Tags tags = objectFactory.createTags();
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());
String text = httpServletRequest.getParameter(TAGS_FIELD_NAME);
if (text != null) {
String[] tagNames = text.split(" |,|\\|");
for (String tagName : tagNames) {
Tag tag = objectFactory.createTag();
tag.setName(tagName);
tags.getTags().add(tag);
}
}
String[] tagNames = httpServletRequest.getParameterValues(TAG_FIELD_NAME);
if (tagNames != null) {
for (String tagName : tagNames) {
Tag tag = objectFactory.createTag();
tag.setName(tagName);
tags.getTags().add(tag);
}
}
} else {
String text = form.getFirstValue(TAGS_FIELD_NAME);
if (text != null) {
String[] tagNames = text.split(" |,|\\|");
for (String tagName : tagNames) {
Tag tag = objectFactory.createTag();
tag.setName(tagName);
tags.getTags().add(tag);
}
}
for (String tagName : form.getValuesArray(TAG_FIELD_NAME)) {
Tag tag = objectFactory.createTag();
tag.setName(tagName);
tags.getTags().add(tag);
}
}
return tags;
}
use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.
the class FormUrlEncodedObjectReader method readFrom.
@Override
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
ObjectFactory objectFactory = new ObjectFactory();
Object object = objectFactory.createObject();
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());
object.setClassName(httpServletRequest.getParameter(CLASSNAME_FIELD_NAME));
Enumeration<String> enumeration = httpServletRequest.getParameterNames();
while (enumeration.hasMoreElements()) {
String name = enumeration.nextElement();
if (name.startsWith(PROPERTY_PREFIX)) {
Property property = objectFactory.createProperty();
property.setName(name.replace(PROPERTY_PREFIX, ""));
property.setValue(httpServletRequest.getParameter(name));
object.getProperties().add(property);
}
}
} else {
object.setClassName(form.getFirstValue(CLASSNAME_FIELD_NAME));
for (String name : form.getNames()) {
if (name.startsWith(PROPERTY_PREFIX)) {
Property property = objectFactory.createProperty();
property.setName(name.replace(PROPERTY_PREFIX, ""));
property.setValue(form.getFirstValue(name));
object.getProperties().add(property);
}
}
}
return object;
}
use of org.xwiki.rest.model.jaxb.ObjectFactory in project xwiki-platform by xwiki.
the class TextPlainPropertyReader 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();
String value = getEntityAsString(entityStream);
property.setValue(value);
return property;
}
Aggregations