it.tidalwave.mobile.media.Media Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Core - open source birding
* Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* 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.
*
***********************************************************************************************************************
*
* WWW: http://bluebill.tidalwave.it
* SCM: https://kenai.com/hg/bluebill~core-src
*
**********************************************************************************************************************/
package it.tidalwave.mobile.media;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.openide.util.Lookup;
import it.tidalwave.util.As;
import it.tidalwave.util.AsException;
import it.tidalwave.util.Id;
import it.tidalwave.util.Key;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.util.TypeSafeMap;
import it.tidalwave.util.TypeSafeHashMap;
import it.tidalwave.util.AsSupport;
import it.tidalwave.role.spi.DefaultIdentifiable;
import it.tidalwave.role.Identifiable;
import it.tidalwave.role.Removable;
import it.tidalwave.mobile.util.Downloadable;
import it.tidalwave.mobile.util.DefaultDownloadable;
import it.tidalwave.semantic.GenericEntity;
/***********************************************************************************************************************
*
* FIXME: refactor over EntityWithProperties! Make StillImage and Movie extend this.
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
@Immutable
public class Media extends AsSupport implements As, Lookup.Provider
{
private final static long serialVersionUID = 876756656347568673L;
private static final Logger log = LoggerFactory.getLogger(Media.class);
public static final Class Media = Media.class;
// FIXME: remove, use standard vocabularies.
public static final String DC = "http://purl.org/dc/elements/1.1/";
public static final String XX = "urn:bluebill-mobile:";
public static final String O = "http://www.tidalwave.it/rdf/observation/2009/02/24#"; // FIXME
public static final String FOAF = "http://xmlns.com/foaf/0.1/";
public static final Id FOAF_DOCUMENT = new Id(FOAF + "Document");
// FIXME: use Dunlin Core ids
public static final Key AUTHOR = new Key(DC + "creator");
public static final Key SOURCE = new Key(DC + "publisher");
public static final Key LOCATION = new Key(O + "madeAt");
public static final Key CALL_TYPE = new Key(DC + "title");
public static final Key DATE = new Key(DC + "date");
public static final Key ID = new Key(DC + "identifier");
public static final Key RES_URL = new Key(XX + "url");
public static final Key RIGHTS = new Key(DC + "rights");
public static final Key MIME_TYPE = new Key(XX + "mime-type");
public static final Key DURATION = new Key(XX + "duration");
public static final Key FORMAT = new Key(DC + "format");
public static final Key TYPE = new Key(DC + "type");
@Nonnull
private final TypeSafeMap map;
@CheckForNull
private Downloadable downloadable;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public Media()
{
this(Collections., Object>emptyMap());
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
private Media (final @Nonnull Map, Object> map)
{
this.map = new TypeSafeHashMap(map);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public T get (final @Nonnull Key key)
throws NotFoundException
{
return map.get(key);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public boolean contains (final @Nonnull Key> item)
{
return map.containsKey(item);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Set> getKeys()
{
return map.getKeys();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnegative
public int getSize()
{
return map.getSize();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Iterator