protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
Document doc = (Document) _doc.clone();
String profileName = request.getParameter("profile");
IDiagramProfile profile = _profileService.findProfile(
request, profileName);
if (profile == null) {
_logger.error("No profile with the name " + profileName
+ " was registered");
throw new IllegalArgumentException(
"No profile with the name " + profileName +
" was registered");
}
//output env javascript files
if (System.getProperty(DEV) != null) {
for (String jsFile : _envFiles) {
addScript(doc, wapama_path + jsFile, true);
}
} else {
addScript(doc, wapama_path + "jsc/env_combined.js", true);
}
// get language from cookie
String lang = null;
Cookie[] cookies = request.getCookies();
for (Cookie cookie : cookies) {
if ("locale".equals(cookie.getName())) {
lang = cookie.getValue().trim();
break;
}
}
// i18n message resource file name
String i18nJsFile = null;
if ("de_DE".equals(lang)) {
i18nJsFile = "i18n/translation_de.js";
} else if ("ru".equals(lang)){
i18nJsFile = "i18n/translation_ru.js";
} else if ("es".equals(lang)){
i18nJsFile = "i18n/translation_es.js";
} else if ("ja_JP".equals(lang)){
i18nJsFile = "i18n/translation_ja.js";
} else {
i18nJsFile = "i18n/translation_en_us.js";
}
// generate script to setup the languages
addScript(doc, wapama_path + i18nJsFile, true);
// generate script tags for plugins.
// they are located after the initialization script.
if (_pluginfiles.get(profileName) == null) {
List<IDiagramPlugin> compressed = new ArrayList<IDiagramPlugin>();
List<IDiagramPlugin> uncompressed = new ArrayList<IDiagramPlugin>();
_pluginfiles.put(profileName, compressed);
_uncompressedPlugins.put(profileName, uncompressed);
for (String pluginName : profile.getPlugins()) {
IDiagramPlugin plugin = _pluginService.findPlugin(request,
pluginName);
if (plugin == null) {
_logger.warn("Could not find the plugin " + pluginName +
" requested by the profile " + profile.getName());
continue;
}
if (plugin.isCompressable()) {
compressed.add(plugin);
} else {
uncompressed.add(plugin);
}
}
if (System.getProperty(DEV) == null) {
// let's call the compression routine
String rs = compressJS(_pluginfiles.get(profileName),
getServletContext());
try {
FileWriter w = new FileWriter(getServletContext().
getRealPath("jsc/plugins_" + profileName
+ ".js"));
w.write(rs.toString());
w.close();
} catch (Exception e) {
_logger.error(e.getMessage(), e);
}
}
}
if (System.getProperty(DEV) != null) {
for (IDiagramPlugin jsFile : _pluginfiles.get(profileName)) {
addScript(doc, wapama_path + "plugin/" + jsFile.getName()
+ ".js", true);
}
} else {
addScript(doc,
wapama_path + "jsc/plugins_" + profileName + ".js",
false);
}
for (IDiagramPlugin uncompressed :
_uncompressedPlugins.get(profileName)) {
addScript(doc, wapama_path + "plugin/" + uncompressed.getName()
+ ".js", false);
}
// send the updated editor.html to client
if(!isIE(request)){
response.setContentType("application/xhtml+xml");
}
XMLOutputter outputter = new XMLOutputter();
Format format = Format.getPrettyFormat();
format.setExpandEmptyElements(true);
outputter.setFormat(format);
String html = outputter.outputString(doc);
StringTokenizer tokenizer = new StringTokenizer(
html, "@", true);
StringBuilder resultHtml = new StringBuilder();
boolean tokenFound = false;
boolean replacementMade = false;
IDiagramPreference pref = PREFERENCE_FACTORY.createPreference(request);
int autoSaveInt = pref.getAutosaveInterval();
boolean autoSaveOn = pref.isAutoSaveEnabled();
while(tokenizer.hasMoreTokens()) {
String elt = tokenizer.nextToken();
if ("title".equals(elt)) {
resultHtml.append(profile.getTitle());
replacementMade = true;
} else if ("stencilset".equals(elt)) {
resultHtml.append(profile.getStencilSet());
replacementMade = true;
} else if ("debug".equals(elt)) {
resultHtml.append(System.getProperty(DEV) != null);
replacementMade = true;
} else if ("autosaveinterval".equals(elt)) {
resultHtml.append(autoSaveInt);
replacementMade = true;
} else if ("autosavedefault".equals(elt)) {
resultHtml.append(autoSaveOn);
replacementMade = true;
} else if ("profileplugins".equals(elt)) {
StringBuilder plugins = new StringBuilder();
boolean commaNeeded = false;
for (String ext : profile.getPlugins()) {
if (commaNeeded) {
plugins.append(",");
} else {
commaNeeded = true;
}
plugins.append("\"").append(ext).append("\"");
}
resultHtml.append(plugins.toString());
replacementMade = true;
} else if ("ssextensions".equals(elt)) {
StringBuilder ssexts = new StringBuilder();
boolean commaNeeded = false;
for (String ext : profile.getStencilSetExtensions()) {
if (commaNeeded) {
ssexts.append(",");
} else {
commaNeeded = true;
}