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));
}
}
}
return result;
}
catch (javax.xml.soap.SOAPException e)
{
throw new ManifoldCFException("Soap exception: "+e.getMessage(),e);
}
catch (java.net.MalformedURLException e)
{
throw new ManifoldCFException("Bad SharePoint url: "+e.getMessage(),e);
}
catch (javax.xml.rpc.ServiceException e)
{
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("SharePoint: Got a service exception getting field values for site "+site+" library "+docLibrary+" document '"+docId+"' - retrying",e);
currentTime = System.currentTimeMillis();
throw new ServiceInterruption("Service exception: "+e.getMessage(), e, currentTime + 300000L,
currentTime + 12 * 60 * 60000L,-1,true);
}
catch (org.apache.axis.AxisFault e)
{
if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/","HTTP")))
{
org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName("http://xml.apache.org/axis/","HttpErrorCode"));
if (elem != null)
{
elem.normalize();
String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
if (httpErrorCode.equals("404"))
return null;
else if (httpErrorCode.equals("403"))
throw new ManifoldCFException("Remote procedure exception: "+e.getMessage(),e);
else if (httpErrorCode.equals("401"))
{
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("SharePoint: Crawl user does not have sufficient privileges to get field values for site "+site+" library "+docLibrary+" - skipping",e);
return null;
}
throw new ManifoldCFException("Unexpected http error code "+httpErrorCode+" accessing SharePoint at "+baseUrl+site+": "+e.getMessage(),e);
}
throw new ManifoldCFException("Unknown http error occurred: "+e.getMessage(),e);
}
if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/","Server.userException")))
{
String exceptionName = e.getFaultString();
if (exceptionName.equals("java.lang.InterruptedException"))
throw new ManifoldCFException("Interrupted",ManifoldCFException.INTERRUPTED);
}
// I don't know if this is what you get when the library is missing, but here's hoping.
if (e.getMessage().indexOf("List does not exist") != -1)
return null;
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("SharePoint: Got a remote exception getting field values for site "+site+" library "+docLibrary+" document ["+docId+"] - retrying",e);
currentTime = System.currentTimeMillis();
throw new ServiceInterruption("Remote procedure exception: "+e.getMessage(), e, currentTime + 300000L,
currentTime + 3 * 60 * 60000L,-1,false);
}
catch (java.rmi.RemoteException e)
{
throw new ManifoldCFException("Unexpected remote exception occurred: "+e.getMessage(),e);
}
}