/** * Look up database accessibility information for specified unit. * * @param u The unit which should get accessibility info assigned to it. * @param form The AccessibilityDatabaseFilterForm to fetch the language id to use. */ public void assignAccessibilityDatabaseInfo(Unit u, AccessibilityDatabaseFilterForm form) { if (this.useAccessibilityDatabaseIntegration) { // First find out the accessibility database id if (assignAccessibilityDatabaseId(u)) { int languageId = Integer.parseInt(form.getLanguageId()); String url = accessibilityDatabaseIntegrationGetInfoUrl + languageId + "&facilityId=" + u.getAccessibilityDatabaseId(); String content = httpFetcher.fetchUrl(url); // Now read the content and get accessibility info Document doc = DocumentHelper.getDocumentFromString(content); doc.normalize(); // Get business object (there is only one) NodeList businessObjectNodeList = doc.getElementsByTagName("businessobject"); AccessibilityObject businessObject = null; for (int i = 0; i < businessObjectNodeList.getLength(); i++) { businessObject = AccessibilityObject.createAccessibilityObjectFromNode(businessObjectNodeList.item(i)); } // Get sub objects NodeList subObjectNodeList = doc.getElementsByTagName("subobject"); ArrayList<AccessibilityObject> subObjects = new ArrayList<AccessibilityObject>(); for (int i = 0; i < subObjectNodeList.getLength(); i++) { AccessibilityObject subObject = AccessibilityObject.createAccessibilityObjectFromNode(subObjectNodeList.item(i)); subObjects.add(subObject); } AccessibilityInformation accessibilityInformation = new AccessibilityInformation(businessObject, subObjects); u.setAccessibilityInformation(accessibilityInformation); } } }
/** * Find out and assign the accessibility database id. * * @param u The Unit to assign accessibility information to. * @return true if succeeded, false otherwise */ public boolean assignAccessibilityDatabaseId(Unit u) { boolean result = true; if (this.useAccessibilityDatabaseIntegration) { // Get accessibility Id String url = accessibilityDatabaseIntegrationGetIdUrl + u.getHsaIdentity(); String content = httpFetcher.fetchUrl(url); // Now read the content into a XML document and get accessibility id Document doc = DocumentHelper.getDocumentFromString(content); try { NodeList ids = doc.getElementsByTagName("string"); for (int i = 0; i < ids.getLength(); i++) { String textContent = ids.item(i).getTextContent(); int accessabilityId = Integer.parseInt(textContent); u.setAccessibilityDatabaseId(accessabilityId); } } catch (NumberFormatException e) { logger.error("We did not get a valid accessability database id. Skip it."); result = false; } } return result; }