2010-11-15 20:35:36 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2016-01-09 12:15:40 +00:00
|
|
|
* (C) Copyright 2009-2017, Arnaud Roques
|
2010-11-15 20:35:36 +00:00
|
|
|
*
|
2016-03-06 16:47:34 +00:00
|
|
|
* Project Info: http://plantuml.com
|
2010-11-15 20:35:36 +00:00
|
|
|
*
|
|
|
|
* This file is part of PlantUML.
|
|
|
|
*
|
|
|
|
* PlantUML is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PlantUML distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
2013-12-10 19:36:50 +00:00
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
2010-11-15 20:35:36 +00:00
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
|
|
|
|
* in the United States and other countries.]
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
2013-12-10 19:36:50 +00:00
|
|
|
* Revision $Revision: 9786 $
|
2010-11-15 20:35:36 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml;
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format for output files generated by PlantUML.
|
|
|
|
*
|
|
|
|
* @author Arnaud Roques
|
|
|
|
*
|
|
|
|
*/
|
2010-11-15 20:35:36 +00:00
|
|
|
public enum FileFormat {
|
2016-04-22 20:36:08 +00:00
|
|
|
PNG, SVG, EPS, EPS_TEXT, ATXT, UTXT, XMI_STANDARD, XMI_STAR, XMI_ARGO, SCXML,
|
2016-03-06 16:47:34 +00:00
|
|
|
PDF, MJPEG, ANIMATED_GIF, HTML, HTML5, VDX, LATEX, LATEX_NO_PREAMBLE, BASE64;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
/**
|
|
|
|
* Returns the file format to be used for that format.
|
|
|
|
*
|
|
|
|
* @return a string starting by a point.
|
|
|
|
*/
|
2010-11-15 20:35:36 +00:00
|
|
|
public String getFileSuffix() {
|
2011-01-05 18:23:06 +00:00
|
|
|
if (name().startsWith("XMI")) {
|
2013-12-10 19:36:50 +00:00
|
|
|
return ".xmi";
|
2011-01-05 18:23:06 +00:00
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
if (this == MJPEG) {
|
|
|
|
return ".avi";
|
|
|
|
}
|
2016-03-06 16:47:34 +00:00
|
|
|
if (this == LATEX_NO_PREAMBLE) {
|
|
|
|
return ".latex";
|
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
if (this == ANIMATED_GIF) {
|
|
|
|
return ".gif";
|
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
if (this == EPS_TEXT) {
|
|
|
|
return EPS.getFileSuffix();
|
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
return "." + StringUtils.goLowerCase(name());
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
/**
|
|
|
|
* Check if this file format is Encapsulated PostScript.
|
|
|
|
*
|
|
|
|
* @return <code>true</code> for EPS.
|
|
|
|
*/
|
2011-08-08 17:48:29 +00:00
|
|
|
public boolean isEps() {
|
|
|
|
if (this == EPS) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (this == EPS_TEXT) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String changeName(String fileName, int cpt) {
|
|
|
|
if (cpt == 0) {
|
2013-12-10 19:36:50 +00:00
|
|
|
return changeName(fileName, getFileSuffix());
|
|
|
|
}
|
|
|
|
return changeName(fileName, "_" + String.format("%03d", cpt) + getFileSuffix());
|
|
|
|
}
|
|
|
|
|
|
|
|
private String changeName(String fileName, String replacement) {
|
|
|
|
String result = fileName.replaceAll("\\.\\w+$", replacement);
|
|
|
|
if (result.equals(fileName)) {
|
|
|
|
result = fileName + replacement;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public File computeFilename(File pngFile, int i) {
|
|
|
|
if (i == 0) {
|
|
|
|
return pngFile;
|
|
|
|
}
|
|
|
|
final File dir = pngFile.getParentFile();
|
|
|
|
return new File(dir, computeFilename(pngFile.getName(), i));
|
|
|
|
// String name = pngFile.getName();
|
|
|
|
// name = name.replaceAll("\\" + getFileSuffix() + "$", "_" + String.format("%03d", i) + getFileSuffix());
|
|
|
|
// return new File(dir, name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public String computeFilename(String name, int i) {
|
|
|
|
if (i == 0) {
|
|
|
|
return name;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
return name.replaceAll("\\" + getFileSuffix() + "$", "_" + String.format("%03d", i) + getFileSuffix());
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|