@Test public void testFromXacmlString() { String testTitle = "testFromXacmlString: generated a RequestPolicy from a XML privacy policy"; LOG.info(testTitle); RequestPolicy retrievedPrivacyPolicy = null; RequestPolicy retrievedPrivacyPolicyWithoutRequestor = null; RequestPolicy retrievedPrivacyPolicyWithoutRequestorString = null; try { retrievedPrivacyPolicy = PrivacyPolicyUtils.fromXacmlString(RequestPolicyUtils.toXmlString(privacyPolicy)); retrievedPrivacyPolicyWithoutRequestor = PrivacyPolicyUtils.fromXacmlString(RequestPolicyUtils.toXmlString(privacyPolicyWithoutRequestor)); retrievedPrivacyPolicyWithoutRequestorString = PrivacyPolicyUtils.fromXacmlString(privacyPolicyWithoutRequestorString); } catch (Exception e) { LOG.error("[Test Exception] "+testTitle, e); fail("Error "+e.getMessage()+": "+testTitle); } assertNotNull("Privacy policy generated should not be null", retrievedPrivacyPolicy); assertNotNull("Privacy policy original should not be null", privacyPolicy); assertEquals("Privacy policy generated (xml) not equal to the original policy", RequestPolicyUtils.toXmlString(privacyPolicy), RequestPolicyUtils.toXmlString(retrievedPrivacyPolicy)); assertEquals("Privacy policy generated not same class as the original policy", privacyPolicy.getClass(), retrievedPrivacyPolicy.getClass()); assertTrue("Privacy policy generated and the original policy: not the same requestor", RequestorUtils.equal(privacyPolicy.getRequestor(), retrievedPrivacyPolicy.getRequestor())); assertEquals("Privacy policy generated and the original policy: not the same request items size", privacyPolicy.getRequestItems().size(), retrievedPrivacyPolicy.getRequestItems().size()); for(int i=0; i<retrievedPrivacyPolicy.getRequestItems().size(); i++) { assertTrue("Privacy policy generated and the original policy: not the same request item "+i, RequestItemUtils.equal(privacyPolicy.getRequestItems().get(i), retrievedPrivacyPolicy.getRequestItems().get(i))); } assertTrue("Privacy policy generated and the original policy: not the same request items", RequestItemUtils.equal(privacyPolicy.getRequestItems(), retrievedPrivacyPolicy.getRequestItems())); assertTrue("Privacy policy generated not equal to the original policy", RequestPolicyUtils.equal(privacyPolicy, retrievedPrivacyPolicy)); assertNotNull("Privacy policy generated should not be null (2)", retrievedPrivacyPolicyWithoutRequestor); assertNotNull("Privacy policy original should not be null (2)", privacyPolicyWithoutRequestor); assertEquals("Privacy policy generated (xml) not equal to the original policy (2)", RequestPolicyUtils.toXmlString(privacyPolicyWithoutRequestor), RequestPolicyUtils.toXmlString(retrievedPrivacyPolicyWithoutRequestor)); assertEquals("Privacy policy generated not same class as the original policy (2)", privacyPolicyWithoutRequestor.getClass(), retrievedPrivacyPolicyWithoutRequestor.getClass()); assertNull("Privacy policy generated should have a null requestor (2)", retrievedPrivacyPolicyWithoutRequestor.getRequestor()); assertTrue("Privacy policy generated and the original policy: not the same requestor (2)", RequestorUtils.equal(privacyPolicyWithoutRequestor.getRequestor(), retrievedPrivacyPolicyWithoutRequestor.getRequestor())); assertEquals("Privacy policy generated and the original policy: not the same request items size (2)", privacyPolicyWithoutRequestor.getRequestItems().size(), retrievedPrivacyPolicyWithoutRequestor.getRequestItems().size()); for(int i=0; i<retrievedPrivacyPolicy.getRequestItems().size(); i++) { assertTrue("Privacy policy generated and the original policy: not the same request item (2)"+i, RequestItemUtils.equal(privacyPolicyWithoutRequestor.getRequestItems().get(i), retrievedPrivacyPolicyWithoutRequestor.getRequestItems().get(i))); } assertTrue("Privacy policy generated and the original policy: not the same request items (2)", RequestItemUtils.equal(privacyPolicyWithoutRequestor.getRequestItems(), retrievedPrivacyPolicyWithoutRequestor.getRequestItems())); assertTrue("Privacy policy generated not equal to the original policy (2)", RequestPolicyUtils.equal(privacyPolicyWithoutRequestor, retrievedPrivacyPolicyWithoutRequestor)); assertNotNull("Privacy policy generated should not be null (3)", retrievedPrivacyPolicyWithoutRequestorString); assertNotNull("Privacy policy original should not be null (3)", privacyPolicyWithoutRequestorString); LOG.info("**** Original XML privacy policy ****"); LOG.info(privacyPolicyWithoutRequestorString); LOG.info("**** Generated RequestPolicy ****"); LOG.info(RequestPolicyUtils.toXmlString(retrievedPrivacyPolicyWithoutRequestorString)); assertNull("Privacy policy generated should have a null requestor (3)", retrievedPrivacyPolicyWithoutRequestorString.getRequestor()); }
public static RequestPolicy fromXacmlString(String xmlPrivacyPolicy) { if (null == xmlPrivacyPolicy || xmlPrivacyPolicy.equals("")) { return null; } String[] encoding = {"UTF-8", "ISO-8859-1"}; if (!xmlPrivacyPolicy.startsWith("<?xml")) { xmlPrivacyPolicy = "<?xml version=\"1.0\" encoding=\""+encoding[0]+"\"?>\n"+xmlPrivacyPolicy; } if (xmlPrivacyPolicy.endsWith("?>")) { return null; } Document docPrivacyPolicy = null; try { DocumentBuilder xmlDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); for(int i=0; i<encoding.length; i++) { try { if (0 == i) { docPrivacyPolicy = xmlDocumentBuilder.parse(new ByteArrayInputStream(xmlPrivacyPolicy.getBytes())); if (null != docPrivacyPolicy) { break; } } docPrivacyPolicy = xmlDocumentBuilder.parse(new ByteArrayInputStream(xmlPrivacyPolicy.getBytes(encoding[i]))); if (null != docPrivacyPolicy) { break; } } catch (UnsupportedEncodingException e) { } } } catch (ParserConfigurationException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } catch (SAXException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } catch (IOException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } RequestPolicy result = fromXmlDocument(docPrivacyPolicy); return result; }
PrivacyPolicyUtils { public static RequestPolicy fromXacmlString(String xmlPrivacyPolicy) { if (null == xmlPrivacyPolicy || xmlPrivacyPolicy.equals("")) { return null; } String[] encoding = {"UTF-8", "ISO-8859-1"}; if (!xmlPrivacyPolicy.startsWith("<?xml")) { xmlPrivacyPolicy = "<?xml version=\"1.0\" encoding=\""+encoding[0]+"\"?>\n"+xmlPrivacyPolicy; } if (xmlPrivacyPolicy.endsWith("?>")) { return null; } Document docPrivacyPolicy = null; try { DocumentBuilder xmlDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); for(int i=0; i<encoding.length; i++) { try { if (0 == i) { docPrivacyPolicy = xmlDocumentBuilder.parse(new ByteArrayInputStream(xmlPrivacyPolicy.getBytes())); if (null != docPrivacyPolicy) { break; } } docPrivacyPolicy = xmlDocumentBuilder.parse(new ByteArrayInputStream(xmlPrivacyPolicy.getBytes(encoding[i]))); if (null != docPrivacyPolicy) { break; } } catch (UnsupportedEncodingException e) { } } } catch (ParserConfigurationException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } catch (SAXException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } catch (IOException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } RequestPolicy result = fromXmlDocument(docPrivacyPolicy); return result; } }
PrivacyPolicyUtils { public static RequestPolicy fromXacmlString(String xmlPrivacyPolicy) { if (null == xmlPrivacyPolicy || xmlPrivacyPolicy.equals("")) { return null; } String[] encoding = {"UTF-8", "ISO-8859-1"}; if (!xmlPrivacyPolicy.startsWith("<?xml")) { xmlPrivacyPolicy = "<?xml version=\"1.0\" encoding=\""+encoding[0]+"\"?>\n"+xmlPrivacyPolicy; } if (xmlPrivacyPolicy.endsWith("?>")) { return null; } Document docPrivacyPolicy = null; try { DocumentBuilder xmlDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); for(int i=0; i<encoding.length; i++) { try { if (0 == i) { docPrivacyPolicy = xmlDocumentBuilder.parse(new ByteArrayInputStream(xmlPrivacyPolicy.getBytes())); if (null != docPrivacyPolicy) { break; } } docPrivacyPolicy = xmlDocumentBuilder.parse(new ByteArrayInputStream(xmlPrivacyPolicy.getBytes(encoding[i]))); if (null != docPrivacyPolicy) { break; } } catch (UnsupportedEncodingException e) { } } } catch (ParserConfigurationException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } catch (SAXException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } catch (IOException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } RequestPolicy result = fromXmlDocument(docPrivacyPolicy); return result; }  }
PrivacyPolicyUtils { public static RequestPolicy fromXacmlString(String xmlPrivacyPolicy) { if (null == xmlPrivacyPolicy || xmlPrivacyPolicy.equals("")) { return null; } String[] encoding = {"UTF-8", "ISO-8859-1"}; if (!xmlPrivacyPolicy.startsWith("<?xml")) { xmlPrivacyPolicy = "<?xml version=\"1.0\" encoding=\""+encoding[0]+"\"?>\n"+xmlPrivacyPolicy; } if (xmlPrivacyPolicy.endsWith("?>")) { return null; } Document docPrivacyPolicy = null; try { DocumentBuilder xmlDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); for(int i=0; i<encoding.length; i++) { try { if (0 == i) { docPrivacyPolicy = xmlDocumentBuilder.parse(new ByteArrayInputStream(xmlPrivacyPolicy.getBytes())); if (null != docPrivacyPolicy) { break; } } docPrivacyPolicy = xmlDocumentBuilder.parse(new ByteArrayInputStream(xmlPrivacyPolicy.getBytes(encoding[i]))); if (null != docPrivacyPolicy) { break; } } catch (UnsupportedEncodingException e) { } } } catch (ParserConfigurationException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } catch (SAXException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } catch (IOException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } RequestPolicy result = fromXmlDocument(docPrivacyPolicy); return result; }  static RequestPolicy inferPrivacyPolicy(PrivacyPolicyTypeConstants privacyPolicyType, Map configuration); static RequestPolicy inferCisPrivacyPolicy(
			PrivacyPolicyBehaviourConstants globalBehaviour,
			MembershipCrit membershipCriteria,
			Map<String, String> configuration); static RequestPolicy inferCisPrivacyPolicy(
			PrivacyPolicyBehaviourConstants globalBehaviour,
			MembershipCrit membershipCriteria); static RequestPolicy infer3pServicePrivacyPolicy(
			Map<String, String> configuration); static List<String> getDataTypes(RequestPolicy privacyPolicy); static List<String> getDataTypes(DataIdentifierScheme schemeFilter, RequestPolicy privacyPolicy); static String toXacmlString(RequestPolicy privacyPolicy); @Deprecated static String toXmlString(RequestPolicy privacyPolicy); static RequestPolicy fromXacmlString(String xmlPrivacyPolicy); }
