it.tidalwave.semantic.document.Document 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.semantic.document;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.util.HashMap;
import java.util.Map;
import it.tidalwave.util.Id;
import it.tidalwave.util.Key;
import it.tidalwave.semantic.EntityWithProperties;
/***********************************************************************************************************************
*
* This class models a simple document with subject, mime type, body and optional attachments.
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
@Immutable
public class Document extends EntityWithProperties
{
public static final Class Document = Document.class;
public static final String PLAIN_TEXT_EXTENSION = "txt";
public static final String PLAIN_TEXT_MIME_TYPE = "text/plain";
public static final String KML_EXTENSION = "kml";
public static final String KML_MIME_TYPE = "application/vnd.google-earth.kml+xml";
public static final String CSV_EXTENSION = "csv";
public static final String CSV_MIME_TYPE = "text/csv";
public static final Map EXTENSION_MAP_BY_MIME_TYPE = new HashMap();
static
{
EXTENSION_MAP_BY_MIME_TYPE.put(PLAIN_TEXT_MIME_TYPE, PLAIN_TEXT_EXTENSION);
EXTENSION_MAP_BY_MIME_TYPE.put(CSV_MIME_TYPE, CSV_EXTENSION);
EXTENSION_MAP_BY_MIME_TYPE.put(KML_MIME_TYPE, KML_EXTENSION);
}
public static final Key SUBJECT = new Key("subject");
public static final Key BODY = new Key("body");
public static final Key MIME_TYPE = new Key("mimeType");
public static final Key ATTACHMENT = new Key("attachment");
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public Document()
{
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public Document (final @Nonnull Id id)
{
super(id);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
private Document (final @Nonnull Id id,
final @Nonnull Map, Object> propertyMap,
final @Nonnull Object[] capabilities)
{
super(id, propertyMap, capabilities);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override @Nonnull
protected Document clone (final @Nonnull Id id,
final @Nonnull Map, Object> propertyMap,
final @Nonnull Object[] capabilities)
{
return new Document(id, propertyMap, capabilities);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void accept (final @Nonnull DocumentVisitor visitor)
throws E
{
visitor.preVisitBody(this);
visitor.visitBody(this);
for (final Document attachment : getMultiple(ATTACHMENT))
{
visitor.visitAttachment(attachment);
}
visitor.postVisitBody(this);
}
}