1 /*******************************************************************************
2 * Copyright (c) 2012-2013 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.resources.entitytypes.nodetypes;
14 import java.io.InputStream;
17 import javax.ws.rs.Consumes;
18 import javax.ws.rs.FormParam;
19 import javax.ws.rs.GET;
20 import javax.ws.rs.HeaderParam;
21 import javax.ws.rs.PUT;
22 import javax.ws.rs.Path;
23 import javax.ws.rs.Produces;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import javax.xml.namespace.QName;
28 import org.eclipse.winery.common.constants.QNames;
29 import org.eclipse.winery.common.ids.definitions.NodeTypeId;
30 import org.eclipse.winery.repository.backend.BackendUtils;
31 import org.eclipse.winery.repository.backend.constants.Filename;
32 import org.eclipse.winery.repository.datatypes.ids.elements.VisualAppearanceId;
33 import org.eclipse.winery.repository.resources.GenericVisualAppearanceResource;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 import com.sun.jersey.api.view.Viewable;
38 import com.sun.jersey.multipart.FormDataBodyPart;
39 import com.sun.jersey.multipart.FormDataParam;
41 public class VisualAppearanceResource extends GenericVisualAppearanceResource {
43 private static final Logger logger = LoggerFactory.getLogger(VisualAppearanceResource.class);
46 public VisualAppearanceResource(NodeTypeResource res, Map<QName, String> map, NodeTypeId parentId) {
47 super(res, map, new VisualAppearanceId(parentId));
51 @Produces(MediaType.TEXT_HTML)
52 public Response getHTML() {
53 Viewable viewable = new Viewable("/jsp/entitytypes/nodetypes/visualappearance.jsp", this);
54 return Response.ok().entity(viewable).build();
59 public Response get50x50Image(@HeaderParam("If-Modified-Since") String modified) {
60 return this.getImage(Filename.FILENAME_BIG_ICON, modified);
65 @Consumes(MediaType.MULTIPART_FORM_DATA)
66 public Response post50x50Image(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataBodyPart body) {
67 return this.putImage(Filename.FILENAME_BIG_ICON, uploadedInputStream, body.getMediaType());
72 public String getBorderColor() {
73 return BackendUtils.getColorAndSetDefaultIfNotExisting(this.getId().getParent().getXmlId().getDecoded(), QNames.QNAME_BORDER_COLOR, this.otherAttributes, this.res);
77 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
79 public Response putBorderColor(@FormParam("color") String color) {
80 this.otherAttributes.put(QNames.QNAME_BORDER_COLOR, color);
81 return BackendUtils.persist(this.res);