package controller.upload;
import controller.OSDetails;
import logging.Log;
/**
* Abstract class for Class diagram upload processors. Implements a
* createPngFile() that should be common for Class diagrams.
*
* @author RD2012
*
*/
public abstract class ClassPngFile implements UploadProcessor {
/**
* Generates PNG file.
*
* @param pFileName
* file name which is used for creating the name for the dot and
* png files.
* @param pInFileName
* java file name used to generate the dot and png file. This file should
* be located in the pFileDir path.
* @param pFileDir
* directory containing uploaded files and generated files.
* @param pLibPath
* library path in context which contains UmlGraph-5.6.jar or pic2plot.
*/
public static void createPngFile(String pFileName, String pInFileName,
String pFileDir, String pLibPath) {
try {
String umlGraphPath = pLibPath + "UmlGraph-5.6.jar";
String dotFileName = pFileName + ".dot";
String pngFileName = pFileName + ".png";
// Command to create the dot file from a Java file
String command1[] = { "java", "-jar", umlGraphPath, "-all",
"-private", pFileDir + pInFileName, "-output",
pFileDir + dotFileName };
Process procObj1 = Runtime.getRuntime().exec(command1);
int exitVal = procObj1.waitFor();
if (exitVal != 0) {
Log.LogCreate().Info("Error in creating the dot file");
}
try {
Thread.sleep(1000L);
} catch (Exception e) {
e.printStackTrace();
Log.LogCreate().Info("Error 1: creating dot file failed");
}
// Command to generate PNG file from dot file
String command2[] = { OSDetails.graphvizPath,
"-Tpng", "-o", pFileDir + pngFileName,
pFileDir + dotFileName };
try {
Process procObj = Runtime.getRuntime().exec(command2);
exitVal = procObj.waitFor();
if (exitVal != 0) {
Log.LogCreate().Info("Error in creating the png file");
}
} catch (Exception e) {
e.printStackTrace();
Log.LogCreate().Info("Error 2: generating png file failed");
}
} catch (Exception e) {
Log.LogCreate().Info("Error in creating the png file.............");
e.printStackTrace();
}
}
}