PrivacyPolicyUtils { public static RequestPolicy fromXacmlString(String xmlPrivacyPolicy) { if (null == xmlPrivacyPolicy || xmlPrivacyPolicy.equals("")) { return null; } String[] encoding = {"UTF-8", "ISO-8859-1"}; if (!xmlPrivacyPolicy.startsWith("<?xml")) { xmlPrivacyPolicy = "<?xml version=\"1.0\" encoding=\""+encoding[0]+"\"?>\n"+xmlPrivacyPolicy; } if (xmlPrivacyPolicy.endsWith("?>")) { return null; } Document docPrivacyPolicy = null; try { DocumentBuilder xmlDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); for(int i=0; i<encoding.length; i++) { try { if (0 == i) { docPrivacyPolicy = xmlDocumentBuilder.parse(new ByteArrayInputStream(xmlPrivacyPolicy.getBytes())); if (null != docPrivacyPolicy) { break; } } docPrivacyPolicy = xmlDocumentBuilder.parse(new ByteArrayInputStream(xmlPrivacyPolicy.getBytes(encoding[i]))); if (null != docPrivacyPolicy) { break; } } catch (UnsupportedEncodingException e) { } } } catch (ParserConfigurationException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } catch (SAXException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } catch (IOException e) { LOG.error("Error during transformation of the string to an XML document: "+e.getMessage(), e); } RequestPolicy result = fromXmlDocument(docPrivacyPolicy); return result; }  static RequestPolicy inferPrivacyPolicy(PrivacyPolicyTypeConstants privacyPolicyType, Map configuration); static RequestPolicy inferCisPrivacyPolicy(
			PrivacyPolicyBehaviourConstants globalBehaviour,
			MembershipCrit membershipCriteria,
			Map<String, String> configuration); static RequestPolicy inferCisPrivacyPolicy(
			PrivacyPolicyBehaviourConstants globalBehaviour,
			MembershipCrit membershipCriteria); static RequestPolicy infer3pServicePrivacyPolicy(
			Map<String, String> configuration); static List<String> getDataTypes(RequestPolicy privacyPolicy); static List<String> getDataTypes(DataIdentifierScheme schemeFilter, RequestPolicy privacyPolicy); static String toXacmlString(RequestPolicy privacyPolicy); @Deprecated static String toXmlString(RequestPolicy privacyPolicy); static RequestPolicy fromXacmlString(String xmlPrivacyPolicy);  }