/* * Copyright (c) 2015 Institut National de l'Audiovisuel, INA * * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Redistributions of source code and compiled versions * must retain the above copyright notice, this list of conditions and * the following disclaimer. * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * You should have received a copy of the GNU Lesser General Public License * along with this file. If not, see <http://www.gnu.org/licenses/> * * This file 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 Lesser General Public License for more details. */ package fr.ina.research.amalia.model; import java.util.GregorianCalendar; import java.util.Locale; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import fr.ina.research.amalia.AmaliaException; import fr.ina.research.amalia.model.jaxb.ActionType; import fr.ina.research.amalia.model.jaxb.Data; import fr.ina.research.amalia.model.jaxb.Metadata; import fr.ina.research.amalia.model.jaxb.ViewControl; import fr.ina.research.rex.commons.tc.RexTimeCode; /** * Wraps the model classes automatically generated by Jaxb. * * @author Nicolas HERVE - nherve@ina.fr */ public class MetadataBlock extends Block { public enum MetadataType { DETECTION(MBT_DETECTION), VISUAL_DETECTION(MBT_VISUAL_DETECTION), VISUAL_TRACKING(MBT_VISUAL_TRACKING), VISUAL_SEGMENTATION(MBT_VISUAL_SEGMENTATION), SEGMENTATION(MBT_SEGMENTATION), AUDIO_SEGMENTATION(MBT_AUDIO_SEGMENTATION), TRANSCRIPTION(MBT_TRANSCRIPTION), SYNCHRONIZED_TEXT(MBT_SYNCHRONIZED_TEXT), KEYFRAMES(MBT_KEYFRAMES), HISTOGRAM(MBT_HISTOGRAM), DEFAULT(MBT_DEFAULT); private final String text; private MetadataType(final String text) { this.text = text; } @Override public String toString() { return text; } } public final static String MBT_DETECTION = "detection"; public final static String MBT_VISUAL_DETECTION = "visual_detection"; public final static String MBT_VISUAL_TRACKING = "visual_tracking"; public final static String MBT_VISUAL_SEGMENTATION = "visual_segmentation"; public final static String MBT_SEGMENTATION = "segmentation"; public final static String MBT_AUDIO_SEGMENTATION = "audio_segmentation"; public final static String MBT_TRANSCRIPTION = "transcription"; public final static String MBT_SYNCHRONIZED_TEXT = "synchronized_text"; public final static String MBT_KEYFRAMES = "keyframes"; public final static String MBT_HISTOGRAM = "histogram"; public final static String MBT_DEFAULT = "default"; private Metadata internal; private LocalisationBlock root; MetadataBlock() { this(new Metadata()); setType(MetadataType.DEFAULT); } MetadataBlock(Metadata m) { super(); internal = m; } @Override public LocalisationBlock addLocalisationBlock(LocalisationBlock l) { l.setTclevel(getTcLevel()); internal.getLocalisation().add(l.getInternal()); return l; } public LocalisationBlock addToRootLocalisationBlock(LocalisationBlock l) { root.addLocalisationBlock(l); return l; } public LocalisationBlock addToRootLocalisationBlock(RexTimeCode tc) throws AmaliaException { return addToRootLocalisationBlock(MetadataFactory.createLocalisationBlock(tc)); } public LocalisationBlock addToRootLocalisationBlock(RexTimeCode tcin, RexTimeCode tcout) throws AmaliaException { return addToRootLocalisationBlock(MetadataFactory.createLocalisationBlock(tcin, tcout)); } public LocalisationBlock addToRootLocalisationBlock(String tc) throws AmaliaException { return addToRootLocalisationBlock(MetadataFactory.createLocalisationBlock(tc)); } public LocalisationBlock addToRootLocalisationBlock(String tcin, String tcout) throws AmaliaException { return addToRootLocalisationBlock(MetadataFactory.createLocalisationBlock(tcin, tcout)); } private void checkViewControl() { if (internal.getViewControl() == null) { internal.setViewControl(new ViewControl()); } } public void clearLocalisationBlock() { internal.getLocalisation().clear(); } @Override public DataBlock getDataBlock() throws AmaliaException { if (internal.getData() == null) { internal.setData(new Data()); } return new DataBlock(internal.getData()); } public String getId() { return internal.getId(); } public Metadata getInternal() { return internal; } public LocalisationBlock getRootLocalisationBlock() { return root; } @Override public int getTcLevel() { if (internal.getLocalisation().isEmpty()) { return 0; } else { return internal.getLocalisation().get(0).getTclevel(); } } public String getType() { return internal.getType(); } public MetadataBlock setAlgorithm(String value) { internal.setAlgorithm(value); return this; } public MetadataBlock setId(String value) { internal.setId(value); return this; } public void setLabel(String value) { internal.setLabel(value); } public MetadataBlock setProcessedNow() throws AmaliaException { return setProcessedNow(Locale.getDefault()); } public MetadataBlock setProcessedNow(Locale locale) throws AmaliaException { try { internal.setProcessed(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar(locale))); return this; } catch (DatatypeConfigurationException e) { throw new AmaliaException(e); } } public MetadataBlock setProcessor(String value) { internal.setProcessor(value); return this; } public void setRootDirectory(String value) { internal.setRootDirectory(value); } public LocalisationBlock setRootLocalisationBlock(LocalisationBlock l) { addLocalisationBlock(l); root = l; return l; } public LocalisationBlock setRootLocalisationBlock(RexTimeCode tcin, RexTimeCode tcout) throws AmaliaException { return setRootLocalisationBlock(MetadataFactory.createLocalisationBlock(tcin, tcout)); } public MetadataBlock setType(MetadataType value) { internal.setType(value.toString()); return this; } public MetadataBlock setType(String value) { internal.setType(value); return this; } public MetadataBlock setVCAction(ActionType value) { checkViewControl(); internal.getViewControl().setAction(value); return this; } public MetadataBlock setVCColor(String value) { checkViewControl(); internal.getViewControl().setColor(value); return this; } public MetadataBlock setVCParseLevel(Integer value) { checkViewControl(); internal.getViewControl().setParseLevel(value); return this; } public MetadataBlock setVCShape(String value) { checkViewControl(); internal.getViewControl().setShape(value); return this; } public MetadataBlock setVersion(Integer value) { internal.setVersion(value); return this; } @Override public String toString() { return "MetadataBlock [" + internal.getId() + " | " + internal.getType() + " | " + internal.getAlgorithm() + " | " + internal.getProcessor() + "]"; } }