1 /*******************************************************************************
2 * Copyright (c) 2013 Rene Trefft, Oliver Kopp.
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 * Rene Trefft - initial API and implementation and/or initial documentation
11 * Oliver Kopp - support for getMimeType(name)
12 *******************************************************************************/
13 package org.eclipse.winery.model.csar.toscametafile;
15 import java.io.Serializable;
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.List;
21 import com.springsource.util.parser.manifest.ManifestContents;
24 * Provides structured access to the content of a TOSCA meta file.<br />
26 * Copyright 2013 IAAS University of Stuttgart <br />
29 * @author Rene Trefft - rene.trefft@developers.opentosca.org
32 public class TOSCAMetaFile implements Serializable {
34 private static final long serialVersionUID = 5636441655503533546L;
36 Map<String, String> block0 = new HashMap<String, String>();
37 List<Map<String, String>> fileBlocks = new ArrayList<Map<String, String>>();
41 * Creates a new TOSCA meta file.
43 * @param manifestContent to create from
45 public TOSCAMetaFile(ManifestContents manifestContent) {
46 this.block0 = manifestContent.getMainAttributes();
47 for (String name : manifestContent.getSectionNames()) {
48 Map<String, String> fileBlock = new HashMap<String, String>();
49 fileBlock.put(TOSCAMetaFileAttributes.NAME, name);
50 fileBlock.putAll(manifestContent.getAttributesForSection(name));
51 this.fileBlocks.add(fileBlock);
57 * @return Value of attribute <code>CSAR-Version</code> in block 0.
59 public String getCSARVersion() {
60 return this.block0.get(TOSCAMetaFileAttributes.CSAR_VERSION);
65 * @return Value of attribute <code>TOSCA-Meta-Version</code> in block 0.
67 public String getTOSCAMetaVersion() {
68 return this.block0.get(TOSCAMetaFileAttributes.TOSCA_META_VERSION);
73 * @return Value of attribute <code>Created-By</code> in block 0.
75 public String getCreatedBy() {
76 return this.block0.get(TOSCAMetaFileAttributes.CREATED_BY);
81 * @return Value of attribute <code>Entry-Definitions</code> in block 0
82 * (contains relative path to the root TOSCA file in the CSAR). If
83 * attribute is not specified <code>null</code>.
85 public String getEntryDefinitions() {
86 return this.block0.get(TOSCAMetaFileAttributes.ENTRY_DEFINITIONS);
91 * @return Value of attribute <code>Description</code> in block 0 (contains
92 * description of CSAR). If attribute is not specified
95 public String getDescription() {
96 return this.block0.get(TOSCAMetaFileAttributes.DESCRIPTION);
101 * @return Value of attribute <code>Topology</code> in block 0 (contains
102 * relative path to topology picture in the CSAR). If attribute is
103 * not specified <code>null</code>.
105 public String getTopology() {
106 return this.block0.get(TOSCAMetaFileAttributes.TOPOLOGY);
111 * @return Block 0 (contains meta data about the CSAR itself).
113 public Map<String, String> getBlock0() {
119 * @return File blocks (block 1 to last block; contains meta data of files
120 * in the CSAR). Every block is a element
121 * <code>Map<String, String></code> in the returned
124 public List<Map<String, String>> getFileBlocks() {
125 return this.fileBlocks;
129 * Returns the mime type for the given name
131 * @param name a reference to a file
132 * @return the mime type associated with the given name, null if no mime
135 public String getMimeType(String name) {
137 throw new IllegalArgumentException("name must not be null");
139 for (Map<String, String> map : this.getFileBlocks()) {
140 String storedName = map.get("Name");
141 if (name.equals(storedName)) {
142 // first hit, check whether content-type is stored
143 String contentType = map.get("Content-Type");
144 if (contentType != null) {
145 // hit - return the found content type