use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class OptionsInfo method createFromXml.
/**
* Build an <code>OptionsInfo</code> object from the root element present
* in the request body.
*
* @param optionsElement
* @return
* @throws DavException if the optionsElement is <code>null</code>
* or not a DAV:options element.
*/
public static OptionsInfo createFromXml(Element optionsElement) throws DavException {
if (!DomUtil.matches(optionsElement, DeltaVConstants.XML_OPTIONS, DeltaVConstants.NAMESPACE)) {
log.warn("DAV:options element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
OptionsInfo oInfo = new OptionsInfo();
ElementIterator it = DomUtil.getChildren(optionsElement);
while (it.hasNext()) {
// todo: not correct since assuming its the deltaV-namespace
oInfo.entriesLocalNames.add(it.nextElement().getLocalName());
}
return oInfo;
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class RepositoryServiceImpl method getRegisteredNamespaces.
@Override
public Map<String, String> getRegisteredNamespaces(SessionInfo sessionInfo) throws RepositoryException {
ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_REGISTERED_NAMESPACES, ItemResourceConstants.NAMESPACE);
HttpReport request = null;
try {
request = new HttpReport(uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()), info);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
Document doc = request.getResponseBodyAsDocument(response.getEntity());
Map<String, String> namespaces = new HashMap<String, String>();
if (doc != null) {
Element rootElement = doc.getDocumentElement();
ElementIterator nsElems = DomUtil.getChildren(rootElement, JcrRemotingConstants.XML_NAMESPACE, ItemResourceConstants.NAMESPACE);
while (nsElems.hasNext()) {
Element elem = nsElems.nextElement();
String prefix = DomUtil.getChildText(elem, JcrRemotingConstants.XML_PREFIX, ItemResourceConstants.NAMESPACE);
String uri = DomUtil.getChildText(elem, JcrRemotingConstants.XML_URI, ItemResourceConstants.NAMESPACE);
// default namespace
if (prefix == null && uri == null) {
prefix = uri = "";
}
// any other uri must not be null
if (uri != null) {
namespaces.put(prefix, uri);
// TODO: not correct since nsRegistry is retrieved from each session
nsCache.add(prefix, uri);
} else {
log.error("Invalid prefix / uri pair: " + prefix + " -> " + uri);
}
}
}
return namespaces;
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class RepositoryServiceImpl method retrieveQNodeTypeDefinitions.
/**
* @param sessionInfo
* @param reportDoc
* @return
* @throws RepositoryException
*/
private Iterator<QNodeTypeDefinition> retrieveQNodeTypeDefinitions(SessionInfo sessionInfo, Document reportDoc) throws RepositoryException {
ElementIterator it = DomUtil.getChildren(reportDoc.getDocumentElement(), NodeTypeConstants.NODETYPE_ELEMENT, null);
List<QNodeTypeDefinition> ntDefs = new ArrayList<QNodeTypeDefinition>();
NamePathResolver resolver = getNamePathResolver(sessionInfo);
while (it.hasNext()) {
ntDefs.add(DefinitionUtil.createQNodeTypeDefinition(it.nextElement(), resolver, getQValueFactory()));
}
// refresh node type definitions map
synchronized (nodeTypeDefinitions) {
nodeTypeDefinitions.clear();
for (Object ntDef : ntDefs) {
QNodeTypeDefinition def = (QNodeTypeDefinition) ntDef;
nodeTypeDefinitions.put(def.getName(), def);
}
}
return ntDefs.iterator();
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class DefinitionUtil method createQPropertyDefinition.
/**
* @param declaringNodeType
* @param pdefElement
* @param resolver
* @param qValueFactory
* @return
* @throws RepositoryException
*/
static QPropertyDefinition createQPropertyDefinition(Name declaringNodeType, Element pdefElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
QPropertyDefinitionBuilder builder = new QPropertyDefinitionBuilder();
buildQItemDefinition(declaringNodeType, pdefElement, resolver, builder);
if (pdefElement.hasAttribute(REQUIREDTYPE_ATTRIBUTE)) {
builder.setRequiredType(PropertyType.valueFromName(pdefElement.getAttribute(REQUIREDTYPE_ATTRIBUTE)));
}
if (pdefElement.hasAttribute(MULTIPLE_ATTRIBUTE)) {
builder.setMultiple(Boolean.valueOf(pdefElement.getAttribute(MULTIPLE_ATTRIBUTE)));
}
if (pdefElement.hasAttribute(FULL_TEXT_SEARCHABLE_ATTRIBUTE)) {
builder.setFullTextSearchable(Boolean.valueOf(pdefElement.getAttribute(FULL_TEXT_SEARCHABLE_ATTRIBUTE)));
}
if (pdefElement.hasAttribute(QUERY_ORDERABLE_ATTRIBUTE)) {
builder.setQueryOrderable(Boolean.valueOf(pdefElement.getAttribute(QUERY_ORDERABLE_ATTRIBUTE)));
}
int requiredType = builder.getRequiredType();
Element child = DomUtil.getChildElement(pdefElement, DEFAULTVALUES_ELEMENT, null);
if (child != null) {
ElementIterator it = DomUtil.getChildren(child, DEFAULTVALUE_ELEMENT, null);
while (it.hasNext()) {
String jcrVal = DomUtil.getText(it.nextElement());
if (jcrVal == null) {
jcrVal = "";
}
QValue qValue;
if (requiredType == PropertyType.BINARY) {
// TODO: improve
Value v = new ValueFactoryQImpl(qValueFactory, resolver).createValue(jcrVal, requiredType);
qValue = ValueFormat.getQValue(v, resolver, qValueFactory);
} else {
qValue = ValueFormat.getQValue(jcrVal, requiredType, resolver, qValueFactory);
}
builder.addDefaultValue(qValue);
}
}
// else: no default values defined.
child = DomUtil.getChildElement(pdefElement, VALUECONSTRAINTS_ELEMENT, null);
if (child != null) {
ElementIterator it = DomUtil.getChildren(child, VALUECONSTRAINT_ELEMENT, null);
while (it.hasNext()) {
String qValue = DomUtil.getText(it.nextElement());
// in case of name and path constraint, the value must be
// converted to SPI values
// TODO: tobefixed. path-constraint may contain trailing *
builder.addValueConstraint(ValueConstraint.create(requiredType, qValue, resolver));
}
}
child = DomUtil.getChildElement(pdefElement, AVAILABLE_QUERY_OPERATORS_ELEMENT, null);
if (child == null) {
builder.setAvailableQueryOperators(new String[0]);
} else {
List<String> names = new ArrayList<String>();
ElementIterator it = DomUtil.getChildren(child, AVAILABLE_QUERY_OPERATOR_ELEMENT, null);
while (it.hasNext()) {
String str = DomUtil.getText(it.nextElement());
names.add(str);
}
builder.setAvailableQueryOperators(names.toArray(new String[names.size()]));
}
return builder.build();
}
use of org.apache.jackrabbit.webdav.xml.ElementIterator in project jackrabbit by apache.
the class BindInfo method createFromXml.
/**
* Build an <code>BindInfo</code> object from the root element present
* in the request body.
*
* @param root the root element of the request body
* @return a BindInfo object containing segment and href
* @throws org.apache.jackrabbit.webdav.DavException if the BIND request is malformed
*/
public static BindInfo createFromXml(Element root) throws DavException {
if (!DomUtil.matches(root, BindConstants.XML_BIND, BindConstants.NAMESPACE)) {
log.warn("DAV:bind element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
String href = null;
String segment = null;
ElementIterator it = DomUtil.getChildren(root);
while (it.hasNext()) {
Element elt = it.nextElement();
if (DomUtil.matches(elt, BindConstants.XML_SEGMENT, BindConstants.NAMESPACE)) {
if (segment == null) {
segment = DomUtil.getText(elt);
} else {
log.warn("unexpected multiple occurrence of DAV:segment element");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
} else if (DomUtil.matches(elt, BindConstants.XML_HREF, BindConstants.NAMESPACE)) {
if (href == null) {
href = DomUtil.getText(elt);
} else {
log.warn("unexpected multiple occurrence of DAV:href element");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
} else {
log.warn("unexpected element " + elt.getLocalName());
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
}
if (href == null) {
log.warn("DAV:href element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
if (segment == null) {
log.warn("DAV:segment element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
return new BindInfo(href, segment);
}
Aggregations