View Javadoc

1   /**********************************************
2    * Copyright (C) 2009 Lukas Laag
3    * This file is part of Vectomatic.
4    * 
5    * Vectomatic is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * Vectomatic is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with Vectomatic.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.common.format;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  /**
24   * Class to represent graphic formats
25   */
26  public class DrawingFormat {
27  	public static final DrawingFormat SVG11 = new DrawingFormat("image/svg+xml", "svg11", ".svg");
28  	public static final DrawingFormat SVG12 = new DrawingFormat("image/svg+xml", "svg12", ".svg");
29  	public static final DrawingFormat PNG = new DrawingFormat("image/png", "png", ".png");
30  	public static final DrawingFormat NATIVE = new DrawingFormat("text/xml", "native", ".xml");
31  	private static Map<String, DrawingFormat> _descriptionToFormat;
32  	static {
33  		_descriptionToFormat = new HashMap<String, DrawingFormat>();
34  		_descriptionToFormat.put(SVG11.getDescription(), SVG11);
35  		_descriptionToFormat.put(SVG12.getDescription(), SVG12);
36  		_descriptionToFormat.put(PNG.getDescription(), PNG);
37  		_descriptionToFormat.put(NATIVE.getDescription(), NATIVE);
38  	}
39  	private String _mimeType;
40  	private String _description;
41  	private String _extension;
42  
43  	private DrawingFormat(String mimeType, String description, String extension) {
44  		_mimeType = mimeType;
45  		_description = description;
46  		_extension = extension;
47  	}
48  	public static DrawingFormat fromDescription(String description) {
49  		return description != null ? _descriptionToFormat.get(description) : null;
50  	}
51  	public String getMimeType() {
52  		return _mimeType;
53  	}
54  	public String getDescription() {
55  		return _description;
56  	}
57  	public String getExtension() {
58  		return _extension;
59  	}
60  }