-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
##Loading an ODRL Policy
ODRL policy documents can be encoded in XML or JSON. The library supports both. The first step is to instantiate a PolicyFactory. Once the PolicyFactory is created, we can create a PolicyBuilder:
//build new PolicyFactory
PolicyFactory factory = PolicyFactory.newPolicyFactory();
//create new PolicyBuilder
PolicyBuilder builder = factory.newPolicyBuilder();
Now that we have a PolicyBuilder, we can use methods to create a new IOdrlDocument instance. Use the newDocument() method There are several parse methods that support different input formats and streams, including File, InputStream, URL, and Reader that will handle file-based, stread-based, and in-memory ODRL data.
###Creating a new Document (no parsing) Using the PolicyBuilder:
IOdrlDocument document = builder.newDocument();
###Parsing an ODRL document
We'll get into more specifics about IOdrlParser implementations later, but for the time being we can use the ParserFactory to instantiate a default parser for either XML or JSON encoding. Let's assume we're using XML on the file system:
File f = new File("/path/to/odrl/data/policy.xml");
IOdrlParser xmlParser = ParserFactory.newDefaultXmlParser();
IOdrlDocument document = builder.parse(xmlParser, f);
Now you can begin working with the ODRL data.