List of usage examples for org.w3c.dom Element getFirstChild
public Node getFirstChild();
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * * @param parentSite// www . j a va 2 s . c o m * @param docLibrary * @return document library ID * @throws ManifoldCFException * @throws ServiceInterruption */ public String getDocLibID(String parentSite, String parentSiteDecoded, String docLibrary) throws ServiceInterruption, ManifoldCFException { long currentTime; try { // The old code here used to call the lists service to find the guid, using the doc library url name as the title. // This did not work when the title differed from the url name. // On 5/8/2008 I modified the code to use the lists service to locate the correct record by matching the defaultViewUrl field, // so that we instead iterate through the children. It's more expensive but it works. String parentSiteRequest = parentSite; if (parentSiteRequest.equals("/")) { parentSiteRequest = ""; // root case parentSiteDecoded = ""; } ListsWS listsService = new ListsWS(baseUrl + parentSiteRequest, userName, password, configuration, httpClient); ListsSoap listsCall = listsService.getListsSoapHandler(); GetListCollectionResponseGetListCollectionResult listResp = listsCall.getListCollection(); org.apache.axis.message.MessageElement[] lists = listResp.get_any(); XMLDoc doc = new XMLDoc(lists[0].toString()); ArrayList nodeList = new ArrayList(); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) { throw new ManifoldCFException("Bad xml - missing outer 'ns1:Lists' node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); if (!doc.getNodeName(parent).equals("ns1:Lists")) throw new ManifoldCFException("Bad xml - outer node is not 'ns1:Lists'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); // <ns1:Lists> String prefixPath = decodedServerLocation + parentSiteDecoded + "/"; int i = 0; while (i < nodeList.size()) { Object o = nodeList.get(i++); String baseType = doc.getValue(o, "BaseType"); if (baseType.equals("1")) { // We think it's a library // This is how we display it, so this has the right path extension String urlPath = doc.getValue(o, "DefaultViewUrl"); // If it has no view url, we don't have any idea what to do with it if (urlPath != null && urlPath.length() > 0) { // Normalize conditionally if (!urlPath.startsWith("/")) urlPath = prefixPath + urlPath; // Get rid of what we don't want, unconditionally if (urlPath.startsWith(prefixPath)) { urlPath = urlPath.substring(prefixPath.length()); // We're at the library name. Figure out where the end of it is. int index = urlPath.indexOf("/"); if (index == -1) throw new ManifoldCFException( "Bad library view url without site: '" + urlPath + "'"); String pathpart = urlPath.substring(0, index); if (pathpart.equals(docLibrary)) { // We found it! // Return its ID return doc.getValue(o, "ID"); } } else { Logging.connectors.warn("SharePoint: Library view url is not in the expected form: '" + urlPath + "'; it should start with '" + prefixPath + "'; skipping"); } } } } // Not found - return null return null; } 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 the library ID for site " + parentSite + " library " + docLibrary + " - 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) { currentTime = System.currentTimeMillis(); 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")) { // Page did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The page at " + baseUrl + parentSite + " did not exist; assuming library deleted"); return null; } else if (httpErrorCode.equals("401")) { // User did not have permissions for this library to list libraries if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: The crawl user did not have access to list libraries for " + baseUrl + parentSite + "; skipping"); return null; } else if (httpErrorCode.equals("403")) throw new ManifoldCFException( "Http error " + httpErrorCode + " while reading from " + baseUrl + parentSite + " - check IIS and SharePoint security settings! " + e.getMessage(), e); else throw new ManifoldCFException("Unexpected http error code " + httpErrorCode + " accessing SharePoint at " + baseUrl + parentSite + ": " + e.getMessage(), e); } throw new ManifoldCFException("Unknown http error occurred: " + e.getMessage(), e); } else if (e.getFaultCode() .equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) { org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorcode")); if (elem != null) { elem.normalize(); String sharepointErrorCode = elem.getFirstChild().getNodeValue().trim(); if (sharepointErrorCode.equals("0x82000006")) { // List did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The list " + docLibrary + " in site " + parentSite + " did not exist; assuming library deleted"); return null; } else { if (Logging.connectors.isDebugEnabled()) { org.w3c.dom.Element elem2 = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorstring")); String errorString = ""; if (elem != null) errorString = elem2.getFirstChild().getNodeValue().trim(); Logging.connectors.debug("SharePoint: Getting library ID for the list " + docLibrary + " in site " + parentSite + " failed with unexpected SharePoint error code " + sharepointErrorCode + ": " + errorString + " - Skipping", e); } return null; } } if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: Unknown SharePoint server error getting library ID for site " + parentSite + " library " + docLibrary + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Unknown SharePoint server error: " + e.getMessage() + " - retrying", e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } 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); } if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unknown remote exception getting library ID for site " + parentSite + " library " + docLibrary + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } catch (java.rmi.RemoteException e) { // We expect the axis exception to be thrown, not this generic one! // So, fail hard if we see it. if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: Got an unexpected remote exception getting library ID for site " + parentSite + " library " + docLibrary, e); throw new ManifoldCFException("Unexpected remote procedure exception: " + e.getMessage(), e); } }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * Get the acls for a document library.//from w w w. j a v a2s . c o m * @param site * @param guid is the list/library GUID * @return array of sids * @throws Exception */ public String[] getACLs(String site, String guid, boolean activeDirectoryAuthority) throws ManifoldCFException, ServiceInterruption { long currentTime; try { if (site.compareTo("/") == 0) site = ""; // root case UserGroupWS userService = new UserGroupWS(baseUrl + site, userName, password, configuration, httpClient); com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap userCall = userService .getUserGroupSoapHandler(); PermissionsWS aclService = new PermissionsWS(baseUrl + site, userName, password, configuration, httpClient); com.microsoft.schemas.sharepoint.soap.directory.PermissionsSoap aclCall = aclService .getPermissionsSoapHandler(); com.microsoft.schemas.sharepoint.soap.directory.GetPermissionCollectionResponseGetPermissionCollectionResult aclResult = aclCall .getPermissionCollection(guid, "List"); org.apache.axis.message.MessageElement[] aclList = aclResult.get_any(); XMLDoc doc = new XMLDoc(aclList[0].toString()); ArrayList nodeList = new ArrayList(); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) { throw new ManifoldCFException( "Bad xml - missing outer 'ns1:GetPermissionCollection' node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); if (!doc.getNodeName(parent).equals("ns1:GetPermissionCollection")) throw new ManifoldCFException("Bad xml - outer node is not 'ns1:GetPermissionCollection'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); if (nodeList.size() != 1) { throw new ManifoldCFException(" No results found."); } parent = nodeList.get(0); nodeList.clear(); doc.processPath(nodeList, "*", parent); Set<String> sids = new HashSet<String>(); int i = 0; for (; i < nodeList.size(); i++) { Object node = nodeList.get(i); String mask = doc.getValue(node, "Mask"); long maskValue = new Long(mask).longValue(); if ((maskValue & 1L) == 1L) { // Permission to view String isUser = doc.getValue(node, "MemberIsUser"); if (isUser.compareToIgnoreCase("True") == 0) { // Use AD user or group String userLogin = doc.getValue(node, "UserLogin"); String userSid = getSidForUser(userCall, userLogin, activeDirectoryAuthority); sids.add(userSid); } else { // Role List<String> roleSids; String roleName = doc.getValue(node, "RoleName"); if (roleName.length() == 0) { roleName = doc.getValue(node, "GroupName"); if (roleName != null && roleName.length() > 0) { roleSids = getSidsForGroup(userCall, roleName, activeDirectoryAuthority); } else { Logging.connectors.warn( "SharePoint: Unrecognized permission collection entry: no role, no group: " + doc.getXML()); roleSids = new ArrayList<String>(); } } else { roleSids = getSidsForRole(userCall, roleName, activeDirectoryAuthority); } for (String sid : roleSids) { sids.add(sid); } } } } return sids.toArray(new String[0]); } 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 the acls for site " + site + " guid " + guid + " - 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) { currentTime = System.currentTimeMillis(); 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")) { // Page did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The page at " + baseUrl + site + " did not exist; assuming list/library deleted"); return null; } else if (httpErrorCode.equals("401")) { // User did not have permissions for this library to get the acls if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug( "SharePoint: The crawl user did not have access to the permissions service for " + baseUrl + site + "; skipping documents within"); return null; } else if (httpErrorCode.equals("403")) throw new ManifoldCFException( "Http error " + httpErrorCode + " while reading from " + baseUrl + site + " - check IIS and SharePoint security settings! " + e.getMessage(), e); else 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); } else if (e.getFaultCode() .equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) { org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorcode")); if (elem != null) { elem.normalize(); String sharepointErrorCode = elem.getFirstChild().getNodeValue().trim(); if (sharepointErrorCode.equals("0x82000006")) { // List did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The list " + guid + " in site " + site + " did not exist; assuming list/library deleted"); return null; } else { if (Logging.connectors.isDebugEnabled()) { org.w3c.dom.Element elem2 = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorstring")); String errorString = ""; if (elem != null) errorString = elem2.getFirstChild().getNodeValue().trim(); Logging.connectors.debug("SharePoint: Getting permissions for the list " + guid + " in site " + site + " failed with unexpected SharePoint error code " + sharepointErrorCode + ": " + errorString + " - Skipping", e); } return null; } } if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: Unknown SharePoint server error getting the acls for site " + site + " guid " + guid + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Unknown SharePoint server error: " + e.getMessage() + " - retrying", e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } 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); } if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unknown remote exception getting the acls for site " + site + " guid " + guid + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } catch (java.rmi.RemoteException e) { // We expect the axis exception to be thrown, not this generic one! // So, fail hard if we see it. if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unexpected remote exception getting the acls for site " + site + " guid " + guid, e); throw new ManifoldCFException("Unexpected remote procedure exception: " + e.getMessage(), e); } }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * * @param parentSite// w w w. j a v a 2s. c om * @param list name * @return document library ID * @throws ManifoldCFException * @throws ServiceInterruption */ public String getListID(String parentSite, String parentSiteDecoded, String listName) throws ServiceInterruption, ManifoldCFException { long currentTime; try { // The old code here used to call the lists service to find the guid, using the doc library url name as the title. // This did not work when the title differed from the url name. // On 5/8/2008 I modified the code to use the lists service to locate the correct record by matching the defaultViewUrl field, // so that we instead iterate through the children. It's more expensive but it works. String parentSiteRequest = parentSite; if (parentSiteRequest.equals("/")) { parentSiteRequest = ""; // root case parentSiteDecoded = ""; } ListsWS listsService = new ListsWS(baseUrl + parentSiteRequest, userName, password, configuration, httpClient); ListsSoap listsCall = listsService.getListsSoapHandler(); GetListCollectionResponseGetListCollectionResult listResp = listsCall.getListCollection(); org.apache.axis.message.MessageElement[] lists = listResp.get_any(); XMLDoc doc = new XMLDoc(lists[0].toString()); ArrayList nodeList = new ArrayList(); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) { throw new ManifoldCFException("Bad xml - missing outer 'ns1:Lists' node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); if (!doc.getNodeName(parent).equals("ns1:Lists")) throw new ManifoldCFException("Bad xml - outer node is not 'ns1:Lists'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); // <ns1:Lists> String prefixPath = decodedServerLocation + parentSiteDecoded + "/"; int i = 0; while (i < nodeList.size()) { Object o = nodeList.get(i++); String baseType = doc.getValue(o, "BaseType"); if (baseType.equals("0")) { // We think it's a list // This is how we display it, so this has the right path extension String urlPath = doc.getValue(o, "DefaultViewUrl"); // If it has no view url, we don't have any idea what to do with it if (urlPath != null && urlPath.length() > 0) { // Normalize conditionally if (!urlPath.startsWith("/")) urlPath = prefixPath + urlPath; // Get rid of what we don't want, unconditionally if (urlPath.startsWith(prefixPath)) { urlPath = urlPath.substring(prefixPath.length()); // We're at the Lists/listname part of the name. Figure out where the end of it is. int index = urlPath.indexOf("/"); if (index == -1) throw new ManifoldCFException("Bad list view url without site: '" + urlPath + "'"); String pathpart = urlPath.substring(0, index); if ("Lists".equals(pathpart)) { int k = urlPath.indexOf("/", index + 1); if (k == -1) throw new ManifoldCFException( "Bad list view url without 'Lists': '" + urlPath + "'"); pathpart = urlPath.substring(index + 1, k); } if (pathpart.equals(listName)) { // We found it! // Return its ID return doc.getValue(o, "ID"); } } else { Logging.connectors.warn("SharePoint: List view url is not in the expected form: '" + urlPath + "'; expected something beginning with '" + prefixPath + "'; skipping"); } } } } // Not found - return null return null; } 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 the list ID for site " + parentSite + " list " + listName + " - 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) { currentTime = System.currentTimeMillis(); 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")) { // Page did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The page at " + baseUrl + parentSite + " did not exist; assuming list deleted"); return null; } else if (httpErrorCode.equals("401")) { // User did not have permissions for this library to list libraries if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: The crawl user did not have access to list lists for " + baseUrl + parentSite + "; skipping"); return null; } else if (httpErrorCode.equals("403")) throw new ManifoldCFException( "Http error " + httpErrorCode + " while reading from " + baseUrl + parentSite + " - check IIS and SharePoint security settings! " + e.getMessage(), e); else throw new ManifoldCFException("Unexpected http error code " + httpErrorCode + " accessing SharePoint at " + baseUrl + parentSite + ": " + e.getMessage(), e); } throw new ManifoldCFException("Unknown http error occurred: " + e.getMessage(), e); } else if (e.getFaultCode() .equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) { org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorcode")); if (elem != null) { elem.normalize(); String sharepointErrorCode = elem.getFirstChild().getNodeValue().trim(); if (sharepointErrorCode.equals("0x82000006")) { // List did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The list " + listName + " in site " + parentSite + " did not exist; assuming list deleted"); return null; } else { if (Logging.connectors.isDebugEnabled()) { org.w3c.dom.Element elem2 = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorstring")); String errorString = ""; if (elem != null) errorString = elem2.getFirstChild().getNodeValue().trim(); Logging.connectors.debug("SharePoint: Getting list ID for the list " + listName + " in site " + parentSite + " failed with unexpected SharePoint error code " + sharepointErrorCode + ": " + errorString + " - Skipping", e); } return null; } } if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Unknown SharePoint server error getting list ID for site " + parentSite + " list " + listName + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Unknown SharePoint server error: " + e.getMessage() + " - retrying", e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } 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); } if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unknown remote exception getting list ID for site " + parentSite + " list " + listName + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } catch (java.rmi.RemoteException e) { // We expect the axis exception to be thrown, not this generic one! // So, fail hard if we see it. if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unexpected remote exception getting list ID for site " + parentSite + " list " + listName, e); throw new ManifoldCFException("Unexpected remote procedure exception: " + e.getMessage(), e); } }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * Get the acls for a document.// w w w . j a v a2s .c om * NOTE that this function only works for SharePoint 2007+ with the MCPermissions web service installed. * @param site is the encoded subsite path * @param file is the encoded file url (not including protocol or server or location, but including encoded subsite, library and folder/file path) * @return array of document SIDs * @throws ManifoldCFException * @throws ServiceInterruption */ public String[] getDocumentACLs(String site, String file, boolean activeDirectoryAuthority) throws ManifoldCFException, ServiceInterruption { long currentTime; try { if (site.compareTo("/") == 0) site = ""; // root case // Calculate the full server-relative path of the file String encodedRelativePath = serverLocation + file; if (encodedRelativePath.startsWith("/")) encodedRelativePath = encodedRelativePath.substring(1); if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Getting document acls for site '" + site + "' file '" + file + "': Encoded relative path is '" + encodedRelativePath + "'"); UserGroupWS userService = new UserGroupWS(baseUrl + site, userName, password, configuration, httpClient); com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap userCall = userService .getUserGroupSoapHandler(); MCPermissionsWS aclService = new MCPermissionsWS(baseUrl + site, userName, password, configuration, httpClient); com.microsoft.sharepoint.webpartpages.PermissionsSoap aclCall = aclService.getPermissionsSoapHandler(); com.microsoft.sharepoint.webpartpages.GetPermissionCollectionResponseGetPermissionCollectionResult aclResult = aclCall .getPermissionCollection(encodedRelativePath, "Item"); if (aclResult == null) { Logging.connectors.debug("SharePoint: document acls were null"); return null; } org.apache.axis.message.MessageElement[] aclList = aclResult.get_any(); if (Logging.connectors.isDebugEnabled()) { Logging.connectors.debug("SharePoint: document acls xml: '" + aclList[0].toString() + "'"); } XMLDoc doc = new XMLDoc(aclList[0].toString()); ArrayList nodeList = new ArrayList(); doc.processPath(nodeList, "*", null); if (nodeList.size() != 1) { throw new ManifoldCFException( "Bad xml - missing outer 'ns1:GetPermissionCollection' node - there are " + Integer.toString(nodeList.size()) + " nodes"); } Object parent = nodeList.get(0); if (!doc.getNodeName(parent).equals("GetPermissionCollection")) throw new ManifoldCFException("Bad xml - outer node is not 'GetPermissionCollection'"); nodeList.clear(); doc.processPath(nodeList, "*", parent); if (nodeList.size() != 1) { throw new ManifoldCFException(" No results found."); } parent = nodeList.get(0); nodeList.clear(); doc.processPath(nodeList, "*", parent); Set<String> sids = new HashSet<String>(); int i = 0; for (; i < nodeList.size(); i++) { Object node = nodeList.get(i); String mask = doc.getValue(node, "Mask"); long maskValue = new Long(mask).longValue(); if ((maskValue & 1L) == 1L) { // Permission to view String isUser = doc.getValue(node, "MemberIsUser"); if (isUser.compareToIgnoreCase("True") == 0) { // Use AD user or group String userLogin = doc.getValue(node, "UserLogin"); String userSid = getSidForUser(userCall, userLogin, activeDirectoryAuthority); sids.add(userSid); } else { // Role List<String> roleSids; String roleName = doc.getValue(node, "RoleName"); if (roleName.length() == 0) { roleName = doc.getValue(node, "GroupName"); roleSids = getSidsForGroup(userCall, roleName, activeDirectoryAuthority); } else { roleSids = getSidsForRole(userCall, roleName, activeDirectoryAuthority); } for (String sid : roleSids) { sids.add(sid); } } } } return sids.toArray(new String[0]); } 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 the acls for site " + site + " file " + file + " - 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) { currentTime = System.currentTimeMillis(); 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")) { // Page did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The page at " + baseUrl + site + " did not exist; assuming library deleted"); return null; } else if (httpErrorCode.equals("401")) { // User did not have permissions for this library to get the acls if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug( "SharePoint: The crawl user did not have access to the MCPermissions service for " + baseUrl + site + "; skipping documents within"); return null; } else if (httpErrorCode.equals("403")) throw new ManifoldCFException( "Http error " + httpErrorCode + " while reading from " + baseUrl + site + " - check IIS and SharePoint security settings! " + e.getMessage(), e); else 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); } else if (e.getFaultCode() .equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) { org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorcode")); if (elem != null) { elem.normalize(); String sharepointErrorCode = elem.getFirstChild().getNodeValue().trim(); if (sharepointErrorCode.equals("0x82000006")) { // List did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The file " + file + " in site " + site + " did not exist; assuming file deleted"); return null; } else { if (Logging.connectors.isDebugEnabled()) { org.w3c.dom.Element elem2 = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorstring")); String errorString = ""; if (elem != null) errorString = elem2.getFirstChild().getNodeValue().trim(); Logging.connectors.debug("SharePoint: Getting permissions for the file " + file + " in site " + site + " failed with unexpected SharePoint error code " + sharepointErrorCode + ": " + errorString + " - Skipping", e); } return null; } } if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: Unknown SharePoint server error getting the acls for site " + site + " file " + file + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Unknown SharePoint server error: " + e.getMessage() + " - retrying", e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } 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); } if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unknown remote exception getting the acls for site " + site + " file " + file + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } catch (java.rmi.RemoteException e) { // We expect the axis exception to be thrown, not this generic one! // So, fail hard if we see it. if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: Got an unexpected remote exception getting the acls for site " + site + " file " + file, e); throw new ManifoldCFException("Unexpected remote procedure exception: " + e.getMessage(), e); } }
From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileBES.java
private DOMXMLSignature createDetached(SignatureParameters params, DOMSignContext signContext, org.w3c.dom.Document doc, String signatureId, String signatureValueId, final Document inside) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, JAXBException, MarshalException, XMLSignatureException, ParserConfigurationException, IOException { final XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM", new XMLDSigRI()); DigestMethod digestMethod = fac.newDigestMethod(params.getDigestAlgorithm().getXmlId(), null); // Create references List<Reference> references = new ArrayList<Reference>(); addReferences(documentIterator(inside), references, digestMethod, fac); // Create repository signContext.setURIDereferencer(new NameBasedDocumentRepository(inside, fac)); List<XMLObject> objects = new ArrayList<XMLObject>(); Map<String, String> xpathNamespaceMap = new HashMap<String, String>(); xpathNamespaceMap.put("ds", "http://www.w3.org/2000/09/xmldsig#"); String xadesSignedPropertiesId = "xades-" + computeDeterministicId(params); QualifyingPropertiesType qualifyingProperties = createXAdESQualifyingProperties(params, xadesSignedPropertiesId, references, inside); qualifyingProperties.setTarget("#" + signatureId); Node marshallNode = doc.createElement("marshall-node"); JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(xades13ObjectFactory.createQualifyingProperties(qualifyingProperties), marshallNode); Element qualifier = (Element) marshallNode.getFirstChild(); // add XAdES ds:Object List<XMLStructure> xadesObjectContent = new LinkedList<XMLStructure>(); xadesObjectContent.add(new DOMStructure(marshallNode.getFirstChild())); XMLObject xadesObject = fac.newXMLObject(xadesObjectContent, null, null, null); objects.add(xadesObject);//from www . jav a 2s . c o m List<Transform> xadesTranforms = new ArrayList<Transform>(); Transform exclusiveTransform2 = fac.newTransform(CanonicalizationMethod.INCLUSIVE, (TransformParameterSpec) null); xadesTranforms.add(exclusiveTransform2); Reference xadesreference = fac.newReference("#" + xadesSignedPropertiesId, digestMethod, xadesTranforms, XADES_TYPE, null); references.add(xadesreference); /* Signed Info */ SignatureMethod sm = fac.newSignatureMethod( params.getSignatureAlgorithm().getXMLSignatureAlgorithm(params.getDigestAlgorithm()), null); CanonicalizationMethod canonicalizationMethod = fac .newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null); SignedInfo signedInfo = fac.newSignedInfo(canonicalizationMethod, sm, references); /* Creation of signature */ KeyInfoFactory keyFactory = KeyInfoFactory.getInstance("DOM", new XMLDSigRI()); List<Object> infos = new ArrayList<Object>(); List<X509Certificate> certs = new ArrayList<X509Certificate>(); certs.add(params.getSigningCertificate()); if (params.getCertificateChain() != null) { for (X509Certificate c : params.getCertificateChain()) { if (!c.getSubjectX500Principal().equals(params.getSigningCertificate().getSubjectX500Principal())) { certs.add(c); } } } infos.add(keyFactory.newX509Data(certs)); KeyInfo keyInfo = keyFactory.newKeyInfo(infos); DOMXMLSignature signature = (DOMXMLSignature) fac.newXMLSignature(signedInfo, keyInfo, objects, signatureId, signatureValueId); /* Marshall the signature to permit the digest. Need to be done before digesting the references. */ doc.removeChild(doc.getDocumentElement()); signature.marshal(doc, "ds", signContext); signContext.setIdAttributeNS((Element) qualifier.getFirstChild(), null, "Id"); digestReferences(signContext, references); return signature; }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * * @param site/*w w w .j av a2s . co m*/ * @param docLibrary * @return an XML document * @throws ManifoldCFException * @throws ServiceInterruption */ public boolean getChildren(IFileStream fileStream, String site, String guid, boolean dspStsWorks) throws ManifoldCFException, ServiceInterruption { long currentTime; try { if (site.equals("/")) site = ""; // root case if (dspStsWorks) { StsAdapterWS listService = new StsAdapterWS(baseUrl + site, userName, password, configuration, httpClient); StsAdapterSoapStub stub = (StsAdapterSoapStub) listService.getStsAdapterSoapHandler(); String[] vArray = new String[1]; vArray[0] = "1.0"; VersionsHeader myVersion = new VersionsHeader(); myVersion.setVersion(vArray); stub.setHeader("http://schemas.microsoft.com/sharepoint/dsp", "versions", myVersion); RequestHeader reqHeader = new RequestHeader(); reqHeader.setDocument(DocumentType.content); reqHeader.setMethod(MethodType.query); stub.setHeader("http://schemas.microsoft.com/sharepoint/dsp", "request", reqHeader); QueryRequest myRequest = new QueryRequest(); DSQuery sQuery = new DSQuery(); sQuery.setSelect("/list[@id='" + guid + "']"); myRequest.setDsQuery(sQuery); StsAdapterSoap call = stub; ArrayList nodeList = new ArrayList(); QueryResponse resp = call.query(myRequest); org.apache.axis.message.MessageElement[] list = resp.get_any(); if (Logging.connectors.isDebugEnabled()) { Logging.connectors.debug("SharePoint: list xml: '" + list[0].toString() + "'"); } XMLDoc doc = new XMLDoc(list[0].toString()); 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); if (nodeList.size() != 2) { throw new ManifoldCFException(" No results found."); } // Now, extract the files from the response document XMLDoc docs = doc; ArrayList nodeDocs = new ArrayList(); docs.processPath(nodeDocs, "*", null); parent = nodeDocs.get(0); // ns1:dsQueryResponse nodeDocs.clear(); docs.processPath(nodeDocs, "*", parent); Object documents = nodeDocs.get(1); nodeDocs.clear(); docs.processPath(nodeDocs, "*", documents); StringBuilder sb = new StringBuilder(); for (int j = 0; j < nodeDocs.size(); j++) { Object node = nodeDocs.get(j); Logging.connectors.debug(node.toString()); String relPath = docs.getData(docs.getElement(node, "FileRef")); fileStream.addFile(relPath, null); } } else { // New code MCPermissionsWS itemService = new MCPermissionsWS(baseUrl + site, userName, password, configuration, httpClient); com.microsoft.sharepoint.webpartpages.PermissionsSoap itemCall = itemService .getPermissionsSoapHandler(); int startingIndex = 0; int amtToRequest = 10000; while (true) { com.microsoft.sharepoint.webpartpages.GetListItemsResponseGetListItemsResult itemsResult = itemCall .getListItems(guid, Integer.toString(startingIndex), Integer.toString(amtToRequest)); MessageElement[] itemsList = itemsResult.get_any(); if (Logging.connectors.isDebugEnabled()) { Logging.connectors .debug("SharePoint: getListItems xml response: '" + itemsList[0].toString() + "'"); } if (itemsList.length != 1) throw new ManifoldCFException("Bad response - expecting one outer 'GetListItems' node, saw " + Integer.toString(itemsList.length)); MessageElement items = itemsList[0]; if (!items.getElementName().getLocalName().equals("GetListItems")) throw new ManifoldCFException( "Bad response - outer node should have been 'GetListItems' node"); int resultCount = 0; Iterator iter = items.getChildElements(); while (iter.hasNext()) { MessageElement child = (MessageElement) iter.next(); if (child.getElementName().getLocalName().equals("GetListItemsResponse")) { Iterator resultIter = child.getChildElements(); while (resultIter.hasNext()) { MessageElement result = (MessageElement) resultIter.next(); if (result.getElementName().getLocalName().equals("GetListItemsResult")) { resultCount++; String relPath = result.getAttribute("FileRef"); String displayURL = result.getAttribute("ListItemURL"); fileStream.addFile(relPath, displayURL); } } } } if (resultCount < amtToRequest) break; startingIndex += resultCount; } } return true; } 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 documents for site " + site + " guid " + guid + " - 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) { currentTime = System.currentTimeMillis(); 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")) { // Page did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The page at " + baseUrl + site + " did not exist; assuming library deleted"); return false; } else if (httpErrorCode.equals("401")) { // User did not have permissions for this library to get the acls if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: The crawl user did not have access to list documents for " + baseUrl + site + "; skipping documents within"); return false; } else if (httpErrorCode.equals("403")) throw new ManifoldCFException( "Http error " + httpErrorCode + " while reading from " + baseUrl + site + " - check IIS and SharePoint security settings! " + e.getMessage(), e); else 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); } else if (e.getFaultCode() .equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) { org.w3c.dom.Element elem = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorcode")); if (elem != null) { elem.normalize(); String sharepointErrorCode = elem.getFirstChild().getNodeValue().trim(); if (sharepointErrorCode.equals("0x82000006")) { // List did not exist if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("SharePoint: The list " + guid + " in site " + site + " did not exist; assuming library deleted"); return false; } else { if (Logging.connectors.isDebugEnabled()) { org.w3c.dom.Element elem2 = e.lookupFaultDetail(new javax.xml.namespace.QName( "http://schemas.microsoft.com/sharepoint/soap/", "errorstring")); String errorString = ""; if (elem != null) errorString = elem2.getFirstChild().getNodeValue().trim(); Logging.connectors.debug("SharePoint: Getting child documents for the list " + guid + " in site " + site + " failed with unexpected SharePoint error code " + sharepointErrorCode + ": " + errorString + " - Skipping", e); } return false; } } if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: Unknown SharePoint server error getting child documents for site " + site + " guid " + guid + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Unknown SharePoint server error: " + e.getMessage() + " - retrying", e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } 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); } if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: Got an unknown remote exception getting child documents for site " + site + " guid " + guid + " - axis fault = " + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e); throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false); } catch (java.rmi.RemoteException e) { // We expect the axis exception to be thrown, not this generic one! // So, fail hard if we see it. if (Logging.connectors.isDebugEnabled()) Logging.connectors .debug("SharePoint: Got an unexpected remote exception getting child documents for site " + site + " guid " + guid, e); throw new ManifoldCFException("Unexpected remote procedure exception: " + e.getMessage(), e); } }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * Gets a list of field values of the given document * @param fieldNames/*from ww w . j a va2 s . c om*/ * @param site * @param docId * @return set of the field values */ public Map<String, String> getFieldValues(String[] fieldNames, String site, String docLibrary, String docId, boolean dspStsWorks) throws ManifoldCFException, ServiceInterruption { long currentTime; try { HashMap<String, String> result = new HashMap<String, String>(); if (site.compareTo("/") == 0) site = ""; // root case if (dspStsWorks) { StsAdapterWS listService = new StsAdapterWS(baseUrl + site, userName, password, configuration, httpClient); StsAdapterSoapStub stub = (StsAdapterSoapStub) listService.getStsAdapterSoapHandler(); String[] vArray = new String[1]; vArray[0] = "1.0"; VersionsHeader myVersion = new VersionsHeader(); myVersion.setVersion(vArray); stub.setHeader("http://schemas.microsoft.com/sharepoint/dsp", "versions", myVersion); RequestHeader reqHeader = new RequestHeader(); reqHeader.setDocument(DocumentType.content); reqHeader.setMethod(MethodType.query); stub.setHeader("http://schemas.microsoft.com/sharepoint/dsp", "request", reqHeader); QueryRequest myRequest = new QueryRequest(); DSQuery sQuery = new DSQuery(); sQuery.setSelect("/list[@id='" + docLibrary + "']"); sQuery.setResultContent(ResultContentType.dataOnly); myRequest.setDsQuery(sQuery); DspQuery spQuery = new DspQuery(); spQuery.setRowLimit(1); // For the Requested Fields if (fieldNames.length > 0) { Fields spFields = new Fields(); Field[] fieldArray = new Field[0]; ArrayList fields = new ArrayList(); Field spField = new Field(); // spField.setName( "ID" ); // spField.setAlias( "ID" ); // fields.add( spField ); for (String fieldName : fieldNames) { spField = new Field(); spField.setName(fieldName); spField.setAlias(fieldName); fields.add(spField); } spFields.setField((Field[]) fields.toArray(fieldArray)); spQuery.setFields(spFields); } // Of this document DspQueryWhere spWhere = new DspQueryWhere(); org.apache.axis.message.MessageElement criterion = new org.apache.axis.message.MessageElement( (String) null, "Contains"); SOAPElement seFieldRef = criterion.addChildElement("FieldRef"); seFieldRef.addAttribute(SOAPFactory.newInstance().createName("Name"), "FileRef"); SOAPElement seValue = criterion.addChildElement("Value"); seValue.addAttribute(SOAPFactory.newInstance().createName("Type"), "String"); seValue.setValue(docId); org.apache.axis.message.MessageElement[] criteria = { criterion }; spWhere.set_any(criteria); spQuery.setWhere((DspQueryWhere) spWhere); // Set Criteria myRequest.getDsQuery().setQuery(spQuery); StsAdapterSoap call = stub; // Make Request QueryResponse resp = call.query(myRequest); org.apache.axis.message.MessageElement[] list = resp.get_any(); 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)); } } } 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); } }
From source file:com.amalto.workbench.providers.datamodel.util.SchemaItemLabelCreator.java
protected String getLableForElement(Element element) { try {//from w w w . ja v a 2 s . c om if (element.getLocalName().equals("documentation")) {//$NON-NLS-1$ return "Documentation: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (element.getLocalName().equals("appinfo")) {//$NON-NLS-1$ String source = element.getAttribute("source");//$NON-NLS-1$ if (source != null) { if (source.startsWith("X_Label_")) {//$NON-NLS-1$ return Util.iso2lang.get(source.substring(8).toLowerCase()) + " Label: "//$NON-NLS-1$ + element.getChildNodes().item(0).getNodeValue(); } else if (source.equals("X_ForeignKey")) {//$NON-NLS-1$ return "Foreign Key: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_ForeignKeyInfo")) {//$NON-NLS-1$ return "Foreign Key Info: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_SourceSystem")) {//$NON-NLS-1$ return "Source System: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_TargetSystem")) {//$NON-NLS-1$ return "Target System(s): " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.startsWith("X_Description_")) {//$NON-NLS-1$ return Util.iso2lang.get(source.substring(14).toLowerCase()) + " Description: "//$NON-NLS-1$ + element.getChildNodes().item(0).getNodeValue(); } else if (source.equals("X_Write")) {//$NON-NLS-1$ return "Writable By : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Lookup_Field")) {//$NON-NLS-1$ return "Look Field : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Workflow")) {//$NON-NLS-1$ return "Workflow access : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Hide")) {//$NON-NLS-1$ return "No Access to : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.startsWith("X_Facet")) {//$NON-NLS-1$ return source.substring(2, 7) + "_Msg_" + source.substring(8) + ": "//$NON-NLS-1$//$NON-NLS-2$ + element.getChildNodes().item(0).getNodeValue(); } else if (source.startsWith("X_Display_Format_")) {//$NON-NLS-1$ return source + ": " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Schematron")) {//$NON-NLS-1$ String pattern = (String) element.getFirstChild().getUserData("pattern_name");//$NON-NLS-1$ if (pattern == null) { Element el = Util.parse(element.getChildNodes().item(0).getNodeValue()) .getDocumentElement(); if (el.getAttributes().getNamedItem("name") != null)//$NON-NLS-1$ pattern = el.getAttributes().getNamedItem("name").getTextContent();//$NON-NLS-1$ } return "Validation Rule: " + (pattern == null ? "" : pattern);//$NON-NLS-1$//$NON-NLS-2$ } else if (source.equals("X_Retrieve_FKinfos")) {//$NON-NLS-1$ return "Foreign Key resolution: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_FKIntegrity")) {//$NON-NLS-1$ return "Foreign Key integrity: " + element.getChildNodes().item(0).getNodeValue(); //$NON-NLS-1$ } else if (source.equals("X_FKIntegrity_Override")) {//$NON-NLS-1$ return "Foreign Key integrity override: " + element.getChildNodes().item(0).getNodeValue(); //$NON-NLS-1$ } if (source.equals("X_ForeignKey_Filter")) {//$NON-NLS-1$ return "Foreign Key Filter: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else { return source + ": " + Util.nodeToString(element);//$NON-NLS-1$ } } else { return Util.nodeToString(element); } } else { return Util.nodeToString(element); } } catch (Exception e) { log.error(e.getMessage(), e); } return "?? " + element.getClass().getName() + " : " + element.toString();//$NON-NLS-1$//$NON-NLS-2$ }
From source file:com.enonic.vertical.adminweb.MenuHandlerServlet.java
private void moveMenuItemDown(HttpServletRequest request, HttpServletResponse response, HttpSession session, ExtendedMap formItems) throws VerticalAdminException { String menuXML = (String) session.getAttribute("menuxml"); Document doc = XMLTool.domparse(menuXML); String xpath = "/model/menuitems-to-list//menuitem[@key = '" + formItems.getString("key") + "']"; Element movingMenuItemElement = (Element) XMLTool.selectNode(doc, xpath); Element parentElement = (Element) movingMenuItemElement.getParentNode(); Node nextSiblingElement = movingMenuItemElement.getNextSibling(); movingMenuItemElement = (Element) parentElement.removeChild(movingMenuItemElement); doc.importNode(movingMenuItemElement, true); if (nextSiblingElement != null) { // spool forward... for (nextSiblingElement = nextSiblingElement.getNextSibling(); (nextSiblingElement != null && nextSiblingElement .getNodeType() != Node.ELEMENT_NODE); nextSiblingElement = nextSiblingElement .getNextSibling()) { }/*from w w w . j a va 2 s . c o m*/ if (nextSiblingElement != null) { parentElement.insertBefore(movingMenuItemElement, nextSiblingElement); } else { parentElement.appendChild(movingMenuItemElement); } } else { // This is the bottom element, move it to the top parentElement.insertBefore(movingMenuItemElement, parentElement.getFirstChild()); } session.setAttribute("menuxml", XMLTool.documentToString(doc)); MultiValueMap queryParams = new MultiValueMap(); queryParams.put("page", formItems.get("page")); queryParams.put("op", "browse"); queryParams.put("keepxml", "yes"); queryParams.put("highlight", formItems.get("key")); queryParams.put("menukey", formItems.get("menukey")); queryParams.put("parentmi", formItems.get("parentmi")); queryParams.put("subop", "shiftmenuitems"); queryParams.put("move_menuitem", formItems.getString("move_menuitem", "")); queryParams.put("move_from_parent", formItems.getString("move_from_parent", "")); queryParams.put("move_to_parent", formItems.getString("move_to_parent", "")); redirectClientToAdminPath("adminpage", queryParams, request, response); }
From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileBES.java
private DOMXMLSignature createEnveloping(SignatureParameters params, DOMSignContext signContext, org.w3c.dom.Document doc, String signatureId, String signatureValueId, Document inside) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, JAXBException, MarshalException, XMLSignatureException, ParserConfigurationException, IOException { XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM", new XMLDSigRI()); DigestMethod digestMethod = fac.newDigestMethod(params.getDigestAlgorithm().getXmlId(), null); List<XMLObject> objects = new ArrayList<XMLObject>(); List<Reference> references = new ArrayList<Reference>(); byte[] b64data = Base64.encode(IOUtils.toByteArray(inside.openStream())); List<Transform> transforms = new ArrayList<Transform>(); Map<String, String> xpathNamespaceMap = new HashMap<String, String>(); xpathNamespaceMap.put("ds", "http://www.w3.org/2000/09/xmldsig#"); Transform exclusiveTransform = fac.newTransform(CanonicalizationMethod.BASE64, (TransformParameterSpec) null); transforms.add(exclusiveTransform);/*from ww w. ja v a 2 s .co m*/ /* The first reference concern the whole document */ Reference reference = fac.newReference("#signed-data-" + computeDeterministicId(params), digestMethod, transforms, null, "signed-data-ref"); references.add(reference); String xadesSignedPropertiesId = "xades-" + computeDeterministicId(params); QualifyingPropertiesType qualifyingProperties = createXAdESQualifyingProperties(params, xadesSignedPropertiesId, reference, MimeType.PLAIN); qualifyingProperties.setTarget("#" + signatureId); Node marshallNode = doc.createElement("marshall-node"); JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(xades13ObjectFactory.createQualifyingProperties(qualifyingProperties), marshallNode); Element qualifier = (Element) marshallNode.getFirstChild(); // add XAdES ds:Object List<XMLStructure> xadesObjectContent = new LinkedList<XMLStructure>(); xadesObjectContent.add(new DOMStructure(marshallNode.getFirstChild())); XMLObject xadesObject = fac.newXMLObject(xadesObjectContent, null, null, null); objects.add(xadesObject); List<Transform> xadesTranforms = new ArrayList<Transform>(); Transform exclusiveTransform2 = fac.newTransform(CanonicalizationMethod.INCLUSIVE, (TransformParameterSpec) null); xadesTranforms.add(exclusiveTransform2); Reference xadesreference = fac.newReference("#" + xadesSignedPropertiesId, digestMethod, xadesTranforms, XADES_TYPE, null); references.add(xadesreference); /* Signed Info */ SignatureMethod sm = fac.newSignatureMethod( params.getSignatureAlgorithm().getXMLSignatureAlgorithm(params.getDigestAlgorithm()), null); CanonicalizationMethod canonicalizationMethod = fac .newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null); SignedInfo signedInfo = fac.newSignedInfo(canonicalizationMethod, sm, references); /* Creation of signature */ KeyInfoFactory keyFactory = KeyInfoFactory.getInstance("DOM", new XMLDSigRI()); List<Object> infos = new ArrayList<Object>(); List<X509Certificate> certs = new ArrayList<X509Certificate>(); certs.add(params.getSigningCertificate()); if (params.getCertificateChain() != null) { for (X509Certificate c : params.getCertificateChain()) { if (!c.getSubjectX500Principal().equals(params.getSigningCertificate().getSubjectX500Principal())) { certs.add(c); } } } infos.add(keyFactory.newX509Data(certs)); KeyInfo keyInfo = keyFactory.newKeyInfo(infos); DOMXMLSignature signature = (DOMXMLSignature) fac.newXMLSignature(signedInfo, keyInfo, objects, signatureId, signatureValueId); /* Marshall the signature to permit the digest. Need to be done before digesting the references. */ doc.removeChild(doc.getDocumentElement()); signature.marshal(doc, "ds", signContext); Element dsObject = doc.createElementNS(XMLSignature.XMLNS, "Object"); dsObject.setAttribute("Id", "signed-data-" + computeDeterministicId(params)); dsObject.setTextContent(new String(b64data)); doc.getDocumentElement().appendChild(dsObject); signContext.setIdAttributeNS((Element) qualifier.getFirstChild(), null, "Id"); signContext.setIdAttributeNS(dsObject, null, "Id"); digestReferences(signContext, references); return signature; }