mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 14:02:22 +00:00
[FIXED HUDSON-3267] api/xml?xpath=...&wrapper=... behaved inconsistently for results of size 0 or 1.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@16157 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
b70e53fe5b
commit
5b28310d28
2 files changed
+63
-20
No files matched your search
@@ -111,30 +111,27 @@ public class Api extends AbstractModelObject {
|
||||
}
|
||||
|
||||
List list = dom.selectNodes(xpath);
|
||||
if(list.isEmpty()) {
|
||||
// XPath didn't match
|
||||
if (wrapper!=null) {
|
||||
Element root = DocumentFactory.getInstance().createElement(wrapper);
|
||||
for (Object o : list) {
|
||||
if (o instanceof String) {
|
||||
root.addText(o.toString());
|
||||
} else {
|
||||
root.add(((org.dom4j.Node)o).detach());
|
||||
}
|
||||
}
|
||||
result = root;
|
||||
} else if (list.isEmpty()) {
|
||||
rsp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
rsp.getWriter().print(Messages.Api_NoXPathMatch(xpath));
|
||||
return;
|
||||
}
|
||||
if(list.size()>1) {
|
||||
if(wrapper!=null) {
|
||||
Element root = DocumentFactory.getInstance().createElement(wrapper);
|
||||
for (Object o : list) {
|
||||
if(o instanceof String)
|
||||
root.addText(o.toString());
|
||||
else
|
||||
root.add(((org.dom4j.Node)o).detach());
|
||||
}
|
||||
result = root;
|
||||
} else {
|
||||
// XPath didn't match
|
||||
rsp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
rsp.getWriter().print(Messages.Api_MultipleMatch(xpath,list.size()));
|
||||
return;
|
||||
}
|
||||
} else
|
||||
} else if (list.size() > 1) {
|
||||
rsp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
rsp.getWriter().print(Messages.Api_MultipleMatch(xpath,list.size()));
|
||||
return;
|
||||
} else {
|
||||
result = list.get(0);
|
||||
}
|
||||
} catch (DocumentException e) {
|
||||
throw new IOException2(e);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user