/** * Constructor defaulting the initial namespace to "everything" * * @param name local name for this repository */ public BasicPolicy(String name) { _pxml = new PolicyXML(); try { if (null != name) _pxml.setLocalName(name); _pxml.setVersion(POLICY_VERSION); _pxml.addNamespace(ContentName.fromNative("/")); } catch (MalformedContentNameStringException e) { } }
public static PolicyXML createPolicyXML(InputStream stream) throws ContentDecodingException { Log.info(Log.FAC_REPO, "Creating policy file"); XMLDecoder decoder = XMLCodecFactory.getDecoder(TextXMLCodec.codecName()); decoder.beginDecoding(stream); PolicyXML pxml = new PolicyXML(); pxml.decode(decoder); Log.fine(Log.FAC_REPO, "Finished pxml decoding"); decoder.endDecoding(); return pxml; }
/** * Applies policy changes * * @param pxml policy data * @return * @throws XMLStreamException */ public void update(PolicyXML pxml, boolean fromNet) throws RepositoryException { Log.info(Log.FAC_REPO, "Updating policy"); if (pxml._version == null) throw new RepositoryException("No version in policy file"); if (!pxml._version.equals(POLICY_VERSION)) { Log.warning(Log.FAC_REPO, "Bad version in policy file: {0}", pxml._version); throw new RepositoryException("Bad version in policy file"); } if (null == pxml._localName) throw new RepositoryException("No local name in policy file"); if (fromNet) { if (!pxml._localName.equals(_pxml.getLocalName())) { Log.warning( Log.FAC_REPO, "Repository local name doesn't match: request = {0}", pxml._localName); throw new RepositoryException("Repository local name doesn't match policy file"); } } else { try { setLocalName(pxml._localName); } catch (MalformedContentNameStringException e) { throw new RepositoryException(e.getMessage()); } } if (null == pxml._globalPrefix) throw new RepositoryException("No globalPrefix in policy file"); if (fromNet) { if (!pxml.getGlobalPrefix().equals(_pxml.getGlobalPrefix())) { Log.warning("Repository globalPrefix doesn't match: request = {0}", pxml._globalPrefix); throw new RepositoryException("Repository global prefix doesn't match policy file"); } } else { _pxml.setGlobalPrefixOnly(pxml._globalPrefix); } _pxml.setNamespace(pxml.getNamespace()); if (null != pxml.getNamespace()) { String message = ""; for (ContentName name : pxml.getNamespace()) { message += name.toString() + ':'; } Log.info(Log.FAC_REPO, "Policy has been updated. New namespace is: " + message); } }
/** * Constructor allowing an initial namespace to be set * * @param name local name for this repository * @param namespace the initial namespace */ public BasicPolicy(String name, ArrayList<ContentName> namespace) { this(name); if (null != namespace) { _pxml.setNamespace(namespace); } }
public void setLocalName(String localName) throws MalformedContentNameStringException { if (null == _pxml.getLocalName()) { _pxml.setLocalName(localName); } }
/** * Gets the local name currently used by this repository * * @return the local name as a slash separated String */ public String getLocalName() { return _pxml.getLocalName(); }
/** * Gets the global prefix currently in use for this repository * * @return the global prefix as a ContentName */ public ContentName getGlobalPrefix() { return _pxml.getGlobalPrefix(); }
/** * Sets the global prefix for this policy interpreter. After this call any policy file containing * a different global prefix will be rejected * * @param globalPrefix the global prefix as a slash separated String */ public void setGlobalPrefix(String globalPrefix) throws MalformedContentNameStringException { _pxml.setGlobalPrefix(globalPrefix); }
/** * Gets the policy path for this repository * * @return the policy path as a ContentName */ public ContentName getPolicyName() { return getPolicyName(_pxml.getGlobalPrefix()); }
public void setNamespace(ArrayList<ContentName> namespace) { _pxml.setNamespace(namespace); }
public ArrayList<ContentName> getNamespace() { return _pxml.getNamespace(); }