use of org.apache.jackrabbit.webdav.xml.ElementIterator 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());
}
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class ResourceConfig method parseNodeTypesEntry.
private static String[] parseNodeTypesEntry(Element parent) {
String[] ntNames;
Element nodetypes = DomUtil.getChildElement(parent, "nodetypes", null);
if (nodetypes != null) {
List<String> l = new ArrayList<String>();
ElementIterator it = DomUtil.getChildren(nodetypes, "nodetype", null);
while (it.hasNext()) {
Element e = it.nextElement();
l.add(DomUtil.getText(e));
}
ntNames = l.toArray(new String[l.size()]);
} else {
ntNames = new String[0];
}
return ntNames;
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class EventImpl method getEventInfo.
private static Map<Name, QValue> getEventInfo(Element infoElement, NamePathResolver resolver, QValueFactory qvFactory) {
if (infoElement == null) {
return Collections.emptyMap();
}
Map<Name, QValue> info = new HashMap<Name, QValue>();
ElementIterator it = DomUtil.getChildren(infoElement);
while (it.hasNext()) {
Element el = it.nextElement();
String uri = el.getNamespaceURI();
if (uri == null) {
uri = Namespace.EMPTY_NAMESPACE.getURI();
}
String localName = el.getLocalName();
String value = DomUtil.getTextTrim(el);
try {
Name n = N_FACTORY.create(uri, localName);
QValue qv = null;
if (value != null) {
qv = ValueFormat.getQValue(value, PropertyType.PATH, resolver, qvFactory);
}
info.put(n, qv);
} catch (RepositoryException e) {
log.error("Internal Error: {}", e.getMessage());
}
}
return info;
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class DefinitionUtil method createQNodeTypeDefinition.
static QNodeTypeDefinition createQNodeTypeDefinition(Element ntdElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
QNodeTypeDefinitionBuilder builder = new QNodeTypeDefinitionBuilder();
// NOTE: the server should send the namespace-mappings as addition ns-defininitions
try {
if (ntdElement.hasAttribute(NAME_ATTRIBUTE)) {
builder.setName(resolver.getQName(ntdElement.getAttribute(NAME_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(PRIMARYITEMNAME_ATTRIBUTE)) {
builder.setPrimaryItemName(resolver.getQName(ntdElement.getAttribute(PRIMARYITEMNAME_ATTRIBUTE)));
}
Element child = DomUtil.getChildElement(ntdElement, SUPERTYPES_ELEMENT, null);
if (child != null) {
ElementIterator stIter = DomUtil.getChildren(child, SUPERTYPE_ELEMENT, null);
List<Name> qNames = new ArrayList<Name>();
while (stIter.hasNext()) {
Name st = resolver.getQName(DomUtil.getTextTrim(stIter.nextElement()));
qNames.add(st);
}
builder.setSupertypes(qNames.toArray(new Name[qNames.size()]));
}
if (ntdElement.hasAttribute(ISMIXIN_ATTRIBUTE)) {
builder.setMixin(Boolean.valueOf(ntdElement.getAttribute(ISMIXIN_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)) {
builder.setOrderableChildNodes(Boolean.valueOf(ntdElement.getAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(ISABSTRACT_ATTRIBUTE)) {
builder.setAbstract(Boolean.valueOf(ntdElement.getAttribute(ISABSTRACT_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(ISQUERYABLE_ATTRIBUTE)) {
builder.setQueryable(Boolean.valueOf(ntdElement.getAttribute(ISQUERYABLE_ATTRIBUTE)));
}
// nodeDefinitions
ElementIterator it = DomUtil.getChildren(ntdElement, CHILDNODEDEFINITION_ELEMENT, null);
List<QNodeDefinition> nds = new ArrayList<QNodeDefinition>();
while (it.hasNext()) {
nds.add(createQNodeDefinition(builder.getName(), it.nextElement(), resolver));
}
builder.setChildNodeDefs(nds.toArray(new QNodeDefinition[nds.size()]));
// propertyDefinitions
it = DomUtil.getChildren(ntdElement, PROPERTYDEFINITION_ELEMENT, null);
List<QPropertyDefinition> pds = new ArrayList<QPropertyDefinition>();
while (it.hasNext()) {
pds.add(createQPropertyDefinition(builder.getName(), it.nextElement(), resolver, qValueFactory));
}
builder.setPropertyDefs(pds.toArray(new QPropertyDefinition[pds.size()]));
} catch (NameException e) {
log.error(e.getMessage());
throw new RepositoryException(e);
}
return builder.build();
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class DefinitionUtil method createQNodeDefinition.
/**
* @param declaringNodeType
* @param ndefElement
* @param resolver
* @return
* @throws RepositoryException
*/
static QNodeDefinition createQNodeDefinition(Name declaringNodeType, Element ndefElement, NamePathResolver resolver) throws RepositoryException {
QNodeDefinitionBuilder builder = new QNodeDefinitionBuilder();
buildQItemDefinition(declaringNodeType, ndefElement, resolver, builder);
// NOTE: the server should send the namespace-mappings as addition ns-defininitions
try {
if (ndefElement.hasAttribute(DEFAULTPRIMARYTYPE_ATTRIBUTE)) {
Name defaultPrimaryType = resolver.getQName(ndefElement.getAttribute(DEFAULTPRIMARYTYPE_ATTRIBUTE));
builder.setDefaultPrimaryType(defaultPrimaryType);
}
Element reqPrimaryTypes = DomUtil.getChildElement(ndefElement, REQUIREDPRIMARYTYPES_ELEMENT, null);
if (reqPrimaryTypes != null) {
ElementIterator it = DomUtil.getChildren(reqPrimaryTypes, REQUIREDPRIMARYTYPE_ELEMENT, null);
while (it.hasNext()) {
builder.addRequiredPrimaryType(resolver.getQName(DomUtil.getTextTrim(it.nextElement())));
}
} else {
builder.addRequiredPrimaryType(NameConstants.NT_BASE);
}
if (ndefElement.hasAttribute(SAMENAMESIBLINGS_ATTRIBUTE)) {
builder.setAllowsSameNameSiblings(Boolean.valueOf(ndefElement.getAttribute(SAMENAMESIBLINGS_ATTRIBUTE)));
}
} catch (NameException e) {
throw new RepositoryException(e);
}
return builder.build();
}
Aggregations