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.metadata.mpeg7;
24  
25  import org.w3c.dom.Document;
26  import org.w3c.dom.Element;
27  import org.w3c.dom.Node;
28  
29  /**
30   * TODO: Comment me!
31   */
32  public class MediaTimeImpl implements MediaTime {
33  
34    /** The media time point */
35    protected MediaTimePoint mediaTimePoint = null;
36  
37    /** The media duration */
38    protected MediaDuration mediaDuration = null;
39  
40    /**
41     * Creates a media time object representing the given timepoint and duration.
42     *
43     * @param timePoint
44     *          the time point
45     * @param duration
46     *          the duration
47     */
48    public MediaTimeImpl(MediaTimePoint timePoint, MediaDuration duration) {
49      mediaTimePoint = timePoint;
50      mediaDuration = duration;
51    }
52  
53    /**
54     * Creates a media time object from the given long values for timepoint and duration.
55     *
56     * @param time
57     *          the time in milliseconds
58     * @param duration
59     *          the duration in milliseconds
60     */
61    public MediaTimeImpl(long time, long duration) {
62      mediaTimePoint = new MediaTimePointImpl(time);
63      mediaDuration = new MediaDurationImpl(duration);
64    }
65  
66    /**
67     * Creates a media time object from the given string representations for timepoint and duration.
68     *
69     * @param time
70     *          the timepoint string representation
71     * @param duration
72     *          the duration string representation
73     */
74    MediaTimeImpl(String time, String duration) {
75      mediaTimePoint = MediaTimePointImpl.parseTimePoint(time);
76      mediaDuration = MediaDurationImpl.parseDuration(duration);
77    }
78  
79    /**
80     * @see org.opencastproject.metadata.mpeg7.MediaTime#getMediaDuration()
81     */
82    public MediaDuration getMediaDuration() {
83      return mediaDuration;
84    }
85  
86    /**
87     * @see org.opencastproject.metadata.mpeg7.MediaTime#getMediaTimePoint()
88     */
89    public MediaTimePoint getMediaTimePoint() {
90      return mediaTimePoint;
91    }
92  
93    /**
94     * Parses a media time and duration.
95     *
96     * @param time
97     * @param duration
98     * @return the
99     */
100   public static MediaTime parse(String time, String duration) {
101     MediaTime mediaTime = new MediaTimeImpl(time, duration);
102     return mediaTime;
103   }
104 
105   /**
106    * @see org.opencastproject.mediapackage.XmlElement#toXml(org.w3c.dom.Document)
107    */
108   public Node toXml(Document document) {
109     Element node = document.createElement("MediaTime");
110     if (mediaTimePoint != null)
111       node.appendChild(mediaTimePoint.toXml(document));
112     if (mediaDuration != null)
113       node.appendChild(mediaDuration.toXml(document));
114     return node;
115   }
116 
117 }