A Java interface to Legislation.gov.uk.
JavaDoc is available at http://phil.uu.nl/~trompper/legislation-gov-uk-latest-javadoc/
Download the latest JAR or grab from Maven:
<dependencies>
<dependency>
<groupId>org.leibnizcenter</groupId>
<artifactId>legislation-gov-uk</artifactId>
<version>1.5.0</version>
</dependency>
</dependencies>
or Gradle:
compile 'org.leibnizcenter:legislation-gov-uk:1.5.0'
To parse a feed and get the table of contents for the first entry:
import org.leibnizcenter.uk.legislation.uri.TopLevelUri;
import org.w3._2005.atom.Entry;
import org.xml.sax.SAXException;
import uk.gov.legislation.namespaces.legislation.Contents;
import uk.gov.legislation.namespaces.legislation.Legislation;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
public class Sample {
public static void main(String[] args) {
// Get search feed
Feed feed = ApiInterface.getSearchFeed(
new SearchRequestBuilder().setStartNumber("4").setEndYear("2015").build()
);
for (Entry e : feed.getEntries()) {
System.out.println("Title: " + e.getTitle());
}
// Get single entry and ToC
TopLevelUri uri = new TopLevelUri("http://www.legislation.gov.uk/anaw/2015/4");
Entry e = ApiInterface.getSingleEntryFromFeed(uri);
for (Legislation tableOfContentsDocument : e.getAllTableOfContents()) {
Contents contents = tableOfContentsDocument.getContents();
System.out.println("Title: " + contents.getContentsTitle());
for (TableOfContentsElement tocElement : contents.getToCChildren()) {
System.out.println("> " + tocElement);
}
}
}
}
For more information about the API, see http://www.legislation.gov.uk/developer or a report about legislation.gov.uk.
Inquiries go to [email protected].