View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  
23  package org.opencastproject.mediapackage;
24  
25  import org.opencastproject.util.Checksum;
26  import org.opencastproject.util.MimeType;
27  import org.opencastproject.util.MimeTypes;
28  
29  import java.net.URI;
30  
31  import javax.xml.bind.annotation.XmlAccessType;
32  import javax.xml.bind.annotation.XmlAccessorType;
33  import javax.xml.bind.annotation.XmlRootElement;
34  import javax.xml.bind.annotation.XmlType;
35  import javax.xml.bind.annotation.adapters.XmlAdapter;
36  
37  /**
38   * This is a basic implementation for handling simple catalogs of metadata.
39   */
40  @XmlRootElement(name = "catalog", namespace = "http://mediapackage.opencastproject.org")
41  @XmlType(name = "catalog", namespace = "http://mediapackage.opencastproject.org")
42  @XmlAccessorType(XmlAccessType.NONE)
43  public class CatalogImpl extends AbstractMediaPackageElement implements Catalog {
44  
45    /** Serial version UID */
46    private static final long serialVersionUID = -908525367616L;
47  
48    /** Needed by JAXB */
49    protected CatalogImpl() {
50      // default to text/xml mimetype
51      super(Type.Catalog, null, null, null, null, MimeTypes.parseMimeType("text/xml"));
52    }
53  
54    /**
55     * Creates an abstract metadata container.
56     *
57     * @param id
58     *          the element identifier withing the package
59     * @param flavor
60     *          the catalog flavor
61     * @param uri
62     *          the document location
63     * @param size
64     *          the catalog size in bytes
65     * @param checksum
66     *          the catalog checksum
67     * @param mimeType
68     *          the catalog mime type
69     */
70    protected CatalogImpl(String id, MediaPackageElementFlavor flavor, URI uri, long size, Checksum checksum,
71            MimeType mimeType) {
72      super(Type.Catalog, flavor, uri, size, checksum, mimeType);
73    }
74  
75    /**
76     * Reads the metadata from the specified file and returns it encapsulated in a {@link Catalog} object.
77     *
78     * @param uri
79     *          the dublin core metadata container file
80     * @return the dublin core object
81     */
82    public static Catalog fromURI(URI uri) {
83      CatalogImpl cat = new CatalogImpl();
84      cat.setURI(uri);
85      return cat;
86    }
87  
88    public static class Adapter extends XmlAdapter<CatalogImpl, Catalog> {
89      public CatalogImpl marshal(Catalog cat) throws Exception {
90        return (CatalogImpl) cat;
91      }
92  
93      public Catalog unmarshal(CatalogImpl cat) throws Exception {
94        return cat;
95      }
96    }
97  
98    /**
99     * @return a new catalog instance
100    */
101   public static Catalog newInstance() {
102     return new CatalogImpl();
103   }
104 
105 }