use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class AbstractInstanceFilterStreamTest method importFromXML.
protected void importFromXML(String resource, InstanceOutputProperties instanceProperties) throws FilterException {
if (instanceProperties == null) {
instanceProperties = new InstanceOutputProperties();
instanceProperties.setVerbose(false);
}
OutputFilterStream outputFilterStream = this.outputFilterStreamFactory.createOutputFilterStream(instanceProperties);
URL url = getClass().getResource("/filter/" + resource + ".xml");
FilterXMLInputProperties properties = new FilterXMLInputProperties();
properties.setSource(new DefaultURLInputSource(url));
InputFilterStream inputFilterStream = this.xmlInputFilterStreamFactory.createInputFilterStream(properties);
inputFilterStream.read(outputFilterStream.getFilter());
try {
inputFilterStream.close();
} catch (IOException e) {
throw new FilterException("Failed to close input wiki stream", e);
}
try {
outputFilterStream.close();
} catch (IOException e) {
throw new FilterException("Failed to close output wiki stream", e);
}
}
use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class PropertyClassOutputFilterStream method onWikiClassPropertyField.
@Override
public void onWikiClassPropertyField(String name, String value, FilterEventParameters parameters) throws FilterException {
if (this.entity != null) {
PropertyClass propertyClass;
try {
propertyClass = (PropertyClass) this.currentClassPropertyMeta.get(name);
} catch (XWikiException e) {
throw new FilterException(String.format("Failed to get definition of field [%s] for property type [%s]", name, this.entity.getClassType()), e);
}
// Make sure the property is known
if (propertyClass == null) {
this.logger.warn("Unknown property meta class field [{}] for property type [{}]", name, this.entity.getClassType());
return;
}
BaseProperty<?> field = propertyClass.fromString(value);
this.entity.safeput(name, field);
}
}
use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class PropertyClassOutputFilterStream method beginWikiClassProperty.
// Events
@Override
public void beginWikiClassProperty(String name, String type, FilterEventParameters parameters) throws FilterException {
if (this.enabled) {
ComponentManager componentManager = this.componentManagerProvider.get();
this.currentClassPropertyMeta = null;
PropertyClassProvider provider;
// First try to use the specified class type as hint.
try {
if (componentManager.hasComponent(PropertyClassProvider.class, type)) {
provider = componentManager.getInstance(PropertyClassProvider.class, type);
} else {
// In previous versions the class type was the full Java class name of the property class
// implementation. Extract the hint by removing the Java package prefix and the Class suffix.
String classType = StringUtils.removeEnd(StringUtils.substringAfterLast(type, "."), "Class");
if (componentManager.hasComponent(PropertyClassProvider.class, classType)) {
provider = componentManager.getInstance(PropertyClassProvider.class, classType);
} else {
this.logger.warn("Unknown property type [{}]", type);
return;
}
}
} catch (ComponentLookupException e) {
throw new FilterException(String.format("Failed to get instance of the property class provider for type [%s]", type), e);
}
this.currentClassPropertyMeta = provider.getDefinition();
if (this.entity == null) {
// We should use PropertyClassInterface (instead of PropertyClass, its default implementation) but it
// doesn't have the set methods and adding them would breaks the backwards compatibility. We make the
// assumption that all property classes extend PropertyClass.
this.entity = (PropertyClass) provider.getInstance();
}
this.entity.setName(name);
this.entity.setObject(this.currentXClass);
}
}
use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class UserInstanceOutputFilterStream method addMember.
private void addMember(String member, XWikiDocument groupDocument, BaseClass groupClass, XWikiContext xcontext) throws FilterException {
BaseObject memberObject;
try {
memberObject = groupDocument.newXObject(groupClass.getReference(), xcontext);
} catch (XWikiException e) {
throw new FilterException("Failed to add a group member object", e);
}
memberObject.setStringValue("member", member);
}
use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class XWikiAttachmentOutputFilterStream method onWikiAttachment.
@Override
public void onWikiAttachment(String name, InputStream content, Long size, FilterEventParameters parameters) throws FilterException {
if (this.entity == null) {
this.entity = new XWikiAttachment();
}
this.entity.setFilename(name);
if (content != null) {
try {
this.entity.setContent(content);
} catch (IOException e) {
throw new FilterException("Failed to set attachment content", e);
}
}
// Author
this.entity.setAuthorReference(getUserReference(WikiAttachmentFilter.PARAMETER_REVISION_AUTHOR, parameters, null));
if (this.properties == null || this.properties.isVersionPreserved()) {
setVersion(parameters);
this.entity.setComment(getString(WikiAttachmentFilter.PARAMETER_REVISION_COMMENT, parameters, ""));
this.entity.setDate(getDate(WikiAttachmentFilter.PARAMETER_REVISION_DATE, parameters, new Date()));
this.entity.setMimeType(getString(WikiAttachmentFilter.PARAMETER_MIMETYPE, parameters, null));
String revisions = getString(XWikiWikiAttachmentFilter.PARAMETER_JRCSREVISIONS, parameters, null);
if (revisions != null) {
try {
this.entity.setArchive(revisions);
} catch (XWikiException e) {
throw new FilterException("Failed to set attachment archive", e);
}
}
this.entity.setMetaDataDirty(false);
}
}
Aggregations