[LIB-4] Add hespiff source files
[hespiff.git] / src / main / java / org / hedgecode / xml / xspf / bind / XSDTrackBinder.java
diff --git a/src/main/java/org/hedgecode/xml/xspf/bind/XSDTrackBinder.java b/src/main/java/org/hedgecode/xml/xspf/bind/XSDTrackBinder.java
new file mode 100644 (file)
index 0000000..d32008c
--- /dev/null
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2015. Developed by Hedgecode.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.hedgecode.xml.xspf.bind;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hedgecode.xml.xspf.Extension;
+import org.hedgecode.xml.xspf.Link;
+import org.hedgecode.xml.xspf.Meta;
+import org.hedgecode.xml.xspf.PlaylistFactory;
+import org.hedgecode.xml.xspf.xsd.ExtensionType;
+import org.hedgecode.xml.xspf.xsd.LinkType;
+import org.hedgecode.xml.xspf.xsd.MetaType;
+import org.hedgecode.xml.xspf.xsd.TrackType;
+
+/**
+ *
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class XSDTrackBinder extends AbstractXSDBinder implements TrackBinder {
+
+    private TrackType xsdTrack;
+
+    public XSDTrackBinder() {
+        this.xsdTrack = XSD_FACTORY.createTrackType();
+    }
+
+    public XSDTrackBinder(TrackType xsdTrack) {
+        this.xsdTrack = xsdTrack;
+    }
+
+    public Object getTrack() {
+        return xsdTrack;
+    }
+
+    public void setTrack(Object track) {
+        if (track != null && track instanceof TrackType)
+            this.xsdTrack = (TrackType) track;
+    }
+
+    @Override
+    public List<String> getLocations() {
+        return xsdTrack.getLocation();
+    }
+
+    @Override
+    public void addLocation(String location) {
+        if (location != null) {
+            xsdTrack.getLocation().add(
+                    location
+            );
+        }
+    }
+
+    @Override
+    public List<String> getIdentifiers() {
+        return xsdTrack.getIdentifier();
+    }
+
+    @Override
+    public void addIdentifier(String identifier) {
+        if (identifier != null) {
+            xsdTrack.getIdentifier().add(
+                    identifier
+            );
+        }
+    }
+
+    @Override
+    public String getTitle() {
+        return xsdTrack.getTitle();
+    }
+
+    @Override
+    public void setTitle(String title) {
+        xsdTrack.setTitle(title);
+    }
+
+    @Override
+    public String getCreator() {
+        return xsdTrack.getCreator();
+    }
+
+    @Override
+    public void setCreator(String creator) {
+        xsdTrack.setCreator(creator);
+    }
+
+    @Override
+    public String getAnnotation() {
+        return xsdTrack.getAnnotation();
+    }
+
+    @Override
+    public void setAnnotation(String annotation) {
+        xsdTrack.setAnnotation(annotation);
+    }
+
+    @Override
+    public String getInfo() {
+        return xsdTrack.getInfo();
+    }
+
+    @Override
+    public void setInfo(String info) {
+        xsdTrack.setInfo(info);
+    }
+
+    @Override
+    public String getImage() {
+        return xsdTrack.getImage();
+    }
+
+    @Override
+    public void setImage(String image) {
+        xsdTrack.setImage(image);
+    }
+
+    @Override
+    public String getAlbum() {
+        return xsdTrack.getAlbum();
+    }
+
+    @Override
+    public void setAlbum(String album) {
+        xsdTrack.setAlbum(album);
+    }
+
+    @Override
+    public Integer getTrackNum() {
+        BigInteger trackNum = xsdTrack.getTrackNum();
+        return trackNum != null ? trackNum.intValue() : null;
+    }
+
+    @Override
+    public void setTrackNum(Integer trackNum) {
+        xsdTrack.setTrackNum(
+                trackNum != null ? BigInteger.valueOf(trackNum) : null
+        );
+    }
+
+    @Override
+    public Integer getDuration() {
+        BigInteger duration = xsdTrack.getDuration();
+        return duration != null ? duration.intValue() : null;
+    }
+
+    @Override
+    public void setDuration(Integer duration) {
+        xsdTrack.setDuration(
+                duration != null ? BigInteger.valueOf(duration) : null
+        );
+    }
+
+    @Override
+    public List<Link> getLinks() {
+        List<Link> links = new ArrayList<>();
+        for (LinkType link : xsdTrack.getLink()) {
+            links.add(
+                    PlaylistFactory.createLink(link.getRel(), link.getValue())
+            );
+        }
+        return links;
+    }
+
+    @Override
+    public void addLink(Link link) {
+        if (link != null) {
+            LinkType linkType = XSD_FACTORY.createLinkType();
+            linkType.setRel(link.getRel());
+            linkType.setValue(link.getContent());
+            xsdTrack.getLink().add(
+                    linkType
+            );
+        }
+    }
+
+    @Override
+    public List<Meta> getMetas() {
+        List<Meta> metas = new ArrayList<>();
+        for (MetaType meta : xsdTrack.getMeta()) {
+            metas.add(
+                    PlaylistFactory.createMeta(meta.getRel(), meta.getValue())
+            );
+        }
+        return metas;
+    }
+
+    @Override
+    public void addMeta(Meta meta) {
+        if (meta != null) {
+            MetaType metaType = XSD_FACTORY.createMetaType();
+            metaType.setRel(meta.getRel());
+            metaType.setValue(meta.getContent());
+            xsdTrack.getMeta().add(
+                    metaType
+            );
+        }
+    }
+
+    @Override
+    public List<Extension> getExtensions() {
+        List<Extension> extensions = new ArrayList<>();
+        for (ExtensionType extension : xsdTrack.getExtension()) {
+            extensions.add(
+                    PlaylistFactory.createExtension(
+                            extension.getApplication(), extension.getContent()
+                    )
+            );
+        }
+        return extensions;
+    }
+
+    @Override
+    public void addExtension(Extension extension) {
+        if (extension != null) {
+            ExtensionType extensionType = XSD_FACTORY.createExtensionType();
+            extensionType.setApplication(extension.getApplication());
+            extensionType.getContent().addAll(extension.getContent());
+            xsdTrack.getExtension().add(
+                    extensionType
+            );
+        }
+    }
+
+}