All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.w3._2005.atom.Entry Maven / Gradle / Ivy

The newest version!
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
// See http://java.sun.com/xml/jaxb 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2015.08.07 at 06:17:52 PM CEST 
//


package org.w3._2005.atom;


import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import org.jsoup.nodes.Document;
import org.leibnizcenter.uk.legislation.ApiInterface;
import org.leibnizcenter.uk.legislation.uri.TopLevelUri;
import org.xml.sax.SAXException;
import uk.gov.legislation.namespaces.legislation.Legislation;
import uk.gov.legislation.namespaces.metadata.*;
import uk.gov.legislation.namespaces.metadata.Number;

import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.*;


/**
 * 

Java class for anonymous complex type. *

*

The following schema fragment specifies the expected content contained within this class. *

*

 * <complexType>
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <choice maxOccurs="unbounded" minOccurs="0">
 *         <element ref="{http://www.w3.org/2005/Atom}author"/>
 *         <element ref="{http://www.w3.org/2005/Atom}category"/>
 *         <element ref="{http://www.w3.org/2005/Atom}content"/>
 *         <element ref="{http://www.w3.org/2005/Atom}contributor"/>
 *         <element ref="{http://www.w3.org/2005/Atom}id"/>
 *         <element ref="{http://www.w3.org/2005/Atom}link"/>
 *         <element ref="{http://www.w3.org/2005/Atom}published"/>
 *         <element ref="{http://www.w3.org/2005/Atom}rights"/>
 *         <element ref="{http://www.w3.org/2005/Atom}source"/>
 *         <element ref="{http://www.w3.org/2005/Atom}summary"/>
 *         <element ref="{http://www.w3.org/2005/Atom}title"/>
 *         <element ref="{http://www.w3.org/2005/Atom}updated"/>
 *       </choice>
 *       <attGroup ref="{http://www.w3.org/2005/Atom}atomCommonAttributes"/>
 *     </restriction>
 *   </complexContent>
 * </complexType>
 * 
*/ @XmlAccessorType(XmlAccessType.FIELD) //@XmlType(name = "", propOrder = { // "authorsAndCategoriesAndContents" //}) @XmlRootElement(name = "entry") public class Entry { // Ignoring this generated stuff for our homegrown solution // // @XmlElementRefs({ // @XmlElementRef(name = "title", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class, required = false), // @XmlElementRef(name = "updated", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class, required = false), // @XmlElementRef(name = "source", namespace = "http://www.w3.org/2005/Atom", type = Source.class, required = false), // @XmlElementRef(name = "author", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class, required = false), // @XmlElementRef(name = "summary", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class, required = false), // @XmlElementRef(name = "contributor", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class, required = false), // @XmlElementRef(name = "link", namespace = "http://www.w3.org/2005/Atom", type = Link.class, required = false), // @XmlElementRef(name = "content", namespace = "http://www.w3.org/2005/Atom", type = Content.class, required = false), // @XmlElementRef(name = "rights", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class, required = false), // @XmlElementRef(name = "category", namespace = "http://www.w3.org/2005/Atom", type = Category.class, required = false), // @XmlElementRef(name = "id", namespace = "http://www.w3.org/2005/Atom", type = Id.class, required = false), // @XmlElementRef(name = "published", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class, required = false) // }) // protected List authorsAndCategoriesAndContents; /** * Collection of Link types */ @XmlElement(required = true, name = "link") public final Collection links = new HashSet<>(); // Start custom definition (overriding generated codes) @XmlElement(required = true) public String id; /** * Document title */ @XmlElement(required = true) public String title; /** * DateTime on which the document was last updated (i.e., not necessarily through a formal amendment) */ @XmlElement(required = true) public String updated; @XmlElement(required = true) public String summary; @XmlElement(required = true) public String published; @XmlElement(required = true, namespace = "http://www.legislation.gov.uk/namespaces/metadata", name = "DocumentMainType") public DocumentMainType documentMainType; /** * Year as it appears in the representation URI */ @XmlElement(required = true, namespace = "http://www.legislation.gov.uk/namespaces/metadata", name = "Year") public Year year; /** * Number as it appears in the representation URI */ @XmlElement(required = true, namespace = "http://www.legislation.gov.uk/namespaces/metadata", name = "Number") public uk.gov.legislation.namespaces.metadata.Number number; /** * Date on which this law was created. Maybe always the same date as {@code published}? */ @XmlElement(required = true, namespace = "http://www.legislation.gov.uk/namespaces/metadata", name = "CreationDate") public uk.gov.legislation.namespaces.metadata.CreationDate creationDate; /** * ISBN number for this law */ @XmlElement(required = true, namespace = "http://www.legislation.gov.uk/namespaces/metadata", name = "isbn") public ISBN isbn; // End custom definition (overriding generated codes) @XmlAttribute(name = "base", namespace = "http://www.w3.org/XML/1998/namespace") @XmlSchemaType(name = "anyURI") protected String base; @XmlAttribute(name = "lang", namespace = "http://www.w3.org/XML/1998/namespace") @XmlJavaTypeAdapter(CollapsedStringAdapter.class) @XmlSchemaType(name = "language") protected String lang; // Ignore generated code: // // /** // * Gets the value of the authorsAndCategoriesAndContents property. // *

