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 package org.opencastproject.metadata.mpeg7;
23
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
26 import org.w3c.dom.Node;
27
28 import java.awt.Rectangle;
29 import java.util.ArrayList;
30 import java.util.List;
31
32 /**
33 * Default implementation of a spatio temporal decomposition.
34 */
35 public class SpatioTemporalDecompositionImpl implements SpatioTemporalDecomposition {
36
37 /** Flag to indicate whether the elements in this decomposition may exhibit gaps */
38 protected boolean hasGap = true;
39
40 /** Flag to indicate whether the elements in this decomposition may overlap */
41 protected boolean hasOverlap = false;
42
43 /** The list of videotext elements */
44 protected List<VideoText> videoTexts = null;
45
46 /**
47 * Creates a new spatio temporal decomposition.
48 *
49 * @param gap
50 * <code>true</code> if there are gaps in the decomposition
51 * @param overlap
52 * <code>true</code> if there are overlapping elements
53 */
54 public SpatioTemporalDecompositionImpl(boolean gap, boolean overlap) {
55 this.hasGap = gap;
56 this.hasOverlap = overlap;
57 this.videoTexts = new ArrayList<VideoText>();
58 }
59
60 /**
61 * {@inheritDoc}
62 *
63 * @see org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition#hasGap()
64 */
65 @Override
66 public boolean hasGap() {
67 return hasGap;
68 }
69
70 /**
71 * {@inheritDoc}
72 *
73 * @see org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition#isOverlapping()
74 */
75 @Override
76 public boolean isOverlapping() {
77 return hasOverlap;
78 }
79
80 /**
81 * {@inheritDoc}
82 *
83 * @see org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition#setGap(boolean)
84 */
85 @Override
86 public void setGap(boolean hasGap) {
87 this.hasGap = hasGap;
88 }
89
90 /**
91 * {@inheritDoc}
92 *
93 * @see org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition#setOverlapping(boolean)
94 */
95 @Override
96 public void setOverlapping(boolean isOverlapping) {
97 this.hasOverlap = isOverlapping;
98 }
99
100 /**
101 * {@inheritDoc}
102 *
103 * @see org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition#addVideoText(org.opencastproject.metadata.mpeg7.Textual,
104 * java.awt.Rectangle, org.opencastproject.metadata.mpeg7.MediaTime)
105 */
106 public VideoText addVideoText(Textual text, Rectangle boundary, MediaTime time) {
107 VideoText videoText = new VideoTextImpl("videotext-" + videoTexts.size(), text, boundary, time);
108 videoTexts.add(videoText);
109 return videoText;
110 }
111
112 /**
113 * {@inheritDoc}
114 *
115 * @see org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition#addVideoText(org.opencastproject.metadata.mpeg7.VideoText)
116 */
117 @Override
118 public void addVideoText(VideoText videoText) {
119 videoTexts.add(videoText);
120 }
121
122 /**
123 * {@inheritDoc}
124 *
125 * @see org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition#getVideoText()
126 */
127 @Override
128 public VideoText[] getVideoText() {
129 return videoTexts.toArray(new VideoText[videoTexts.size()]);
130 }
131
132 /**
133 * {@inheritDoc}
134 *
135 * @see org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition#getVideoText(java.lang.String)
136 */
137 @Override
138 public VideoText getVideoText(String id) {
139 for (VideoText videoText : videoTexts) {
140 if (id.equals(videoText.getIdentifier()))
141 return videoText;
142 }
143 return null;
144 }
145
146 /**
147 * @see org.opencastproject.mediapackage.XmlElement#toXml(org.w3c.dom.Document)
148 */
149 public Node toXml(Document document) {
150 Element node = document.createElement("SpatioTemporalDecomposition");
151 node.setAttribute("gap", (hasGap ? "true" : "false"));
152 node.setAttribute("overlap", (hasOverlap ? "true" : "false"));
153 for (VideoText videoText : videoTexts) {
154 node.appendChild(videoText.toXml(document));
155 }
156 return node;
157 }
158
159 }