JBoss Tools SVN: r11616 - workspace/rstryker/event_refactor.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2008-11-07 20:38:20 -0500 (Fri, 07 Nov 2008)
New Revision: 11616
Added:
workspace/rstryker/event_refactor/plugins/
Log:
branching
Copied: workspace/rstryker/event_refactor/plugins (from rev 11615, trunk/as/plugins)
17 years, 5 months
JBoss Tools SVN: r11615 - workspace/rstryker.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2008-11-07 20:36:24 -0500 (Fri, 07 Nov 2008)
New Revision: 11615
Added:
workspace/rstryker/event_refactor/
Log:
branching for new events
17 years, 5 months
JBoss Tools SVN: r11614 - workspace/rstryker.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2008-11-07 20:34:31 -0500 (Fri, 07 Nov 2008)
New Revision: 11614
Removed:
workspace/rstryker/viewRefactor/
Log:
removing old workspace
17 years, 5 months
JBoss Tools SVN: r11612 - trunk/as/plugins/org.jboss.ide.eclipse.as.core.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2008-11-07 19:32:18 -0500 (Fri, 07 Nov 2008)
New Revision: 11612
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
Log:
Cleanup of plugin.xml related to JBIDE-2742
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2008-11-07 17:27:37 UTC (rev 11611)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2008-11-08 00:32:18 UTC (rev 11612)
@@ -504,14 +504,8 @@
</facet>
</default-facets>
</extension>
+
<extension
- point="org.eclipse.jdt.launching.classpathProviders">
- <classpathProvider
- class="org.jboss.ide.eclipse.as.core.server.internal.launch.JBossServerStartupLaunchConfiguration$StartupClasspathProvider"
- id="org.jboss.ide.eclipse.as.core.launch.classpathProvider">
- </classpathProvider>
- </extension>
- <extension
point="org.eclipse.wst.xml.core.catalogContributions">
<catalogContribution>
<public publicId="-//JBoss//DTD JBOSS 4.0//EN"
@@ -563,23 +557,7 @@
<extension
point="org.jboss.ide.eclipse.as.core.publishers">
<publisher
- class="org.jboss.ide.eclipse.as.core.publishers.JstPublisher"
- priority="5">
- </publisher>
- <publisher
class="org.jboss.ide.eclipse.as.core.publishers.SingleFilePublisher"
- priority="5">
- </publisher>
- <publisher
- class="org.jboss.ide.eclipse.as.core.publishers.NullPublisher"
- priority="0">
- </publisher>
- </extension>
-
- <extension
- point="org.jboss.ide.eclipse.as.core.publishers">
- <publisher
- class="org.jboss.ide.eclipse.as.core.publishers.SingleFilePublisher"
priority="7">
</publisher>
<publisher
17 years, 5 months
JBoss Tools SVN: r11611 - trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet.
by jbosstools-commits@lists.jboss.org
Author: dgolovin
Date: 2008-11-07 12:27:37 -0500 (Fri, 07 Nov 2008)
New Revision: 11611
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2669 fixed
JUnit tests were added
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java 2008-11-07 15:21:42 UTC (rev 11610)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java 2008-11-07 17:27:37 UTC (rev 11611)
@@ -22,6 +22,7 @@
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
@@ -143,8 +144,21 @@
final IContainer warLibs = (IContainer) warProject.getProject().findMember("WebContent/WEB-INF/lib").getAdapter(IContainer.class);
assertOnlyContainsTheseFiles(seamgenlibs, warLibs);
+ }
+
+ public void testMvelWarJars() {
+ final IContainer warLibs = (IContainer) warProject.getProject().findMember("WebContent/WEB-INF/lib").getAdapter(IContainer.class);
+ try {
+ for (IResource resource : warLibs.members()) {
+ if(resource.getName().matches("mvel.*\\.jar") ) {
+ return;
+ }
+ }
+ fail("mvel*.jar weren't found in seam 2.0. WAR project");
+ } catch (CoreException e) {
+ fail("Error occured during search mvel libraries in lib folder");
+ }
-
}
public void testEarLibs() throws CoreException {
@@ -208,6 +222,24 @@
assertOnlyContainsTheseFiles(onlyInEjbSrc, (IContainer)ejb.findMember("ejbModule").getAdapter(IContainer.class));
}
+ public void testMvelEarJars() {
+ IProject war = earProject.getProject();
+
+ SeamProjectsSet seamProjectsSet = new SeamProjectsSet(earProject.getProject());
+
+ IProject ear = seamProjectsSet.getEarProject();
+ final IContainer earLibs = (IContainer) ear.findMember("EarContent").getAdapter(IContainer.class);
+ try {
+ for (IResource resource : earLibs.members()) {
+ if(resource.getName().matches("mvel.*\\.jar") ) {
+ return;
+ }
+ }
+ fail("mvel*.jar weren't found in seam 2.0. EAR project");
+ } catch (CoreException e) {
+ fail("Error occured during search mvel libraries in lib folder");
+ }
+ }
/**
* Fails if set of fileNames is not found in dir or some other filename is found in dir.
17 years, 5 months
JBoss Tools SVN: r11610 - in trunk/common/plugins/org.jboss.tools.common.model: src/org/jboss/tools/common/model/filesystems/impl and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-11-07 10:21:42 -0500 (Fri, 07 Nov 2008)
New Revision: 11610
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/Properties_.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model/resources/meta/files.meta
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/PropertiesLoader.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java
Log:
JBIDE-2601
Modified: trunk/common/plugins/org.jboss.tools.common.model/resources/meta/files.meta
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/resources/meta/files.meta 2008-11-07 15:20:06 UTC (rev 11609)
+++ trunk/common/plugins/org.jboss.tools.common.model/resources/meta/files.meta 2008-11-07 15:21:42 UTC (rev 11610)
@@ -291,6 +291,7 @@
visibility="false" xmlname="EXTENSION">
<Editor name="Uneditable"/>
</XModelAttribute>
+ <XModelAttribute name="encoding"/>
</XModelAttributes>
<XActionItem kind="list">
<XActionItem HandlerClassName="%Open%" ICON="main.file.java_file"
Modified: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java 2008-11-07 15:20:06 UTC (rev 11609)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java 2008-11-07 15:21:42 UTC (rev 11610)
@@ -20,6 +20,7 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -39,6 +40,7 @@
import org.jboss.tools.common.model.impl.XModelImpl;
import org.jboss.tools.common.model.loaders.Reloadable;
import org.jboss.tools.common.model.loaders.XObjectLoader;
+import org.jboss.tools.common.model.loaders.impl.PropertiesLoader;
import org.jboss.tools.common.model.util.Paths;
import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
import org.jboss.tools.common.util.FileUtil;
@@ -208,6 +210,10 @@
if(loader != null) {
if(body == null) body = bs.get();
XModelObjectLoaderUtil.setTempBody(c, body);
+ if("FilePROPERTIES".equals(entity) && bs instanceof EclipseFileBodySource) {
+ String encoding = FileUtil.getEncoding(((EclipseFileBodySource)bs).ef);
+ if(encoding != null) c.set("_encoding_", encoding);
+ }
loader.load(c);
} else if(c.getModelEntity().getAttribute("_file") != null) {
c.set("_file", f.getAbsolutePath());
@@ -461,7 +467,7 @@
}
((FolderImpl)o).update();
} else {
- if(!registerFileInPeer(peer, f)) {
+ if(!registerFileInPeer(peer, f) && !isEncodingChanged(o)) {
if(!f.getName().equals(FileAnyImpl.toFileName(o))) {
String n = f.getName();
int i = n.lastIndexOf(".");
@@ -492,7 +498,25 @@
}
}
}
-
+
+ private boolean isEncodingChanged(XModelObject o) {
+ if(o != null && o.getModelEntity().getName().equals("FilePROPERTIES")) {
+ String encoding = o.getAttributeValue("encoding");
+ if(encoding == null) {
+ return false;
+ }
+ String newEncoding = PropertiesLoader.getEncoding(o);
+ if(newEncoding == null) {
+ newEncoding = "8859_1";
+ }
+
+ if(!encoding.equals(newEncoding)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
private int question(File f) {
if(Display.getCurrent() == null) return -100;
return getModel().getService().showDialog("Update",
@@ -538,6 +562,10 @@
XObjectLoader loader = XModelObjectLoaderUtil.getObjectLoader(o);
if(loader != null) {
XModelObjectLoaderUtil.setTempBody(o, bs.get());
+ if("FilePROPERTIES".equals(o.getModelEntity().getName()) && bs instanceof EclipseFileBodySource) {
+ String encoding = FileUtil.getEncoding(((EclipseFileBodySource)bs).ef);
+ if(encoding != null) o.setAttributeValue("encoding", encoding);
+ }
loader.update(o);
} else if(o instanceof Reloadable) {
((Reloadable)o).reload();
@@ -980,20 +1008,21 @@
}
public String get() {
- return XModelObjectLoaderUtil.readFile(f);
+ String encoding = ResourcesPlugin.getEncoding();
+ return FileUtil.readFileWithEncodingCheck(f, encoding);
}
public boolean write(Object object) {
if(!(object instanceof XModelObject)) return false;
XModelObject o = (XModelObject)object;
- return XModelObjectLoaderUtil.saveBody(f, o);
+ return XModelObjectLoaderUtil.saveBody(f, o, ResourcesPlugin.getEncoding());
}
}
class EclipseFileBodySource implements BodySource {
- private IFile ef = null;
- private File f;
+ IFile ef = null;
+ File f;
public EclipseFileBodySource(IFile ef, File f) {
this.ef = ef;
@@ -1001,14 +1030,28 @@
}
public String get() {
- return XModelObjectLoaderUtil.readFile(f);
+ String encoding = null;
+ if(ef != null && ef.exists()) {
+ encoding = FileUtil.getEncoding(ef);
+ }
+ if(encoding == null) {
+ encoding = ResourcesPlugin.getEncoding();
+ }
+ return FileUtil.readFileWithEncodingCheck(f, encoding);
}
public boolean write(Object object) {
if(!(object instanceof XModelObject)) return false;
XModelObject o = (XModelObject)object;
try {
- XModelObjectLoaderUtil.saveBody(f, o);
+ String encoding = null;
+ if(ef != null && ef.exists()) {
+ encoding = FileUtil.getEncoding(ef);
+ }
+ if(encoding == null) {
+ encoding = ResourcesPlugin.getEncoding();
+ }
+ XModelObjectLoaderUtil.saveBody(f, o, encoding);
/*
String r = XModelObjectLoaderUtil.getTempBody(o);
ByteArrayInputStream is = new ByteArrayInputStream(r.getBytes());
Modified: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/PropertiesLoader.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/PropertiesLoader.java 2008-11-07 15:20:06 UTC (rev 11609)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/PropertiesLoader.java 2008-11-07 15:21:42 UTC (rev 11610)
@@ -11,15 +11,21 @@
package org.jboss.tools.common.model.loaders.impl;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*;
+
+import org.eclipse.core.internal.resources.Workspace;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.jboss.tools.common.model.*;
import org.jboss.tools.common.model.loaders.*;
import org.jboss.tools.common.model.plugin.ModelPlugin;
-import org.jboss.tools.common.model.util.*;
+import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
import org.jboss.tools.common.model.impl.*;
import org.jboss.tools.common.meta.XAttribute;
+import org.jboss.tools.common.util.FileUtil;
public class PropertiesLoader implements XObjectLoader {
static String INTERNAL_SEPARATOR = "@";
@@ -27,17 +33,32 @@
public PropertiesLoader() {}
+ public static String getEncoding(XModelObject object) {
+ if(!object.isActive()) {
+ String encoding = object.get("_encoding_");
+ return encoding != null && encoding.length() > 0 ? encoding : "8859_1";
+ }
+ IResource resource = (IResource)object.getAdapter(IResource.class);
+ if(!(resource instanceof IFile)) return null;
+ IFile f = (IFile)resource;
+ return FileUtil.getEncoding(f);
+ }
+
public void load(XModelObject object) {
+ String encoding = getEncoding(object);
+
+ object.setAttributeValue("encoding", encoding);
String body = XModelObjectLoaderUtil.getTempBody(object);
- Properties properties = new Properties();
+ Properties_ properties = new Properties_();
+ properties.setEncoding(encoding);
Properties mapping = new Properties();
try {
- ByteArrayInputStream s = new ByteArrayInputStream(body.getBytes());
+ ByteArrayInputStream s = new ByteArrayInputStream(body.getBytes(encoding));
properties.load(s);
Iterator it = properties.keySet().iterator();
while(it.hasNext()) {
String nm = it.next().toString();
- String sn = convertName(nm);
+ String sn = Properties_.saveConvert(nm, true); // convertName(nm);
mapping.put(sn, nm);
}
} catch (IOException e) {
@@ -123,7 +144,9 @@
}
public boolean update(XModelObject object) throws XModelException {
+ String encoding = getEncoding(object);
XModelObject c = object.copy(0);
+ if(encoding != null) c.set("_encoding_", encoding);
XModelObjectLoaderUtil.setTempBody(c, XModelObjectLoaderUtil.getTempBody(object));
load(c);
////EnginesLoader.merge(object, c, false);
@@ -159,11 +182,11 @@
appendComments(sb, cs[i].get("COMMENTS"), cs[i].get("SEPARATOR"), lineSeparator);
if("no".equals(cs[i].get("ENABLED"))) sb.append('#');
String dirtyname = cs[i].getAttributeValue("dirtyname");
- String name = convertName(cs[i].get("NAME"));
+ String name = Properties_.saveConvert(cs[i].get("NAME"), true); // convertName(cs[i].get("NAME"));
String value = cs[i].get("VALUE");
String dirtyvalue = cs[i].getAttributeValue("dirtyvalue");
if(value == null || dirtyvalue == null || !value.equals(dirtyvalue.trim())) {
- value = convertValue(value);
+ value = Properties_.saveConvert(value, false); // convertValue(value);
}
String resolved = resolveValue(value, dirtyvalue);
//preserve one white space after separator
@@ -274,40 +297,6 @@
if(ch || mod) o1.setModified(true);
}
- private String convertName(String n) {
- Properties p = new Properties();
- p.setProperty(n, "value");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- try {
- p.store(os, null);
- } catch (IOException e) {
- ModelPlugin.getPluginLog().logError(e);
- }
- String q = os.toString();
- int i = q.indexOf("=value");
- q = q.substring(0, i);
- i = q.lastIndexOf('\n');
- if(i >= 0) q = q.substring(i + 1);
- return q.trim();
- }
-
- private String convertValue(String v) {
- Properties p = new Properties();
- p.setProperty("name", v);
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- try {
- p.store(os, null);
- } catch (IOException e) {
- ModelPlugin.getPluginLog().logError(e);
- }
- String q = os.toString();
- int i = q.indexOf("name=");
- q = q.substring(i + 5);
- while(q.endsWith("\n")) q = q.substring(0, q.length() - 1);
- while(q.endsWith("\r")) q = q.substring(0, q.length() - 1);
- return q;
- }
-
private static int getSeparatorIndex(String s) {
String tr = s.trim();
if(tr.length() == 0 || tr.charAt(0) == '#' || tr.charAt(0) == '!') return -1;
Added: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/Properties_.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/Properties_.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/Properties_.java 2008-11-07 15:21:42 UTC (rev 11610)
@@ -0,0 +1,406 @@
+package org.jboss.tools.common.model.loaders.impl;
+
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.jboss.tools.common.CommonPlugin;
+
+public class Properties_ extends Properties {
+ private static final long serialVersionUID = 4112578634029123456L;
+
+ /**
+ * V.K.
+ */
+ private String encoding = "8859_1";
+
+ /**
+ * Creates an empty property list with no default values.
+ */
+ public Properties_() {
+ this(null);
+ }
+
+ /**
+ * Creates an empty property list with the specified defaults.
+ *
+ * @param defaults the defaults.
+ */
+ public Properties_(Properties_ defaults) {
+ super(defaults);
+ }
+
+ /**
+ * V.K
+ * @param encoding
+ */
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ /**
+ *
+ * @param inStream the input stream.
+ * @exception IOException if an error occurred when reading from the
+ * input stream.
+ * @throws IllegalArgumentException if the input stream contains a
+ * malformed Unicode escape sequence.
+ */
+ public synchronized void load(InputStream inStream) throws IOException {
+ char[] convtBuf = new char[1024];
+ LineReader lr = new LineReader(inStream);
+
+ int limit;
+ int keyLen;
+ int valueStart;
+ char c;
+ boolean hasSep;
+ boolean precedingBackslash;
+
+ while ((limit = lr.readLine()) >= 0) {
+ c = 0;
+ keyLen = 0;
+ valueStart = limit;
+ hasSep = false;
+
+ //System.out.println("line=<" + new String(lineBuf, 0, limit) + ">");
+ precedingBackslash = false;
+ while (keyLen < limit) {
+ c = lr.lineBuf[keyLen];
+ //need check if escaped.
+ if ((c == '=' || c == ':') && !precedingBackslash) {
+ valueStart = keyLen + 1;
+ hasSep = true;
+ break;
+ } else if ((c == ' ' || c == '\t' || c == '\f') && !precedingBackslash) {
+ valueStart = keyLen + 1;
+ break;
+ }
+ if (c == '\\') {
+ precedingBackslash = !precedingBackslash;
+ } else {
+ precedingBackslash = false;
+ }
+ keyLen++;
+ }
+ while (valueStart < limit) {
+ c = lr.lineBuf[valueStart];
+ if (c != ' ' && c != '\t' && c != '\f') {
+ if (!hasSep && (c == '=' || c == ':')) {
+ hasSep = true;
+ } else {
+ break;
+ }
+ }
+ valueStart++;
+ }
+ String key = loadConvert(lr.lineBuf, 0, keyLen, convtBuf);
+ String value = loadConvert(lr.lineBuf, valueStart, limit - valueStart, convtBuf);
+ put(key, value);
+ }
+ }
+
+ private String readStream(InputStream is) {
+ StringBuffer sb = new StringBuffer("");
+ try {
+ byte[] b = new byte[4096];
+ while(true) {
+ int l = is.read(b, 0, b.length);
+ if(l < 0) break;
+ sb.append(new String(b, 0, l, encoding));
+ }
+ is.close();
+ } catch (IOException e) {
+ CommonPlugin.getPluginLog().logError(e);
+ }
+ return sb.toString();
+ }
+
+
+ /* read in a "logical line" from input stream, skip all comment and
+ * blank lines and filter out those leading whitespace characters
+ * (\u0020, \u0009 and \u000c) from the beginning of a "natural line".
+ * Method returns the char length of the "logical line" and stores
+ * the line in "lineBuf".
+ */
+ class LineReader {
+ char[] lineBuf = new char[1024];
+ int inOff = 0;
+ int inLimit = 0;
+ String source = null;
+
+ public LineReader(InputStream inStream) {
+ source = readStream(inStream);
+ inLimit = source.length();
+ }
+
+ int readLine() throws IOException {
+ int len = 0;
+ char c = 0;
+
+ boolean skipWhiteSpace = true;
+ boolean isCommentLine = false;
+ boolean isNewLine = true;
+ boolean appendedLineBegin = false;
+ boolean precedingBackslash = false;
+ boolean skipLF = false;
+
+ while (true) {
+ if (inOff >= inLimit) {
+ if (len == 0 || isCommentLine) {
+ return -1;
+ }
+ return len;
+ }
+
+ //V.K.
+ c = source.charAt(inOff++);
+
+ if (skipLF) {
+ skipLF = false;
+ if (c == '\n') {
+ continue;
+ }
+ }
+ if (skipWhiteSpace) {
+ if (c == ' ' || c == '\t' || c == '\f') {
+ continue;
+ }
+ if (!appendedLineBegin && (c == '\r' || c == '\n')) {
+ continue;
+ }
+ skipWhiteSpace = false;
+ appendedLineBegin = false;
+ }
+ if (isNewLine) {
+ isNewLine = false;
+ if (c == '#' || c == '!') {
+ isCommentLine = true;
+ continue;
+ }
+ }
+
+ if (c != '\n' && c != '\r') {
+ lineBuf[len++] = c;
+ if (len == lineBuf.length) {
+ int newLength = lineBuf.length * 2;
+ if (newLength < 0) {
+ newLength = Integer.MAX_VALUE;
+ }
+ char[] buf = new char[newLength];
+ System.arraycopy(lineBuf, 0, buf, 0, lineBuf.length);
+ lineBuf = buf;
+ }
+ //flip the preceding backslash flag
+ if (c == '\\') {
+ precedingBackslash = !precedingBackslash;
+ } else {
+ precedingBackslash = false;
+ }
+ } else {
+ // reached EOL
+ if (isCommentLine || len == 0) {
+ isCommentLine = false;
+ isNewLine = true;
+ skipWhiteSpace = true;
+ len = 0;
+ continue;
+ }
+ if (inOff >= inLimit) {
+ return len;
+ }
+ if (precedingBackslash) {
+ len -= 1;
+ //skip the leading whitespace characters in following line
+ skipWhiteSpace = true;
+ appendedLineBegin = true;
+ precedingBackslash = false;
+ if (c == '\r') {
+ skipLF = true;
+ }
+ } else {
+ return len;
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * Converts encoded \uxxxx to unicode chars
+ * and changes special saved chars to their original forms
+ */
+ private String loadConvert (char[] in, int off, int len, char[] convtBuf) {
+ if (convtBuf.length < len) {
+ int newLen = len * 2;
+ if (newLen < 0) {
+ newLen = Integer.MAX_VALUE;
+ }
+ convtBuf = new char[newLen];
+ }
+ char aChar;
+ char[] out = convtBuf;
+ int outLen = 0;
+ int end = off + len;
+
+ while (off < end) {
+ aChar = in[off++];
+ if (aChar == '\\') {
+ aChar = in[off++];
+ if(aChar == 'u') {
+ // Read the xxxx
+ int value=0;
+ for (int i=0; i<4; i++) {
+ aChar = in[off++];
+ switch (aChar) {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ value = (value << 4) + aChar - '0';
+ break;
+ case 'a': case 'b': case 'c':
+ case 'd': case 'e': case 'f':
+ value = (value << 4) + 10 + aChar - 'a';
+ break;
+ case 'A': case 'B': case 'C':
+ case 'D': case 'E': case 'F':
+ value = (value << 4) + 10 + aChar - 'A';
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Malformed \\uxxxx encoding.");
+ }
+ }
+ out[outLen++] = (char)value;
+ } else {
+ if (aChar == 't') aChar = '\t';
+ else if (aChar == 'r') aChar = '\r';
+ else if (aChar == 'n') aChar = '\n';
+ else if (aChar == 'f') aChar = '\f';
+ out[outLen++] = aChar;
+ }
+ } else {
+ out[outLen++] = (char)aChar;
+ }
+ }
+ return new String (out, 0, outLen);
+ }
+
+ /*
+ * Converts unicodes to encoded \uxxxx and escapes
+ * special characters with a preceding slash
+ */
+ public static String saveConvert(String theString, boolean escapeSpace) {
+ int len = theString.length();
+ int bufLen = len * 2;
+ if (bufLen < 0) {
+ bufLen = Integer.MAX_VALUE;
+ }
+ StringBuffer outBuffer = new StringBuffer(bufLen);
+
+ for(int x=0; x<len; x++) {
+ char aChar = theString.charAt(x);
+ // Handle common case first, selecting largest block that
+ // avoids the specials below
+ if ((aChar > 61) && (aChar < 127)) {
+ if (aChar == '\\') {
+ outBuffer.append('\\'); outBuffer.append('\\');
+ continue;
+ }
+ outBuffer.append(aChar);
+ continue;
+ }
+ switch(aChar) {
+ case ' ':
+ if (x == 0 || escapeSpace)
+ outBuffer.append('\\');
+ outBuffer.append(' ');
+ break;
+ case '\t':outBuffer.append('\\'); outBuffer.append('t');
+ break;
+ case '\n':outBuffer.append('\\'); outBuffer.append('n');
+ break;
+ case '\r':outBuffer.append('\\'); outBuffer.append('r');
+ break;
+ case '\f':outBuffer.append('\\'); outBuffer.append('f');
+ break;
+ case '=': // Fall through
+ case ':': // Fall through
+ case '#': // Fall through
+ case '!':
+ outBuffer.append('\\'); outBuffer.append(aChar);
+ break;
+ default:
+ if ((aChar < 0x0020) || (aChar > 0x007e)) {
+ outBuffer.append('\\');
+ outBuffer.append('u');
+ outBuffer.append(toHex((aChar >> 12) & 0xF));
+ outBuffer.append(toHex((aChar >> 8) & 0xF));
+ outBuffer.append(toHex((aChar >> 4) & 0xF));
+ outBuffer.append(toHex( aChar & 0xF));
+ } else {
+ outBuffer.append(aChar);
+ }
+ }
+ }
+ return outBuffer.toString();
+ }
+
+ public synchronized void store(OutputStream out, String comments)
+ throws IOException
+ {
+ BufferedWriter awriter;
+ awriter = new BufferedWriter(new OutputStreamWriter(out, encoding));
+ if (comments != null)
+ writeln(awriter, "#" + comments);
+ writeln(awriter, "#" + new Date().toString());
+ for (Enumeration e = keys(); e.hasMoreElements();) {
+ String key = (String)e.nextElement();
+ String val = (String)get(key);
+ key = saveConvert(key, true);
+
+ /* No need to escape embedded and trailing spaces for value, hence
+ * pass false to flag.
+ */
+ val = saveConvert(val, false);
+ writeln(awriter, key + "=" + val);
+ }
+ awriter.flush();
+ }
+
+ private static void writeln(BufferedWriter bw, String s) throws IOException {
+ bw.write(s);
+ bw.newLine();
+ }
+
+ /**
+ * Convert a nibble to a hex character
+ * @param nibble the nibble to convert.
+ */
+ private static char toHex(int nibble) {
+ return hexDigit[(nibble & 0xF)];
+ }
+
+ /** A table of hex digits */
+ private static final char[] hexDigit = {
+ '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
+ };
+
+ public static void main(String[] args) {
+ String ps = "p1:v1 \\\n hh \\\n gg\n\np2=v2\\u0034\\u0055";
+ Properties_ p = new Properties_();
+ ByteArrayInputStream s = new ByteArrayInputStream(ps.getBytes());
+ try {
+ p.load(s);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ p.list(System.out);
+ }
+
+}
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-11-07 15:20:06 UTC (rev 11609)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java 2008-11-07 15:21:42 UTC (rev 11610)
@@ -677,7 +677,7 @@
return true;
}
- public static boolean saveBody(File f, XModelObject o) {
+ public static boolean saveBody(File f, XModelObject o, String defaultEncoding) {
boolean same = FileUtil.isSameFile(f);
if(same && !o.isModified()) return true;
String r = getTempBody(o);
@@ -685,7 +685,7 @@
int i = (c) ? 0 : handleReadOnly(f, o);
if(i != 0) return (i == 1);
if(!c) {
- if(!writeFile(f, r)) return false;
+ if(!FileUtil.writeFileWithEncodingCheck(f, r, defaultEncoding)) return false;
}
o.setModified(false);
return true;
17 years, 5 months
JBoss Tools SVN: r11609 - trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-11-07 10:20:06 -0500 (Fri, 07 Nov 2008)
New Revision: 11609
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java
Log:
JBIDE-2601
Modified: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java 2008-11-07 13:33:00 UTC (rev 11608)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java 2008-11-07 15:20:06 UTC (rev 11609)
@@ -41,12 +41,24 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
import org.jboss.tools.common.CommonPlugin;
public final class FileUtil {
public FileUtil() {}
+ public static String getEncoding(IFile f) {
+ String encoding = null;
+ if(f != null && f.exists() && f.isSynchronized(0)) try {
+ encoding = f.getCharset();
+ } catch (CoreException e) {
+ CommonPlugin.getPluginLog().logError(e);
+ }
+ return encoding != null ? encoding : "8859_1";
+ }
+
public static String readFile(File f) {
if(!f.isFile()) return "";
ReadBytes bs = readBytes(f);
@@ -60,6 +72,20 @@
}
}
+ public static String readFileWithEncodingCheck(File f, String defaultEncoding) {
+ if(!f.isFile()) return "";
+ ReadBytes bs = readBytes(f);
+ if(bs == null) return "";
+ String encoding = getEncoding(bs.bs);
+ if(encoding == null) encoding = validateEncoding(defaultEncoding, null);
+ if(encoding == null) return new String(bs.bs, 0, bs.length);
+ try {
+ return new String(bs.bs, 0, bs.length, encoding);
+ } catch (UnsupportedEncodingException e) {
+ return new String(bs.bs, 0, bs.length);
+ }
+ }
+
public static ReadBytes readBytes(File f) {
if(!f.isFile()) return null;
BufferedInputStream br = null;
@@ -158,8 +184,13 @@
}
public static boolean writeFile(File f, String value) {
+ return writeFileWithEncodingCheck(f, value, null);
+ }
+
+ public static boolean writeFileWithEncodingCheck(File f, String value, String defaultEncoding) {
if(value == null) return false;
String encoding = getEncoding(value);
+ if(encoding == null) encoding = validateEncoding(defaultEncoding, null);
if(value.startsWith("<?xml")) {
String s = validateEncoding(encoding, "UTF-8");
if(encoding == null) {
@@ -610,7 +641,7 @@
if(validEncodings.contains(encoding)) return encoding;
if(invalidEncodings.contains(encoding)) return defaultEncoding;
try {
- if(defaultEncoding.equals("UTF-16")) {
+ if(defaultEncoding != null && defaultEncoding.equals("UTF-16")) {
new String(XML_16, 0, XML_16.length, encoding);
} else {
new String(XML_8, 0, XML_8.length, encoding);
17 years, 5 months
JBoss Tools SVN: r11608 - trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2008-11-07 08:33:00 -0500 (Fri, 07 Nov 2008)
New Revision: 11608
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/ValidationErrorManager.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3082 Fixed
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/ValidationErrorManager.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/ValidationErrorManager.java 2008-11-07 10:59:37 UTC (rev 11607)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/ValidationErrorManager.java 2008-11-07 13:33:00 UTC (rev 11608)
@@ -115,7 +115,7 @@
*/
public void addError(String messageId, String preferenceKey,
String[] messageArguments, int length, int offset, IResource target) {
- String preferenceValue = SeamPreferences.getProjectPreference(project, preferenceKey);
+ String preferenceValue = SeamPreferences.getProjectPreference(target.getProject(), preferenceKey);
if(preferenceValue==null && seamProject!=null) {
preferenceValue = SeamPreferences.getProjectPreference(seamProject.getProject(), preferenceKey);
}
17 years, 5 months