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.elementbuilder;
24  
25  import org.opencastproject.mediapackage.Attachment;
26  import org.opencastproject.mediapackage.MediaPackageElement;
27  import org.opencastproject.mediapackage.MediaPackageElementBuilder;
28  import org.opencastproject.mediapackage.MediaPackageElementFlavor;
29  
30  import org.w3c.dom.Node;
31  
32  import java.net.URI;
33  
34  /**
35   * This implementation of the {@link MediaPackageElementBuilderPlugin} recognizes arbitrary attachments and creates
36   * media package element representations for them.
37   * <p>
38   * A media package element is considered an attachment by this plugin if it is of type {@link Attachment} and does not
39   * have any specializing flavor.
40   */
41  public class AttachmentBuilderPlugin extends AbstractAttachmentBuilderPlugin implements MediaPackageElementBuilder {
42  
43    /**
44     * @see org.opencastproject.mediapackage.elementbuilder.AbstractAttachmentBuilderPlugin#accept(URI,
45     *      org.opencastproject.mediapackage.MediaPackageElement.Type ,
46     *      org.opencastproject.mediapackage.MediaPackageElementFlavor)
47     */
48    @Override
49    public boolean accept(URI uri, MediaPackageElement.Type type, MediaPackageElementFlavor flavor) {
50      if (type != null && flavor != null) {
51        if (!type.equals(MediaPackageElement.Type.Attachment))
52          return false;
53      } else if (type != null && !type.equals(MediaPackageElement.Type.Attachment)) {
54        return false;
55      } else if (flavor != null && !flavor.equals(Attachment.FLAVOR)) {
56        return false;
57      }
58      return super.accept(uri, type, flavor);
59    }
60  
61    /**
62     * @see org.opencastproject.mediapackage.elementbuilder.AbstractAttachmentBuilderPlugin#accept(org.w3c.dom.Node)
63     */
64    @Override
65    public boolean accept(Node elementNode) {
66      return super.accept(elementNode);
67    }
68  
69    /**
70     * {@inheritDoc}
71     *
72     * This plugin is an implementation for unknown attachments, therefore it returns <code>-1</code> as its priority.
73     *
74     * @see org.opencastproject.mediapackage.elementbuilder.AbstractElementBuilderPlugin#getPriority()
75     */
76    @Override
77    public int getPriority() {
78      return -1;
79    }
80  
81    /**
82     * @see java.lang.Object#toString()
83     */
84    @Override
85    public String toString() {
86      return "Attachment Builder Plugin";
87    }
88  
89  }