2 * Copyright (c) 2015-2019. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.xml.xspf.bind;
19 import java.math.BigInteger;
20 import java.util.ArrayList;
21 import java.util.List;
23 import org.hedgecode.xml.xspf.Extension;
24 import org.hedgecode.xml.xspf.Link;
25 import org.hedgecode.xml.xspf.Meta;
26 import org.hedgecode.xml.xspf.PlaylistFactory;
27 import org.hedgecode.xml.xspf.xsd.ExtensionType;
28 import org.hedgecode.xml.xspf.xsd.LinkType;
29 import org.hedgecode.xml.xspf.xsd.MetaType;
30 import org.hedgecode.xml.xspf.xsd.TrackType;
35 * @author Dmitry Samoshin aka gotty
37 public class XSDTrackBinder extends AbstractXSDBinder implements TrackBinder {
39 private TrackType xsdTrack;
41 public XSDTrackBinder() {
42 this.xsdTrack = XSD_FACTORY.createTrackType();
45 public XSDTrackBinder(TrackType xsdTrack) {
46 this.xsdTrack = xsdTrack;
49 public Object getTrack() {
53 public void setTrack(Object track) {
54 if (track != null && track instanceof TrackType)
55 this.xsdTrack = (TrackType) track;
59 public List<String> getLocations() {
60 return xsdTrack.getLocation();
64 public void addLocation(String location) {
65 if (location != null) {
66 xsdTrack.getLocation().add(
73 public List<String> getIdentifiers() {
74 return xsdTrack.getIdentifier();
78 public void addIdentifier(String identifier) {
79 if (identifier != null) {
80 xsdTrack.getIdentifier().add(
87 public String getTitle() {
88 return xsdTrack.getTitle();
92 public void setTitle(String title) {
93 xsdTrack.setTitle(title);
97 public String getCreator() {
98 return xsdTrack.getCreator();
102 public void setCreator(String creator) {
103 xsdTrack.setCreator(creator);
107 public String getAnnotation() {
108 return xsdTrack.getAnnotation();
112 public void setAnnotation(String annotation) {
113 xsdTrack.setAnnotation(annotation);
117 public String getInfo() {
118 return xsdTrack.getInfo();
122 public void setInfo(String info) {
123 xsdTrack.setInfo(info);
127 public String getImage() {
128 return xsdTrack.getImage();
132 public void setImage(String image) {
133 xsdTrack.setImage(image);
137 public String getAlbum() {
138 return xsdTrack.getAlbum();
142 public void setAlbum(String album) {
143 xsdTrack.setAlbum(album);
147 public Integer getTrackNum() {
148 BigInteger trackNum = xsdTrack.getTrackNum();
149 return trackNum != null ? trackNum.intValue() : null;
153 public void setTrackNum(Integer trackNum) {
154 xsdTrack.setTrackNum(
155 trackNum != null ? BigInteger.valueOf(trackNum) : null
160 public Integer getDuration() {
161 BigInteger duration = xsdTrack.getDuration();
162 return duration != null ? duration.intValue() : null;
166 public void setDuration(Integer duration) {
167 xsdTrack.setDuration(
168 duration != null ? BigInteger.valueOf(duration) : null
173 public List<Link> getLinks() {
174 List<Link> links = new ArrayList<>();
175 for (LinkType link : xsdTrack.getLink()) {
177 PlaylistFactory.createLink(link.getRel(), link.getValue())
184 public void addLink(Link link) {
186 LinkType linkType = XSD_FACTORY.createLinkType();
187 linkType.setRel(link.getRel());
188 linkType.setValue(link.getContent());
189 xsdTrack.getLink().add(
196 public List<Meta> getMetas() {
197 List<Meta> metas = new ArrayList<>();
198 for (MetaType meta : xsdTrack.getMeta()) {
200 PlaylistFactory.createMeta(meta.getRel(), meta.getValue())
207 public void addMeta(Meta meta) {
209 MetaType metaType = XSD_FACTORY.createMetaType();
210 metaType.setRel(meta.getRel());
211 metaType.setValue(meta.getContent());
212 xsdTrack.getMeta().add(
219 public List<Extension> getExtensions() {
220 List<Extension> extensions = new ArrayList<>();
221 for (ExtensionType extension : xsdTrack.getExtension()) {
223 PlaylistFactory.createExtension(
224 extension.getApplication(), extension.getContent()
232 public void addExtension(Extension extension) {
233 if (extension != null) {
234 ExtensionType extensionType = XSD_FACTORY.createExtensionType();
235 extensionType.setApplication(extension.getApplication());
236 extensionType.getContent().addAll(extension.getContent());
237 xsdTrack.getExtension().add(