Author: scabanovich
Date: 2010-09-28 09:49:09 -0400 (Tue, 28 Sep 2010)
New Revision: 25264
Modified:
trunk/struts/plugins/org.jboss.tools.struts/META-INF/MANIFEST.MF
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/model/handlers/page/create/CreatePageSupport.java
Log:
JBIDE-6256
https://jira.jboss.org/browse/JBIDE-6256
Modified: trunk/struts/plugins/org.jboss.tools.struts/META-INF/MANIFEST.MF
===================================================================
--- trunk/struts/plugins/org.jboss.tools.struts/META-INF/MANIFEST.MF 2010-09-28 13:44:59
UTC (rev 25263)
+++ trunk/struts/plugins/org.jboss.tools.struts/META-INF/MANIFEST.MF 2010-09-28 13:49:09
UTC (rev 25264)
@@ -1,59 +1,61 @@
-Manifest-Version: 1.0
-Bundle-Name: %Bundle-Name.0
-Bundle-ClassPath: struts.jar
-Bundle-ActivationPolicy: lazy
-Bundle-Activator: org.jboss.tools.struts.StrutsModelPlugin
-Bundle-Vendor: %providerName
-Bundle-SymbolicName: org.jboss.tools.struts;singleton:=true
-Bundle-Localization: plugin
-Export-Package: org.jboss.tools.common.meta.constraint.impl,
- org.jboss.tools.common.meta.impl.adapters,
- org.jboss.tools.struts,
- org.jboss.tools.struts.gen.java,
- org.jboss.tools.struts.model,
- org.jboss.tools.struts.model.handlers,
- org.jboss.tools.struts.model.handlers.page,
- org.jboss.tools.struts.model.handlers.page.create,
- org.jboss.tools.struts.model.helpers,
- org.jboss.tools.struts.model.helpers.autolayout,
- org.jboss.tools.struts.model.helpers.page,
- org.jboss.tools.struts.model.helpers.page.link,
- org.jboss.tools.struts.model.helpers.path,
- org.jboss.tools.struts.model.icons,
- org.jboss.tools.struts.model.pv,
- org.jboss.tools.struts.model.pv.handler,
- org.jboss.tools.struts.plugins.model,
- org.jboss.tools.struts.plugins.model.handlers,
- org.jboss.tools.struts.tictacktoe,
- org.jboss.tools.struts.tiles.model.handlers,
- org.jboss.tools.struts.validators.model,
- org.jboss.tools.struts.validators.model.handlers,
- org.jboss.tools.struts.validators.model.helpers,
- org.jboss.tools.struts.webprj.model,
- org.jboss.tools.struts.webprj.model.handlers,
- org.jboss.tools.struts.webprj.model.helpers,
- org.jboss.tools.struts.webprj.model.helpers.adopt,
- org.jboss.tools.struts.webprj.model.helpers.context,
- org.jboss.tools.struts.webprj.model.helpers.sync,
- org.jboss.tools.struts.webprj.pattern,
- org.jboss.tools.struts.webprj.resource,
- org.jboss.tools.struts.model.handlers.refactoring,
- org.jboss.tools.struts.messages
-Require-Bundle: org.jboss.tools.common,
- org.eclipse.jdt.core,
- org.jboss.tools.common.model,
- org.jboss.tools.jst.web,
- org.jboss.tools.jst.web.tiles,
- org.eclipse.ui,
- org.eclipse.debug.core,
- org.eclipse.wst.sse.core,
- org.eclipse.wst.xml.core,
- org.jboss.tools.common.projecttemplates,
- org.eclipse.ltk.core.refactoring,
- org.eclipse.ltk.ui.refactoring,
- org.eclipse.core.resources,
- org.eclipse.core.runtime,
- org.apache.velocity;bundle-version="1.5.0"
-Bundle-Version: 3.2.0.qualifier
+Manifest-Version: 1.0
+Bundle-Name: %Bundle-Name.0
+Bundle-ClassPath: struts.jar
+Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.jboss.tools.struts.StrutsModelPlugin
+Bundle-Vendor: %providerName
+Bundle-SymbolicName: org.jboss.tools.struts;singleton:=true
+Bundle-Localization: plugin
+Export-Package: org.jboss.tools.common.meta.constraint.impl,
+ org.jboss.tools.common.meta.impl.adapters,
+ org.jboss.tools.struts,
+ org.jboss.tools.struts.gen.java,
+ org.jboss.tools.struts.model,
+ org.jboss.tools.struts.model.handlers,
+ org.jboss.tools.struts.model.handlers.page,
+ org.jboss.tools.struts.model.handlers.page.create,
+ org.jboss.tools.struts.model.helpers,
+ org.jboss.tools.struts.model.helpers.autolayout,
+ org.jboss.tools.struts.model.helpers.page,
+ org.jboss.tools.struts.model.helpers.page.link,
+ org.jboss.tools.struts.model.helpers.path,
+ org.jboss.tools.struts.model.icons,
+ org.jboss.tools.struts.model.pv,
+ org.jboss.tools.struts.model.pv.handler,
+ org.jboss.tools.struts.plugins.model,
+ org.jboss.tools.struts.plugins.model.handlers,
+ org.jboss.tools.struts.tictacktoe,
+ org.jboss.tools.struts.tiles.model.handlers,
+ org.jboss.tools.struts.validators.model,
+ org.jboss.tools.struts.validators.model.handlers,
+ org.jboss.tools.struts.validators.model.helpers,
+ org.jboss.tools.struts.webprj.model,
+ org.jboss.tools.struts.webprj.model.handlers,
+ org.jboss.tools.struts.webprj.model.helpers,
+ org.jboss.tools.struts.webprj.model.helpers.adopt,
+ org.jboss.tools.struts.webprj.model.helpers.context,
+ org.jboss.tools.struts.webprj.model.helpers.sync,
+ org.jboss.tools.struts.webprj.pattern,
+ org.jboss.tools.struts.webprj.resource,
+ org.jboss.tools.struts.model.handlers.refactoring,
+ org.jboss.tools.struts.messages
+Require-Bundle: org.jboss.tools.common,
+ org.eclipse.jdt.core,
+ org.jboss.tools.common.model,
+ org.jboss.tools.jst.web,
+ org.jboss.tools.jst.web.tiles,
+ org.eclipse.ui,
+ org.eclipse.debug.core,
+ org.eclipse.wst.sse.core,
+ org.eclipse.wst.xml.core,
+ org.jboss.tools.common.projecttemplates,
+ org.eclipse.ltk.core.refactoring,
+ org.eclipse.ltk.ui.refactoring,
+ org.eclipse.core.resources,
+ org.eclipse.core.runtime,
+ org.apache.velocity;bundle-version="1.5.0",
+ org.eclipse.jface.text,
+ org.eclipse.jst.jsp.ui
+Bundle-Version: 3.2.0.qualifier
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Bundle-ManifestVersion: 2
+Bundle-ManifestVersion: 2
Modified:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/model/handlers/page/create/CreatePageSupport.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/model/handlers/page/create/CreatePageSupport.java 2010-09-28
13:44:59 UTC (rev 25263)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/model/handlers/page/create/CreatePageSupport.java 2010-09-28
13:49:09 UTC (rev 25264)
@@ -10,10 +10,21 @@
******************************************************************************/
package org.jboss.tools.struts.model.handlers.page.create;
-import java.io.File;
+import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
+import java.util.TreeMap;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.templates.DocumentTemplateContext;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateBuffer;
+import org.eclipse.jface.text.templates.TemplateContext;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.jface.text.templates.persistence.TemplateStore;
+import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin;
+import org.eclipse.jst.jsp.ui.internal.templates.TemplateContextTypeIdsJSP;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.common.meta.action.XActionInvoker;
@@ -29,10 +40,8 @@
import org.jboss.tools.common.model.undo.XTransactionUndo;
import org.jboss.tools.common.model.undo.XUndoManager;
import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
-import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.struts.StrutsModelPlugin;
import org.jboss.tools.struts.StrutsPreference;
-import org.jboss.tools.struts.StrutsUtils;
import org.jboss.tools.struts.messages.StrutsUIMessages;
import org.jboss.tools.struts.model.helpers.StrutsProcessHelper;
import org.jboss.tools.struts.model.helpers.page.PageUpdateManager;
@@ -41,9 +50,11 @@
static String LAST_CREATE_FILE_PREFERENCE =
"org.jboss.tools.struts.lastCreateFileValue";
static String ATTR_FILE_SYSTEM = "file system";
protected CreatePageContext context = new CreatePageContext();
- protected StrutsUtils templates = new StrutsUtils();
+
String lastCreateFileValue = "true";
+ Map<String, Template> templates = null;
+
public CreatePageSupport() {
context.setSupport(this);
}
@@ -67,8 +78,9 @@
StrutsModelPlugin.getPluginLog().logError("Exception caught in
CreatePageSupport:reset " + e.getMessage(), e);
}
} else {
- templates.updatePageTemplates();
- String[] s = templates.getPageTemplateList();
+ loadTemplates();
+
+ String[] s = templates.keySet().toArray(new String[0]);
setValueList(getStepId(), "template", s);
if(s.length > 0) {
setAttributeValue(getStepId(), "template", getDefaultTemplate(s));
@@ -84,6 +96,39 @@
}
}
+ TemplateStore getTemplateStore() {
+ return JSPUIPlugin.getInstance().getTemplateStore();
+ }
+
+ String getTemplateString(String templateName) {
+ if(templateName == null) return null;
+ String templateString = null;
+
+ Template template = templates.get(templateName);
+ if (template != null) {
+ TemplateContextType contextType
=JSPUIPlugin.getInstance().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsJSP.NEW);
+ IDocument document = new Document();
+ TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
+ try {
+ TemplateBuffer buffer = context.evaluate(template);
+ templateString = buffer.getString();
+ }
+ catch (Exception e) {
+ StrutsModelPlugin.getDefault().logWarning("Could not create template for new
html", e); //$NON-NLS-1$
+ }
+ }
+
+ return templateString;
+ }
+
+ void loadTemplates() {
+ templates = new TreeMap<String, Template>();
+ Template[] ts = getTemplateStore().getTemplates(TemplateContextTypeIdsJSP.NEW);
+ for (Template t: ts) {
+ templates.put(t.getName(), t);
+ }
+ }
+
public void action(String name) throws XModelException {
if(FINISH.equals(name)) {
finish();
@@ -245,14 +290,8 @@
// StrutsModelPlugin.getDefault().getPluginPreferences().setDefault(LAST_CREATE_FILE_PREFERENCE,
lastCreateFileValue);
if(!"true".equals(lastCreateFileValue)) return;
- File templateFile = null;
String template = getAttributeValue(getStepId(), "template").trim();
- if(template.length() > 0) {
- templateFile = (File)templates.getPageTemplates().get(template);
- if(templateFile == null || !templateFile.isFile()) throw new Exception("Template
" + template + " is not found.");
- }
-
- String body = (templateFile == null) ? "" : FileUtil.readFile(templateFile);
+ String body = (template == null) ? "" : getTemplateString(template);;
XModelObject fs = context.getSelectedFileSystem();
if(fs == null) return;
@@ -347,8 +386,8 @@
message = StrutsUIMessages.TEMPLATE_ISNOT_SPECIFIED;
return;
}
- File templateFile = (File)templates.getPageTemplates().get(template.trim());
- if(templateFile == null || !templateFile.isFile()) {
+ String t = getTemplateString(template.trim());
+ if(t == null) {
message = StrutsUIMessages.TEMPLATE_DOESNT_EXIST;
}
}