/* * This file is part of DroidClic * * DroidClic is copyright 2012 by * Marc Alier Forment, * Maria Jos� Casany Guerrero, * Enric Mayol * * UPC Students involved in this project: * * Previous version and legacy code: * --------------------------------- * PUJOL BENET, MIRIAM * * * Project management * ------------------ * ALMA SERRANO, ALBERT * CLAVER ARGUDO, MARIA * JIMENEZ TARRES, VICTOR * CORCHADO MERINO, JUAN CARLOS * JUAN JANE, ANDREU * MENES ROUCO, MARTIN * ORTEGA GOMEZ, CRISTIAN * PURCET SOTO, SERGI * RAMOS GONZALEZ, RICARDO * SOLE MORERA, DANIEL * * * Research & support * -------------------- * ALBALATE FERNANDEZ, AIDA * CABRE JUAN, ALBERT * CANDON ARENAS, HECTOR * ELBAILE SERRA, ABEL * GONZALEZ DE PABLO, BORJA * IGLESIAS LOPEZ, OSCAR * MARTINEZ LOPEZ, SERGIO * PEREZ PLANAS, ORIAC * SANCHEZ MARCOS, IVAN * TORNE GOZALBO, ORIOL * * * Development * ----------- * Lead developers * ALBALATE FERNANDEZ, AIDA * COSTA MANSILLA, GERARD * GONZALEZ DE PABLO, BORJA * Developers: * ALEMANY FONT, ALBERT * ALVAREZ JUSTE, XAVIER * ALVAREZ MORALES, FERRAN * BARRERO MARTINEZ, LINDSAY * BENITEZ VALLS, ALBERT * BERRUEZO MARTINEZ, DAVID * BRAMON DEVANT, MARC * BRIGUELLI DA SILVA, LUIS FERNANDO * CABRE JUAN, ALBERT * CANDON ARENAS, HECTOR * CAPEL CATALAN, VICTOR * CLAVER ARGUDO, MARIA * DE PAULA DE PUIG GUIXE, FRANCESC * DIEZ RUIZ, ALBERT * ELBAILE SERRA, ABEL * FARRE GONZALEZ, PAU * GARCIA GARCIA, XAVIER * HURTADO OBIOLS, CRISTINA * MARTINEZ DIAZ, ARTURO * MARTINEZ LOPEZ, SERGIO * MENES ROUCO, MARTIN * MONTSERRAT GARCIA, EDUARD * ORTIZ GRIMAU, XAVIER * OSORIO ALVAREZ, DAVID * PASCUAL VAZQUEZ, PABLO * PEDRAZA GUTIERREZ, M. MERCEDES * PEREZ PLANAS, ORIAC * RODRIGUEZ TORRES, MIREIA * SANCHEZ MARCOS, IVAN * SEGARRA RODA, EDUARD * SELLES FEITO, MANEL * SOLER PASCUAL, GERARD * SUBIRATS SALVANS, JOAN * * * Design & usability * -------------------- * Lead designer: * LEGORBURU CLADERA, I�IGO * Designers: * OTAL RODRIGUEZ, DANIEL * PASCUAL VAZQUEZ, PABLO * SEGARRA RODA, EDUARD * SOLER PASCUAL, GERARD * SUBIRATS SALVANS, JOAN * VIDAL PASTALLE, MARIA * * * Testing, evaluation & audit * --------------------------- * Lead tester: * NAVARRO JIMENEZ, GERMAN * ALEMANY FONT, ALBERT * Testers: * ALVAREZ MORALES, FERRAN * BENITEZ VALLS, ALBERT * CAPEL CATALAN, VICTOR * MONTSERRAT GARCIA, EDUARD * ORTIZ GRIMAU, XAVIER * SANCHEZ CORREDOR, MONTSERRAT * * * Documentation, communication & broadcast * ---------------------------------------- * Lead documentator: * ALVAREZ JUSTE, XAVIER * SANCHEZ CORREDOR, MONTSERRAT * Documentators: * BARRERO MARTINEZ, LINDSAY * GARCIA GARCIA, XAVIER * NAVARRO JIMENEZ, GERMAN * OSORIO ALVAREZ, DAVID * TORNE GOZALBO, ORIOL * * * DroidClic is copyright 2012 by * Universitat Politecnica de Catalunya http://www.upc.edu * Contact info: * Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu * * DroiClic is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Droidlic is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DroidClic. If not, see <http://www.gnu.org/licenses/>. * * DroidClic is based on the Software JClic by Francesc Busquets * http://clic.xtec.cat/es/jclic/ * */ package pfc.ConnectionLayer; import java.io.IOException; import java.net.URL; import java.net.UnknownHostException; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.DOMException; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.xml.sax.SAXException; /** * The ClicMetaData class represents a Clic with all it's metadata as it's * stored on the server. * * @author Albert Cabr� Juan */ public final class ClicMetaData { // definition for the xml tags private static final String TITLE_TAG = "title"; private static final String BODY_TAG = "body"; private static final String AUTHOR_TAG = "author"; private static final String AGE_TAG = "age"; private static final String LANGUAGE_TAG = "language"; private static final String THEME_TAG = "thematic"; private static final String CLIC_TAG = "path"; private static final String LICENSE_TAG = "license"; private static final String IMAGE_TAG = "image"; private final String title; private final String body; private final String author; private final int age; private final String license; private final int thematic; private final int language; private final URL image; private final URL clic; private final String fileName; /** * Creates an instance of a ClicMetaData based on a XML representation of * the Clic and it's metadata. * * @param xml * Node representation of the XML * @throws ParserConfigurationException * Should never be thrown. * @throws SAXException * The file reached is not valid XML * @throws IOException * Thrown when connectivity problems appear. * @throws DOMException * The XML format was unexpected (ex:missing attributes) * @throws UnknownHostException * Unchecked exception, it's thrown when there's no Internet at * all (DNS servers unreachable). */ ClicMetaData(Element item) throws ParserConfigurationException, SAXException, IOException, DOMException { // String attributes title = item.getElementsByTagName(TITLE_TAG).item(0).getFirstChild() .getNodeValue(); Node authorNode = item.getElementsByTagName(AUTHOR_TAG).item(0); if (authorNode.hasChildNodes()) { author = item.getElementsByTagName(AUTHOR_TAG).item(0) .getFirstChild().getNodeValue(); } else { author = null; } body = item.getElementsByTagName(BODY_TAG).item(0).getFirstChild() .getNodeValue(); Node licenseNode = item.getElementsByTagName(LICENSE_TAG).item(0); if (licenseNode.hasChildNodes()) { license = item.getElementsByTagName(LICENSE_TAG).item(0) .getFirstChild().getNodeValue(); } else { license = null; } thematic = Integer.parseInt(item.getElementsByTagName(THEME_TAG) .item(0).getFirstChild().getNodeValue()); age = Integer.parseInt(item.getElementsByTagName(AGE_TAG).item(0) .getFirstChild().getNodeValue()); language = Integer.parseInt(item.getElementsByTagName(LANGUAGE_TAG) .item(0).getFirstChild().getNodeValue()); // File attributes, only the URL is stored for later lazy downloading image = new URL(item.getElementsByTagName(IMAGE_TAG).item(0) .getFirstChild().getNodeValue()); clic = new URL(item.getElementsByTagName(CLIC_TAG).item(0) .getFirstChild().getNodeValue()); String[] split = item.getElementsByTagName(CLIC_TAG).item(0) .getFirstChild().getNodeValue().split("/"); fileName = split[split.length - 1].split("\\.")[0]; } public String getTitle() { return title; } public String getBody() { return body; } public String getAuthor() { return author; } public String getLicense() { return license; } public int getThematic() { return thematic; } public int getAge() { return age; } public int getLanguage() { return language; } /** * Downloads and returns the screenshot. * * @return The screenshot in a byte array * @throws IOException * Connectivity problems */ public byte[] getImage() throws IOException { return Downloader.downloadFile(image); } /** * Downloads and returns the clic. * * @return The clic in a byte array * @throws IOException * Connectivity problems */ public byte[] getClic() throws IOException { return Downloader.downloadFile(clic); } public String getFileName() { return fileName; } }