if (Logging.connectors.isDebugEnabled())
{
Logging.connectors.debug("SharePoint: list xml: '" + list[0].toString() + "'");
}
XMLDoc doc = new XMLDoc( list[0].toString() );
ArrayList nodeList = new ArrayList();
doc.processPath(nodeList, "*", null);
if (nodeList.size() != 1)
{
throw new ManifoldCFException("Bad xml - missing outer 'ns1:dsQueryResponse' node - there are "+Integer.toString(nodeList.size())+" nodes");
}
Object parent = nodeList.get(0);
//System.out.println( "Outer NodeName = " + doc.getNodeName(parent) );
if (!doc.getNodeName(parent).equals("ns1:dsQueryResponse"))
throw new ManifoldCFException("Bad xml - outer node is not 'ns1:dsQueryResponse'");
nodeList.clear();
doc.processPath(nodeList, "*", parent);
parent = nodeList.get( 0 ); // <Shared_X0020_Documents />
nodeList.clear();
doc.processPath(nodeList, "*", parent);
// Process each result (Should only be one )
// Get each childs Value and add to return array
for ( int i= 0; i < nodeList.size(); i++ )
{
Object documentNode = nodeList.get( i );
ArrayList fieldList = new ArrayList();
doc.processPath( fieldList, "*", documentNode );
for ( int j =0; j < fieldList.size(); j++)
{
Object field = fieldList.get( j );
String fieldData = doc.getData(field);
String fieldName = doc.getNodeName(field);
// Right now this really only works right for single-valued fields. For multi-valued
// fields, we'd need to know in advance that they were multivalued
// so that we could interpret commas as value separators.
result.put(fieldName,fieldData);
}
}
}
else
{
// SharePoint 2010: Get field values some other way
// Sharepoint 2010; use Lists service instead
ListsWS lservice = new ListsWS(baseUrl + site, userName, password, configuration, httpClient );
ListsSoapStub stub1 = (ListsSoapStub)lservice.getListsSoapHandler();
String sitePlusDocId = serverLocation + site + docId;
if (sitePlusDocId.startsWith("/"))
sitePlusDocId = sitePlusDocId.substring(1);
GetListItemsQuery q = buildMatchQuery("FileRef","Text",sitePlusDocId);
GetListItemsViewFields viewFields = buildViewFields(fieldNames);
GetListItemsResponseGetListItemsResult items = stub1.getListItems(docLibrary, "", q, viewFields, "1", buildNonPagingQueryOptions(), null);
if (items == null)
return result;
MessageElement[] list = items.get_any();
if (Logging.connectors.isDebugEnabled()){
Logging.connectors.debug("SharePoint: getListItems for '"+docId+"' using FileRef value '"+sitePlusDocId+"' xml response: '" + list[0].toString() + "'");
}
ArrayList nodeList = new ArrayList();
XMLDoc doc = new XMLDoc(list[0].toString());
doc.processPath(nodeList, "*", null);
if (nodeList.size() != 1)
throw new ManifoldCFException("Bad xml - expecting one outer 'ns1:listitems' node - there are " + Integer.toString(nodeList.size()) + " nodes");
Object parent = nodeList.get(0);
if (!"ns1:listitems".equals(doc.getNodeName(parent)))
throw new ManifoldCFException("Bad xml - outer node is not 'ns1:listitems'");
nodeList.clear();
doc.processPath(nodeList, "*", parent);
if (nodeList.size() != 1)
throw new ManifoldCFException("Expected rsdata result but no results found.");
Object rsData = nodeList.get(0);
int itemCount = Integer.parseInt(doc.getValue(rsData, "ItemCount"));
if (itemCount == 0)
return result;
// Now, extract the files from the response document
ArrayList nodeDocs = new ArrayList();
doc.processPath(nodeDocs, "*", rsData);
if (nodeDocs.size() != itemCount)
throw new ManifoldCFException("itemCount does not match with nodeDocs.size()");
if (itemCount != 1)
throw new ManifoldCFException("Expecting only one item, instead saw '"+itemCount+"'");
Object o = nodeDocs.get(0);
// Look for all the specified attributes in the record
for (Object attrName : fieldNames)
{
String attrValue = doc.getValue(o,"ows_"+(String)attrName);
if (attrValue != null)
{
result.put(attrName.toString(),valueMunge(attrValue));
}
}