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(
104 * org.opencastproject.metadata.mpeg7.Textual, 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(
116 * org.opencastproject.metadata.mpeg7.VideoText)
117 */
118 @Override
119 public void addVideoText(VideoText videoText) {
120 videoTexts.add(videoText);
121 }
122
123 /**
124 * {@inheritDoc}
125 *
126 * @see org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition#getVideoText()
127 */
128 @Override
129 public VideoText[] getVideoText() {
130 return videoTexts.toArray(new VideoText[videoTexts.size()]);
131 }
132
133 /**
134 * {@inheritDoc}
135 *
136 * @see org.opencastproject.metadata.mpeg7.SpatioTemporalDecomposition#getVideoText(java.lang.String)
137 */
138 @Override
139 public VideoText getVideoText(String id) {
140 for (VideoText videoText : videoTexts) {
141 if (id.equals(videoText.getIdentifier())) {
142 return videoText;
143 }
144 }
145 return null;
146 }
147
148 /**
149 * @see org.opencastproject.mediapackage.XmlElement#toXml(org.w3c.dom.Document)
150 */
151 public Node toXml(Document document) {
152 Element node = document.createElement("SpatioTemporalDecomposition");
153 node.setAttribute("gap", (hasGap ? "true" : "false"));
154 node.setAttribute("overlap", (hasOverlap ? "true" : "false"));
155 for (VideoText videoText : videoTexts) {
156 node.appendChild(videoText.toXml(document));
157 }
158 return node;
159 }
160
161 }