package eu.dnetlib.efg1914.various.utils;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import eu.dnetlib.efg1914.authoring.components.Frame;
import eu.dnetlib.efg1914.authoring.components.Item;

@XmlRootElement
public class Frames {

    private Frame frame;
    private List<Item> items;

    public Frame getFrame() {
        return frame;
    }

    public void setFrame(Frame frame) {
        this.frame = frame;
    }

    @XmlElementWrapper(name = "items")
    @XmlElement(name = "item")
    public List<Item> getItems() {
        return items;
    }

    public void setItems(List<Item> items) {
        this.items = items;
    }

    public static void main(String[] args) throws JAXBException, UnsupportedEncodingException {
        JAXBContext jc = JAXBContext.newInstance(Frames.class);

        Unmarshaller unmarshaller = jc.createUnmarshaller();
        String s = "<frames><frame id=\"90b49ca3-eefc-4859-813b-be7269b41f91\"><header><lastModified>09-12-2013</lastModified>" +
                "</header><curator>dafdad53-f80b-4f05-a3a9-4bd8479615cf</curator><description>&lt;br&gt;</description><items><item>" +
                "1b8c81db-117d-41ed-9882-62e56dc23a0c</item><item>81d845d2-73dc-43af-a5d5-ab6c82614347</item></items><published>0</published>" +
                "<shortDescription/><suggestedTopics/><template>ft3</template><title>Comedies (1)</title></frame><items><item type=\"image\" " +
                "id=\"1b8c81db-117d-41ed-9882-62e56dc23a0c\"><header><creationDate>09-12-2013</creationDate><lastModified>09-12-2013</lastModified>" +
                "</header><affiliation>Deutsches Filminstitut</affiliation><archive/><aspectRatio>4:3</aspectRatio><category>Poster</category>" +
                "<creator/><curator>dafdad53-f80b-4f05-a3a9-4bd8479615cf</curator><description/><EFGlink>http://europeanfilmgateway.eu/node/33/d" +
                "etail/Galeotto+fu+il+mare/image:NGIyYWY5MWYtZGViNC00NmUzLTgwYmYtM2YxMTUxYTVkNDVkX1VtVndiM05wZEc5eWVWTmxjblpwWTJWU1pYTnZkWEpqWlh" +
                "NdlVtVndiM05wZEc5eWVWTmxjblpwWTJWU1pYTnZkWEpqWlZSNWNHVT06OmF2Q3JlYXRpb24uRVlFL0VZRV9Ob25BVkNyZWF0aW9uX3Bvc3RlcjEwNDg0/paging" +
                ":dmlkZW8tMS00LWltYWdlLTEtNC1zb3VuZC0xLTQtcGVyc29uLTEtNC10ZXh0LTEtNA==</EFGlink><extendedDescription>&lt;br&gt;</extendedDescription><" +
                "filetype>image/jpeg</filetype><length>0</length><mediumImage>513b9625-81f5-4ee0-bcd9-7752effead3a.jpeg</mediumImage><metadataLink" +
                "/><miniImage>c93fa5f3-e758-4bda-8549-84e42b7ca492.jpeg</miniImage><originalTitle>Galeotto fu il mare</originalTitle><productionCompan" +
                "y>Raggio Film</productionCompany><productionCountry>Italy</productionCountry><productionYear>1916</productionYear><provider/><pro" +
                "viderLink/><published>0</published><releaseDate/><snippet>false</snippet><source>96ceb3e9-3577-4d9d-932a-a3e4e22f4dd2.jpeg</source><t" +
                "itle>Galeotto fu il mare</title><used>false</used></item><item type=\"image\" id=\"81d845d2-73dc-43af-a5d5-ab6c82614347\"><header>" +
                "<creationDate>09-12-2013</creationDate></header><affiliation>Deutsches Filminstitut</affiliation><archive/><aspectRatio>4:3</aspe" +
                "ctRatio><category>Poster</category><creator/><curator>dafdad53-f80b-4f05-a3a9-4bd8479615cf</curator><description/><EFGlink>http:/" +
                "/europeanfilmgateway.eu/node/33/detail/Los+vom+Mann!/image:NGIyYWY5MWYtZGViNC00NmUzLTgwYmYtM2YxMTUxYTVkNDVkX1VtVndiM05wZEc5eWVWTmxj" +
                "blpwWTJWU1pYTnZkWEpqWlhNdlVtVndiM05wZEc5eWVWTmxjblpwWTJWU1pYTnZkWEpqWlZSNWNHVT06OmF2Q3JlYXRpb24uRVlFL0VZRV9Ob25BVkNyZWF0" +
                "aW9uX3Bvc3RlcjEwMjAwMDQ=/paging:dmlkZW8tMS00LWltYWdlLTEtNC1zb3VuZC0xLTQtcGVyc29uLTEtNC10ZXh0LTEtNA==</EFGlink><extendedDe" +
                "scription>&lt;br&gt;</extendedDescription><filetype>image/jpeg</filetype><length>0</length><mediumImage>ace380bc-5376-4b3" +
                "3-b8d1-6d3c5cf7b547.jpeg</mediumImage><metadataLink/><miniImage>eaf7c692-fcde-4d39-a66b-ef0f59da0fbd.jpeg</miniImage><ori" +
                "ginalTitle>Los vom Mann!</originalTitle><productionCompany/><productionCountry/><productionYear>1915</productionYear><prov" +
                "ider/><providerLink/><published>0</published><releaseDate/><snippet>false</snippet><source>d2fd1086-a9aa-4825-9ad3-9f772a98df3" +
                "9.jpeg</source><title>Los vom Mann!</title><used>false</used></item></items></frames>";

        InputStream stream = new ByteArrayInputStream(s.getBytes("UTF-8"));

        Frames fr = (Frames) unmarshaller.unmarshal(stream);

        System.out.println(fr.getItems().size());

//        Customer customer = new Customer();
//        customer.setBio("biological");
//        customer.setName("Katerina");
// 
//        Marshaller marshaller = jc.createMarshaller();
//        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
//        marshaller.marshal(customer, System.out);
    }
}