// *

// * This accessor method returns a reference to the live list, // * not a snapshot. Therefore any modification you make to the // * returned list will be present inside the JAXB object. // * This is why there is not a set method for the authorsAndCategoriesAndContents property. // *

// *

// * For example, to add a new item, do as follows: // *

//     *    getAuthorsAndCategoriesAndContents().add(newItem);
//     * 
// *

// *

// *

// * Objects of the following type(s) are allowed in the list // * {@link JAXBElement }{@code <}{@link AtomTextConstruct }{@code >} // * {@link JAXBElement }{@code <}{@link AtomPersonConstruct }{@code >} // * {@link Source } // * {@link JAXBElement }{@code <}{@link AtomDateConstruct }{@code >} // * {@link JAXBElement }{@code <}{@link AtomTextConstruct }{@code >} // * {@link JAXBElement }{@code <}{@link AtomPersonConstruct }{@code >} // * {@link Link } // * {@link Content } // * {@link JAXBElement }{@code <}{@link AtomTextConstruct }{@code >} // * {@link Category } // * {@link Id } // * {@link JAXBElement }{@code <}{@link AtomDateConstruct }{@code >} // */ // public List getAuthorsAndCategoriesAndContents() { // if (authorsAndCategoriesAndContents == null) { // authorsAndCategoriesAndContents = new ArrayList(); // } // return this.authorsAndCategoriesAndContents; // } /** * Gets the value of the base property. * * @return possible object is * {@link String } */ public String getBase() { return base; } /** * Sets the value of the base property. * * @param value allowed object is * {@link String } */ public void setBase(String value) { this.base = value; } /** * Gets the value of the lang property. * * @return possible object is * {@link String } */ public String getLang() { return lang; } /** * Sets the value of the lang property. * * @param value allowed object is * {@link String } */ public void setLang(String value) { this.lang = value; } public List getTableOfContentsLinks() { return getLinksForRel("http://purl.org/dc/terms/tableOfContents"); } /** * Returns a map from language codes to ToC {@link Link} objects. * * @return map from language codes to ToC links */ public Map getTableOfContentsLinksMap() { Map links = new HashMap<>(getTableOfContentsLinks().size()); for (Link l : getLinksForRel("http://purl.org/dc/terms/tableOfContents")) { String key = l.getNormalizedHrefLang(); Preconditions.checkState(links.get(key) == null); links.put(key, l); } return links; } /** * @see #getAlternateHtmLinks() */ @Deprecated public List getHtmlSnippets() { return new ArrayList<>(getAlternateHtmLinks()); } public Map getLegislationByLanguage() throws IOException, JAXBException { Map ls = new HashMap<>(getLinks().size()); for (Link l : getAlternateXmlLinks()) { Legislation leg = ApiInterface.parseLegislationDoc(l.getHref()); String key = l.getNormalizedHrefLang(); Preconditions.checkState(ls.get(key) == null); ls.put(key, leg); } return ls; } public Map getHtmlSnippetsLinksByLanguage() { Map links = new HashMap<>(getLinks().size()); for (Link l : getLinks()) { if ("alternate".equals(l.getRel()) && "application/xhtml+xml".equals(l.getType())) { String key = l.getNormalizedHrefLang(); Preconditions.checkState(links.get(key) == null); links.put(key, l); } } return links; } /** * @return Link to English HTML, null if not found */ public Link getEnglishHtmlSnippet() { for (Link l : getLinks()) { if ("alternate".equals(l.getRel()) && "application/xhtml+xml".equals(l.getType()) && "en".equals(l.getNormalizedHrefLang())) { return l; } } return null; } /** * @return Link to Welsh HTML, null if not found */ public Link getWelshHtmlSnippet() { for (Link l : getLinks()) { if ("alternate".equals(l.getRel()) && "application/xhtml+xml".equals(l.getType()) && "cy".equals(l.getHreflang()) ) { return l; } } return null; } /** * @return Links with the "alternate" attribute */ public List getAlternateLinks() { return getLinksForRel("alternate"); } /** * @param rel "rel" attribute to query links for. (E.g.; @code{}) * @return List of links which have the given "rel" attribute */ public List getLinksForRel(String rel) { List links = new ArrayList<>(getLinks().size()); for (Link l : getLinks()) { if (rel.equals(l.getRel())) { links.add(l); } } return links; } /** * @return Legislation that represents the English table of contents (as opposed to Welsh) * @throws ParserConfigurationException * @throws JAXBException * @throws SAXException * @throws IOException */ public Legislation getEnglishTableOfContents() throws ParserConfigurationException, JAXBException, SAXException, IOException { for (Link link : getTableOfContentsLinks()) { String lang = link.getNormalizedHrefLang(); //Default language is English if ("en".equals(lang)) { return ApiInterface.parseLegislationDoc(link.getHref() + "/data.xml"); } } return null; } /** * @return Legislation that represents the Welsh table of contents (as opposed to English) * @throws ParserConfigurationException * @throws JAXBException * @throws SAXException * @throws IOException */ public Legislation getWelshTableOfContents() throws ParserConfigurationException, JAXBException, SAXException, IOException { for (Link link : getTableOfContentsLinks()) { if ("cy".equals(link.getHreflang())) { return ApiInterface.parseLegislationDoc(link.getHref() + "/data.xml"); } } return null; } /** * See {@link #getTableOfContentsByLanguage()} * * @return List of ToC documents */ @Deprecated public List getAllTableOfContents() throws ParserConfigurationException, JAXBException, SAXException, IOException { List contents = new ArrayList<>(getTableOfContentsLinks().size()); for (Link l : getTableOfContentsLinks()) { Legislation leg = ApiInterface.parseLegislationDoc(l.getHref() + "/data.xml"); contents.add(leg); } return contents; } /** * Returns a map with language codes for keys and {@link Legislation} objects (representing ToC documents) as values * * @return Map from language codes to ToC documents */ public Map getTableOfContentsByLanguage() throws ParserConfigurationException, JAXBException, SAXException, IOException { Map contents = new HashMap<>(getTableOfContentsLinks().size()); for (Link l : getTableOfContentsLinks()) { Legislation leg = ApiInterface.parseLegislationDoc(l.getHref() + "/data.xml"); putButThrowErrorWhenAlreadyFilled(contents, l.getNormalizedHrefLang(), leg); } return contents; } private void putButThrowErrorWhenAlreadyFilled(Map contents, String key, Legislation leg) { if (contents.get(key) != null) { throw new IllegalStateException("Map should not have a value yet for '" + key + "'"); } contents.put(key, leg); } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public Collection getLinks() { return links; } public String getUpdated() { return updated; } public void setUpdated(String updated) { this.updated = updated; } public String getSummary() { return summary; } public void setSummary(String summary) { this.summary = summary; } public String getPublished() { return published; } public void setPublished(String published) { this.published = published; } public DocumentMainType getDocumentMainType() { return documentMainType; } public void setDocumentMainType(DocumentMainType documentMainType) { this.documentMainType = documentMainType; } public Year getYear() { return year; } public void setYear(Year year) { this.year = year; } public uk.gov.legislation.namespaces.metadata.Number getNumber() { return number; } public void setNumber(Number number) { this.number = number; } public CreationDate getCreationDate() { return creationDate; } public void setCreationDate(CreationDate creationDate) { this.creationDate = creationDate; } public ISBN getIsbn() { return isbn; } public void setIsbn(ISBN isbn) { this.isbn = isbn; } /** * @return Representation URI for this law */ public TopLevelUri getUriObject() { String backupLink = null; for (Link link : links) { backupLink = link.href; if ("self".equals(link.rel)) { break; } } return new TopLevelUri(backupLink, getYear().asInt(), getNumber().asInt()); } /** * Different from {@link #getAlternateHtmlLinks()} in that this one provides {@code data.html} instead of {@code data.htm} */ public Collection getAlternateHtmLinks() { return getLinksForPredicate(new Predicate() { @Override public boolean apply(Link l) { return ("alternate".equals(l.getRel()) && "application/xhtml+xml".equals(l.getType())); } }); } /** * Different from {@link #getAlternateHtmLinks()} in that this one provides {@code data.htm} instead of {@code data.html} */ public Collection getAlternateHtmlLinks() { Predicate htmLinks = new Predicate() { @Override public boolean apply(Link l) { return ("alternate".equals(l.getRel()) && "application/xhtml+xml".equals(l.getType())); } }; return Collections2.transform(getLinksForPredicate(htmLinks), new Function() { @Override public Link apply(Link link) { Preconditions.checkState(link.getHref().endsWith("htm")); Link l = link.copy(); l.setHref(l.getHref() + "l"); return l; } }); } public Map getLanguageToHtmlMap() throws IOException { Collection links = getAlternateHtmlLinks(); Map m = new HashMap<>(links.size()); for (Link l : links) { String key = l.getNormalizedHrefLang(); Preconditions.checkState(!m.containsKey(key)); Document doc = ApiInterface.parseHtml(l.getHref()); m.put(key, doc); } return m; } public Collection getAlternateXmlLinks() { return getLinksForPredicate(new Predicate() { @Override public boolean apply(Link l) { return "alternate".equals(l.getRel()) && "application/xml".equals(l.getType()); } }); } public Collection getLinksForPredicate(Predicate p) { return Collections2.filter(getLinks(), p); } public static class TagWithValueAttribute { @XmlAttribute(name = "Value") public String value; public TagWithValueAttribute() { } public TagWithValueAttribute(String c) { value = c; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } @Override public String toString() { return value; } } }