提交 0b9636b3 编写于 作者: N nilspreusker

minor refactoring of cycle API in order to display file type (content-type)...

minor refactoring of cycle API in order to display file type (content-type) information in the UI, made ContentType an enum and added a ContentType property to ArtifactType
上级 849c40a5
......@@ -28,6 +28,8 @@ import java.util.List;
public interface ArtifactType {
public String getId();
public ContentType getContentType();
/**
* list of {@link ContentRepresentation} in the configured order
......
......@@ -25,10 +25,10 @@ public interface ContentRepresentation extends Serializable {
public String getId();
/**
* type of content as normally indicated by {@link ContentType} (e.g. text
* file, image, ...). Information for the client to render it correctly.
* Type of content (e.g. text file, image, ...). Information for the client
* to render the content correctly.
*/
public String getMimeType();
public ContentType getContentType();
// TODO: Think about that, maybe as annotation in the Plugin-Config
// public boolean isDownloadable();
}
......@@ -10,22 +10,32 @@ package org.activiti.cycle;
*
* @author bernd.ruecker@camunda.com
*/
public class ContentType {
public enum ContentType {
public static final String PNG = "image/png";
public static final String GIF = "image/gif";
public static final String JPEG = "image/jpeg"; // or use "image/jpeg;charset=ISO-8859-1" ?
public static final String XML = "application/xml";
public static final String HTML = "text/html";
public static final String TEXT = "text/plain";
public static final String PDF = "application/pdf";
public static final String JSON = "application/json;charset=UTF-8";
public static final String MS_WORD = "application/msword";
public static final String MS_POWERPOINT = "application/powerpoint";
public static final String MS_EXCEL = "application/excel";
public static final String JAVASCRIPT = "application/javascript";
// TODO: Hmm?
public static final String BINARY = "unknown";
PNG("image/png"),
GIF("image/gif"),
JPEG("image/jpeg") /* or use "image/jpeg;charset=ISO-8859-1" ? */,
XML("application/xml"),
HTML("text/html"),
TEXT("text/plain"),
PDF("application/pdf"),
JSON("application/json;charset=UTF-8"),
MS_WORD("application/msword"),
MS_POWERPOINT("application/powerpoint"),
MS_EXCEL("application/excel"),
JAVASCRIPT("application/javascript"),
//
// // TODO: Hmm?
BINARY("unknown");
}
private final String name;
private ContentType(String description) {
this.name = description;
}
public String getName() {
return this.name;
}
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ import java.util.Map;
import org.activiti.cycle.ArtifactType;
import org.activiti.cycle.ContentProvider;
import org.activiti.cycle.ContentRepresentation;
import org.activiti.cycle.ContentType;
import org.activiti.cycle.CreateUrlAction;
import org.activiti.cycle.DownloadContentAction;
import org.activiti.cycle.ParameterizedAction;
......@@ -42,6 +43,8 @@ import org.activiti.cycle.RepositoryException;
public class ArtifactTypeImpl implements ArtifactType {
private String id;
private ContentType contentType;
/**
* {@link List} of registered {@link ContentRepresentation}s of this
......@@ -63,8 +66,9 @@ public class ArtifactTypeImpl implements ArtifactType {
private List<DownloadContentAction> downloadContentActions;
public ArtifactTypeImpl(String id) {
public ArtifactTypeImpl(String id, ContentType contentType) {
this.id = id;
this.contentType = contentType;
this.contentRepresentationList = new ArrayList<ContentRepresentation>();
this.contentProviderMap = new HashMap<String, ContentProvider>();
this.parameterizedActions = new ArrayList<ParameterizedAction>();
......@@ -72,10 +76,11 @@ public class ArtifactTypeImpl implements ArtifactType {
this.downloadContentActions = new ArrayList<DownloadContentAction>();
}
public ArtifactTypeImpl(String id, List<ContentRepresentation> contentRepresentationList, ContentRepresentation defaultContentRepresentation,
public ArtifactTypeImpl(String id, ContentType contentType, List<ContentRepresentation> contentRepresentationList, ContentRepresentation defaultContentRepresentation,
Map<String, ContentProvider> contentProviderMap, List<ParameterizedAction> parameterizedActions, List<CreateUrlAction> openUrlActions,
List<DownloadContentAction> downloadContentActions) {
this.id = id;
this.contentType = contentType;
this.contentRepresentationList = contentRepresentationList;
this.defaultContentRepresentation = defaultContentRepresentation;
this.contentProviderMap = contentProviderMap;
......@@ -88,6 +93,10 @@ public class ArtifactTypeImpl implements ArtifactType {
return id;
}
public ContentType getContentType() {
return this.contentType;
}
public ContentRepresentation getContentRepresentation(String id) {
for (ContentRepresentation cr : getContentRepresentations()) {
if (id.equals(cr.getId())) {
......@@ -268,6 +277,10 @@ public class ArtifactTypeImpl implements ArtifactType {
throw new RepositoryException("Action '" + id + "' not found, cannot be executed. Existing actions are: " + actionNames.toString());
}
public void setContentType(ContentType contentType) {
this.contentType = contentType;
}
public void addDefaultContentRepresentation(ContentRepresentation contentRepresentation, ContentProvider provider) {
addContentRepresentation(contentRepresentation, provider);
defaultContentRepresentation = contentRepresentation;
......
......@@ -3,6 +3,7 @@ package org.activiti.cycle.impl;
import java.io.Serializable;
import org.activiti.cycle.ContentRepresentation;
import org.activiti.cycle.ContentType;
/**
* Data structure for link to content, including the URL to the content, the
......@@ -22,11 +23,10 @@ public class ContentRepresentationImpl implements ContentRepresentation, Seriali
private static final long serialVersionUID = 1L;
/**
* type of content as normally indicated by {@link ContentType}
* (e.g. text file, image, ...). Information for the client to render it
* correctly.
* type of content (e.g. text file, image, ...). Information for the client to render
* the content correctly.
*/
private String mimeType;
private ContentType contentType;
/**
* Name of this representation, serves as a <b>unique key</b> to query the
......@@ -35,17 +35,17 @@ public class ContentRepresentationImpl implements ContentRepresentation, Seriali
*/
private String id;
public ContentRepresentationImpl(String id, String mimeType) {
public ContentRepresentationImpl(String id, ContentType contentType) {
super();
this.id = id;
this.mimeType = mimeType;
this.contentType = contentType;
}
public String getId() {
return id;
}
public String getMimeType() {
return mimeType;
public ContentType getContentType() {
return this.contentType;
}
}
......@@ -27,7 +27,7 @@ public class DemoConnectorPluginDefinition implements ActivitiCyclePluginDefinit
public static final String CONTENT_REPRESENTATION_ID_XML = "XML";
public void addArtifactTypes(List<ArtifactType> types) {
ArtifactTypeImpl artifactType1 = new ArtifactTypeImpl(ARTIFACT_TYPE_TEXT);
ArtifactTypeImpl artifactType1 = new ArtifactTypeImpl(ARTIFACT_TYPE_TEXT, ContentType.TEXT);
artifactType1.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_TEXT, ContentType.TEXT), new DemoProvider(
CONTENT_REPRESENTATION_ID_TEXT));
artifactType1.addContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_EXCEPTION, ContentType.TEXT), new ExceptionProvider());
......@@ -36,14 +36,14 @@ public class DemoConnectorPluginDefinition implements ActivitiCyclePluginDefinit
artifactType1.addDownloadContentAction(CONTENT_REPRESENTATION_ID_TEXT);
types.add(artifactType1);
ArtifactTypeImpl artifactType2 = new ArtifactTypeImpl(ARTIFACT_TYPE_MINDMAP);
ArtifactTypeImpl artifactType2 = new ArtifactTypeImpl(ARTIFACT_TYPE_MINDMAP, ContentType.XML);
artifactType2.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_TEXT, ContentType.TEXT), new DemoProvider(
CONTENT_REPRESENTATION_ID_TEXT));
artifactType2.addContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_PNG, ContentType.PNG), new DemoProvider(
CONTENT_REPRESENTATION_ID_PNG));
types.add(artifactType2);
ArtifactTypeImpl artifactType3 = new ArtifactTypeImpl(ARTIFACT_TYPE_BPMN_20);
ArtifactTypeImpl artifactType3 = new ArtifactTypeImpl(ARTIFACT_TYPE_BPMN_20, ContentType.XML);
artifactType3.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_XML, ContentType.TEXT), new DemoProvider(
CONTENT_REPRESENTATION_ID_XML));
artifactType3.addParameterizedAction(new CopyArtifactAction());
......
......@@ -36,48 +36,48 @@ public class FileSystemPluginDefinition implements ActivitiCyclePluginDefinition
// public static final String CONTENT_REPRESENTATION_ID_PDF = "pdf";
public void addArtifactTypes(List<ArtifactType> types) {
ArtifactTypeImpl artifactTypeDefault = new ArtifactTypeImpl(ARTIFACT_TYPE_DEFAULT);
ArtifactTypeImpl artifactTypeDefault = new ArtifactTypeImpl(ARTIFACT_TYPE_DEFAULT, ContentType.TEXT);
artifactTypeDefault.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_BINARY, ContentType.BINARY),
new FileBinaryContentProvider());
artifactTypeDefault.addDownloadContentAction(CONTENT_REPRESENTATION_ID_BINARY);
types.add(artifactTypeDefault);
ArtifactTypeImpl artifactType1 = new ArtifactTypeImpl(ARTIFACT_TYPE_BPMN_20_XML);
ArtifactTypeImpl artifactType1 = new ArtifactTypeImpl(ARTIFACT_TYPE_BPMN_20_XML, ContentType.XML);
artifactType1.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_XML, ContentType.XML), new XmlFileContentProvider());
artifactType1.addDownloadContentAction(CONTENT_REPRESENTATION_ID_XML);
types.add(artifactType1);
ArtifactTypeImpl artifactType2 = new ArtifactTypeImpl(ARTIFACT_TYPE_ORYX_XML);
ArtifactTypeImpl artifactType2 = new ArtifactTypeImpl(ARTIFACT_TYPE_ORYX_XML, ContentType.XML);
artifactType2.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_XML, ContentType.XML), new XmlFileContentProvider());
artifactType2.addDownloadContentAction(CONTENT_REPRESENTATION_ID_XML);
types.add(artifactType2);
ArtifactTypeImpl artifactType3 = new ArtifactTypeImpl(ARTIFACT_TYPE_TEXT);
ArtifactTypeImpl artifactType3 = new ArtifactTypeImpl(ARTIFACT_TYPE_TEXT, ContentType.TEXT);
artifactType3
.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_TEXT, ContentType.TEXT),
new TextFileContentProvider());
artifactType3.addDownloadContentAction(CONTENT_REPRESENTATION_ID_TEXT);
types.add(artifactType3);
ArtifactTypeImpl artifactTypeXml = new ArtifactTypeImpl(ARTIFACT_TYPE_XML);
ArtifactTypeImpl artifactTypeXml = new ArtifactTypeImpl(ARTIFACT_TYPE_XML, ContentType.XML);
artifactTypeXml
.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_XML, ContentType.XML), new XmlFileContentProvider());
artifactTypeXml.addDownloadContentAction(CONTENT_REPRESENTATION_ID_XML);
types.add(artifactTypeXml);
ArtifactTypeImpl artifactType4 = new ArtifactTypeImpl(ARTIFACT_TYPE_MS_WORD);
ArtifactTypeImpl artifactType4 = new ArtifactTypeImpl(ARTIFACT_TYPE_MS_WORD, ContentType.MS_WORD);
artifactType4.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_BINARY, ContentType.MS_WORD),
new FileBinaryContentProvider());
artifactType4.addDownloadContentAction(CONTENT_REPRESENTATION_ID_BINARY);
types.add(artifactType4);
ArtifactTypeImpl artifactType5 = new ArtifactTypeImpl(ARTIFACT_TYPE_MS_PP);
ArtifactTypeImpl artifactType5 = new ArtifactTypeImpl(ARTIFACT_TYPE_MS_PP, ContentType.MS_POWERPOINT);
artifactType5.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_BINARY, ContentType.MS_POWERPOINT),
new FileBinaryContentProvider());
artifactType5.addDownloadContentAction(CONTENT_REPRESENTATION_ID_BINARY);
types.add(artifactType5);
ArtifactTypeImpl artifactType6 = new ArtifactTypeImpl(ARTIFACT_TYPE_PDF);
ArtifactTypeImpl artifactType6 = new ArtifactTypeImpl(ARTIFACT_TYPE_PDF, ContentType.PDF);
artifactType6.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_BINARY, ContentType.PDF),
new FileBinaryContentProvider());
artifactType6.addDownloadContentAction(CONTENT_REPRESENTATION_ID_BINARY);
......
......@@ -59,7 +59,7 @@ public class SignavioPluginDefinition implements ActivitiCyclePluginDefinition {
// SignavioConnector.SIGNAVIO_NAMESPACE_FOR_BPMN_JBPM4));
ArtifactTypeImpl artifactType1 = new ArtifactTypeImpl(ARTIFACT_TYPE_BPMN_20);
ArtifactTypeImpl artifactType1 = new ArtifactTypeImpl(ARTIFACT_TYPE_BPMN_20, ContentType.XML);
artifactType1.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_PNG, ContentType.PNG), new PngProvider());
artifactType1.addContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_BPMN_20_DEVELOPER, ContentType.XML),
new ActivitiCompliantBpmn20Provider());
......@@ -75,7 +75,7 @@ public class SignavioPluginDefinition implements ActivitiCyclePluginDefinition {
types.add(artifactType1);
ArtifactTypeImpl artifactType2 = new ArtifactTypeImpl(ARTIFACT_TYPE_BPMN_FOR_JPDL4);
ArtifactTypeImpl artifactType2 = new ArtifactTypeImpl(ARTIFACT_TYPE_BPMN_FOR_JPDL4, ContentType.XML);
artifactType2.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_PNG, ContentType.PNG), new PngProvider());
artifactType2.addContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_JPDL4, ContentType.XML), new Jpdl4Provider());
artifactType2.addContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_JSON, ContentType.XML), new JsonProvider());
......@@ -89,7 +89,7 @@ public class SignavioPluginDefinition implements ActivitiCyclePluginDefinition {
// initialize RepositoryRegistry with supported formats?
// TODO: Check if really any artifact in Signavio has a PNG?
ArtifactTypeImpl artifactTypeDefault = new ArtifactTypeImpl(ARTIFACT_TYPE_DEFAULT);
ArtifactTypeImpl artifactTypeDefault = new ArtifactTypeImpl(ARTIFACT_TYPE_DEFAULT, ContentType.XML);
artifactTypeDefault.addDefaultContentRepresentation(new ContentRepresentationImpl(CONTENT_REPRESENTATION_ID_PNG, ContentType.PNG), new PngProvider());
types.add(artifactTypeDefault);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册