use of org.apache.jackrabbit.server.io.PropertyManager in project jackrabbit by apache.
the class ResourceConfig method parse.
/**
* Parses the given input stream into the xml configuration file.
* The xml must match the following structure:<br>
* <pre>
* <!ELEMENT config (iomanager, propertymanager, (collection | noncollection)?, filter?, mimetypeproperties?) >
* <!ELEMENT iomanager (class, iohandler*) >
* <!ELEMENT iohandler (class) >
* <!ELEMENT propertymanager (class, propertyhandler*) >
* <!ELEMENT propertyhandler (class) >
* <!ELEMENT collection (nodetypes) >
* <!ELEMENT noncollection (nodetypes) >
* <!ELEMENT filter (class, namespaces?, nodetypes?) >
* <!ELEMENT class >
* <!ATTLIST class
* name CDATA #REQUIRED
* >
* <!ELEMENT namespaces (prefix|uri)* >
* <!ELEMENT prefix (CDATA) >
* <!ELEMENT uri (CDATA) >
* <!ELEMENT nodetypes (nodetype)* >
* <!ELEMENT nodetype (CDATA) >
* <!ELEMENT mimetypeproperties (mimemapping*, defaultmimetype) >
* <!ELEMENT mimemapping >
* <!ATTLIST mimemapping
* extension CDATA #REQUIRED
* mimetype CDATA #REQUIRED
* >
* <!ELEMENT defaultmimetype (CDATA) >
* </pre>
* <p>
* The <mimetypeproperties/> settings have been deprecated and will
* be ignored with a warning. Instead you can use the
* {@link SimpleWebdavServlet#INIT_PARAM_MIME_INFO mime-info}
* servlet initialization parameter to customize the media type settings.
*
* @param stream
*/
public void parse(InputStream stream) {
try {
Element config = DomUtil.parseDocument(stream).getDocumentElement();
if (config == null) {
log.warn("Mandatory 'config' element is missing.");
return;
}
// iomanager config entry
Element el = DomUtil.getChildElement(config, ELEMENT_IOMANAGER, null);
if (el != null) {
Object inst = buildClassFromConfig(el);
if (inst != null && inst instanceof IOManager) {
ioManager = (IOManager) inst;
ioManager.setDetector(detector);
// get optional 'iohandler' child elements and populate the
// ioManager with the instances
ElementIterator iohElements = DomUtil.getChildren(el, ELEMENT_IOHANDLER, null);
while (iohElements.hasNext()) {
Element iohEl = iohElements.nextElement();
inst = buildClassFromConfig(iohEl);
if (inst != null && inst instanceof IOHandler) {
IOHandler handler = (IOHandler) inst;
setParameters(handler, iohEl);
ioManager.addIOHandler(handler);
} else {
log.warn("Not a valid IOHandler : " + getClassName(iohEl));
}
}
} else {
log.warn("'iomanager' element does not define a valid IOManager.");
}
} else {
log.warn("'iomanager' element is missing.");
}
// propertymanager config entry
el = DomUtil.getChildElement(config, ELEMENT_PROPERTYMANAGER, null);
if (el != null) {
Object inst = buildClassFromConfig(el);
if (inst != null && inst instanceof PropertyManager) {
propManager = (PropertyManager) inst;
// get optional 'iohandler' child elements and populate the
// ioManager with the instances
ElementIterator iohElements = DomUtil.getChildren(el, ELEMENT_PROPERTYHANDLER, null);
while (iohElements.hasNext()) {
Element iohEl = iohElements.nextElement();
inst = buildClassFromConfig(iohEl);
if (inst != null && inst instanceof PropertyHandler) {
PropertyHandler handler = (PropertyHandler) inst;
setParameters(handler, iohEl);
propManager.addPropertyHandler(handler);
} else {
log.warn("Not a valid PropertyHandler : " + getClassName(iohEl));
}
}
} else {
log.warn("'propertymanager' element does not define a valid PropertyManager.");
}
} else {
log.debug("'propertymanager' element is missing.");
}
// copymovemanager config entry
el = DomUtil.getChildElement(config, ELEMENT_COPYMOVEMANAGER, null);
if (el != null) {
Object inst = buildClassFromConfig(el);
if (inst != null && inst instanceof CopyMoveManager) {
cmManager = (CopyMoveManager) inst;
// get optional 'copymovehandler' child elements and populate
// the copy move manager with the instances
ElementIterator iohElements = DomUtil.getChildren(el, ELEMENT_COPYMOVEHANDLER, null);
while (iohElements.hasNext()) {
Element iohEl = iohElements.nextElement();
inst = buildClassFromConfig(iohEl);
if (inst != null && inst instanceof CopyMoveHandler) {
CopyMoveHandler handler = (CopyMoveHandler) inst;
setParameters(handler, iohEl);
cmManager.addCopyMoveHandler(handler);
} else {
log.warn("Not a valid CopyMoveHandler : " + getClassName(iohEl));
}
}
} else {
log.warn("'copymovemanager' element does not define a valid CopyMoveManager.");
}
} else {
log.debug("'copymovemanager' element is missing.");
}
// collection/non-collection config entry
el = DomUtil.getChildElement(config, "collection", null);
if (el != null) {
nodetypeNames = parseNodeTypesEntry(el);
collectionNames = true;
} else if ((el = DomUtil.getChildElement(config, "noncollection", null)) != null) {
nodetypeNames = parseNodeTypesEntry(el);
collectionNames = false;
}
// todo: should check if both 'noncollection' and 'collection' are present and write a warning
// filter config entry
el = DomUtil.getChildElement(config, "filter", null);
if (el != null) {
Object inst = buildClassFromConfig(el);
if (inst != null && inst instanceof ItemFilter) {
itemFilter = (ItemFilter) inst;
}
if (itemFilter != null) {
itemFilter.setFilteredNodetypes(parseNodeTypesEntry(el));
parseNamespacesEntry(el);
}
} else {
log.debug("No 'filter' element specified.");
}
el = DomUtil.getChildElement(config, "mimetypeproperties", null);
if (el != null) {
log.warn("Ignoring deprecated mimetypeproperties settings");
}
} catch (IOException e) {
log.debug("Invalid resource configuration: " + e.getMessage());
} catch (ParserConfigurationException e) {
log.warn("Failed to parse resource configuration: " + e.getMessage());
} catch (SAXException e) {
log.warn("Failed to parse resource configuration: " + e.getMessage());
}
}
Aggregations