Author: scabanovich
Date: 2008-04-07 10:37:09 -0400 (Mon, 07 Apr 2008)
New Revision: 7383
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/ant/model/AntEntityRecognizer.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/ant/parser/AntParser.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/CopyHandler.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FileSystemImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/PromptingProviderFactory.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/FindObjectHelper.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/jst/web/tld/FilePathEncoderFactory.java
Log:
JBIDE-893
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/ant/model/AntEntityRecognizer.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/ant/model/AntEntityRecognizer.java 2008-04-07
14:36:31 UTC (rev 7382)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/ant/model/AntEntityRecognizer.java 2008-04-07
14:37:09 UTC (rev 7383)
@@ -10,17 +10,40 @@
******************************************************************************/
package org.jboss.tools.common.ant.model;
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.eclipse.ant.internal.core.contentDescriber.AntBuildfileContentDescriber;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.content.IContentDescriber;
+import org.eclipse.core.runtime.content.IContentDescription;
+import org.eclipse.core.runtime.content.IContentType;
import org.jboss.tools.common.model.loaders.*;
-import org.jboss.tools.common.ant.parser.*;
+import org.jboss.tools.common.model.plugin.ModelPlugin;
public class AntEntityRecognizer implements EntityRecognizer {
-
+ private static final QualifiedName[] SUPPORTED_OPTIONS = new QualifiedName[]
{IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK};
public AntEntityRecognizer() {}
public String getEntityName(String ext, String body) {
if(body == null) return null;
- AntParser p = new AntParser(body);
- return (p.getTargets() != null) ? "FileANT" : null;
+ IContentType cd =
Platform.getContentTypeManager().getContentType("org.eclipse.ant.core.antBuildFile");
+ AntBuildfileContentDescriber d = new AntBuildfileContentDescriber();
+ int i = -1;
+ try {
+ i = d.describe(new StringReader(body), null);
+ if(i == 2) {
+ IContentDescription aa = cd.getDescriptionFor(new StringReader(body),
SUPPORTED_OPTIONS);
+ System.out.println("aaa");
+ }
+ } catch (IOException e) {
+ ModelPlugin.getPluginLog().logError(e);
+ }
+ return i == 2 ? "FileANT" : null;
+
+// AntParser p = new AntParser(body);
+// return (p.getTargets() != null) ? "FileANT" : null;
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/ant/parser/AntParser.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/ant/parser/AntParser.java 2008-04-07
14:36:31 UTC (rev 7382)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/ant/parser/AntParser.java 2008-04-07
14:37:09 UTC (rev 7383)
@@ -22,8 +22,8 @@
Element element = XMLUtil.getElement(new StringReader(body));
if(element == null) return;
if(!"project".equals(element.getNodeName())) return;
- if(element.getAttributeNode("xmlns") != null) return;
- if(element.getAttributeNode("xsi:schemaLocation") != null) return;
+ if(element.hasAttribute("xmlns")) return;
+ if(element.hasAttribute("xsi:schemaLocation")) return;
NodeList es = element.getElementsByTagName("target");
for (int i = 0; i < es.getLength(); i++)
if(!((Element)es.item(i)).hasAttribute("name")) return;
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/CopyHandler.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/CopyHandler.java 2008-04-07
14:36:31 UTC (rev 7382)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/action/impl/handlers/CopyHandler.java 2008-04-07
14:37:09 UTC (rev 7383)
@@ -25,9 +25,8 @@
static Transfer modelTransfer;
static {
- try {
- modelTransfer =
(Transfer)ModelFeatureFactory.getInstance().createFeatureInstance("org.jboss.tools.common.model.ui.dnd.ModelTransfer");
- } catch (Exception e) {
+ modelTransfer =
(Transfer)ModelFeatureFactory.getInstance().createFeatureInstance("org.jboss.tools.common.model.ui.dnd.ModelTransfer");
+ if(modelTransfer == null) {
ModelPlugin.getPluginLog().logError("Model transfer class not found.");
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FileSystemImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FileSystemImpl.java 2008-04-07
14:36:31 UTC (rev 7382)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FileSystemImpl.java 2008-04-07
14:37:09 UTC (rev 7383)
@@ -66,21 +66,17 @@
if(prloc.toLowerCase().startsWith(thloc.toLowerCase())) return resource = null;
if(thloc.toLowerCase().startsWith(prloc.toLowerCase())) {
String relative = thloc.substring(prloc.length());
- try {
- IFolder f = project.getFolder(new Path(relative));
- if(!f.exists()) {
- try {
- if(f.getParent() != null && f.getParent().exists()) {
- f.create(true, true, null);
- }
- } catch (Exception e) {
- ModelPlugin.getPluginLog().logError(e);
+ IFolder f = project.getFolder(new Path(relative));
+ if(!f.exists()) {
+ try {
+ if(f.getParent() != null && f.getParent().exists()) {
+ f.create(true, true, null);
}
+ } catch (CoreException e) {
+ ModelPlugin.getPluginLog().logError(e);
}
- return resource = f;
- } catch (Exception e) {
- ModelPlugin.getPluginLog().logError(e);
}
+ return resource = f;
}
IFolder f = project.getFolder(new Path("/" +
getAttributeValue("name")));
@@ -88,7 +84,7 @@
try {
f.createLink(new Path(thloc), IFolder.FORCE, null);
resource = f;
- } catch (Exception e) {
+ } catch (CoreException e) {
ModelPlugin.getPluginLog().logError("Cannot create link: " +
e.getMessage());
ModelPlugin.getPluginLog().logError("Project path=" + prloc);
ModelPlugin.getPluginLog().logError(" Link path=" + thloc);
@@ -103,9 +99,10 @@
public String getAbsoluteLocation() {
String s = XModelObjectUtil.getExpandedValue(this, "location", null);
+ if(s == null || s.length() == 0) return s;
try {
return new java.io.File(s).getCanonicalPath();
- } catch (Exception e) {
+ } catch (IOException e) {
//ignore if file does not exist, just use its path
return s;
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/PromptingProviderFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/PromptingProviderFactory.java 2008-04-07
14:36:31 UTC (rev 7382)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/PromptingProviderFactory.java 2008-04-07
14:37:09 UTC (rev 7383)
@@ -18,7 +18,7 @@
static {
try {
WEB =
(IPromptingProvider)ModelFeatureFactory.getInstance().createFeatureInstance("org.jboss.tools.jst.web.project.list.WebPromptingProvider");
- } catch (Exception e) {
+ } catch (ClassCastException e) {
ModelPlugin.getPluginLog().logError(e);
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/FindObjectHelper.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/FindObjectHelper.java 2008-04-07
14:36:31 UTC (rev 7382)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/FindObjectHelper.java 2008-04-07
14:37:09 UTC (rev 7383)
@@ -97,7 +97,7 @@
if(q >= 0) {
try {
line = Integer.parseInt(p.substring(q + 1));
- } catch (Exception e) {
+ } catch (NumberFormatException e) {
//ignore
}
p = p.substring(0, q);
@@ -278,7 +278,7 @@
String sln = text.substring(sc + 1, cb);
try {
ln = Integer.parseInt(sln) - 1;
- } catch (Exception e) {
+ } catch (NumberFormatException e) {
//ignore
}
}
@@ -316,7 +316,7 @@
int j = command.indexOf(':', i + 6);
try {
ln = Integer.parseInt(command.substring(i + 6, j));
- } catch (Exception e) {
+ } catch (NumberFormatException e) {
//ignore
}
String fn = command.substring(0, i);
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java 2008-04-07
14:36:31 UTC (rev 7382)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java 2008-04-07
14:37:09 UTC (rev 7383)
@@ -314,7 +314,7 @@
} else if(o.isActive()) try {
XModelObject q = o.getChildByPath(co.getPathPart());
if(q != null) EnginesLoader.merge(q, co, false);
- } catch (Exception exc) {
+ } catch (XModelException exc) {
ModelPlugin.getPluginLog().logError("XModelObjectLoaderUtil:loadChildren:" +
exc.getMessage(), exc);
}
continue;
@@ -577,13 +577,17 @@
public String asString(XModelObject object) {
StringWriter w = new StringWriter();
+ Exception e = null;
try {
serialize(object, w);
return w.toString();
- } catch (Exception e) {
- ModelPlugin.getPluginLog().logError("XModelObjectLoaderUtil:asString:"
+ e.getMessage(), e);
- return "";
+ } catch (XModelException e1) {
+ e = e1;
+ } catch (IOException e2) {
+ e = e2;
}
+ ModelPlugin.getPluginLog().logError("XModelObjectLoaderUtil:asString:" +
e.getMessage(), e);
+ return "";
}
public static final String getCDATA(Element elem) {
@@ -653,9 +657,15 @@
public boolean save(File f, XModelObject o) {
if(f.exists() && !o.isModified()) return true;
StringWriter w = new StringWriter();
+ Exception e = null;
try {
if(!serialize(o, w)) return false;
- } catch (Exception e) {
+ } catch (XModelException e1) {
+ e = e1;
+ } catch (IOException e2) {
+ e = e2;
+ }
+ if(e != null) {
ModelPlugin.getPluginLog().logError("XModelObjectLoaderUtil:save(f,o):" +
e.getMessage(), e);
return false;
}
@@ -712,12 +722,8 @@
}
public static String readFile(String filename) {
- try {
- return readFile(new File(expandString(filename)));
- } catch (Exception e) {
- ModelPlugin.getPluginLog().logError("XModelObjectLoaderUtil:readFile("
+ filename + "):" + e.getMessage(), e);
- return "";
- }
+ if(filename == null) return "";
+ return readFile(new File(expandString(filename)));
}
public static String readFile(File f) {
@@ -729,12 +735,8 @@
}
public static boolean writeFile(String filename, String value) {
- try {
- return writeFile(new File(expandString(filename)), value);
- } catch (Exception e) {
-
ModelPlugin.getPluginLog().logError("XModelObjectLoaderUtil:writeFile(" +
filename + "):" + e.getMessage(), e);
- return false;
- }
+ if(filename == null) return false;
+ return writeFile(new File(expandString(filename)), value);
}
public static boolean writeFile(File f, String value) {
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/jst/web/tld/FilePathEncoderFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/jst/web/tld/FilePathEncoderFactory.java 2008-04-07
14:36:31 UTC (rev 7382)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/jst/web/tld/FilePathEncoderFactory.java 2008-04-07
14:37:09 UTC (rev 7383)
@@ -21,7 +21,7 @@
static {
try {
jsfEncoder =
(IFilePathEncoder)ModelFeatureFactory.getInstance().createFeatureInstance("org.jboss.tools.jsf.model.helpers.pages.FilePathEncoder");
- } catch (Exception e) {
+ } catch (ClassCastException e) {
ModelPlugin.getPluginLog().logError(e);
}
}