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        }
54      } else if (type != null && !type.equals(MediaPackageElement.Type.Attachment)) {
55        return false;
56      } else if (flavor != null && !flavor.equals(Attachment.FLAVOR)) {
57        return false;
58      }
59      return super.accept(uri, type, flavor);
60    }
61  
62    /**
63     * @see org.opencastproject.mediapackage.elementbuilder.AbstractAttachmentBuilderPlugin#accept(org.w3c.dom.Node)
64     */
65    @Override
66    public boolean accept(Node elementNode) {
67      return super.accept(elementNode);
68    }
69  
70    /**
71     * {@inheritDoc}
72     *
73     * This plugin is an implementation for unknown attachments, therefore it returns <code>-1</code> as its priority.
74     *
75     * @see org.opencastproject.mediapackage.elementbuilder.AbstractElementBuilderPlugin#getPriority()
76     */
77    @Override
78    public int getPriority() {
79      return -1;
80    }
81  
82    /**
83     * @see java.lang.Object#toString()
84     */
85    @Override
86    public String toString() {
87      return "Attachment Builder Plugin";
88    }
89  
90  }