summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-04-07 21:14:43 (EDT)
committer pelder2006-04-07 21:14:43 (EDT)
commitb7d35798cea349b20e750ee89662c758cc9c648f (patch)
tree0170c33fcdd2876ea3921a4b3f564e505df3f858
parente9ce42804d0297a373600fb66b01d08a7243f34e (diff)
downloadorg.eclipse.jet-b7d35798cea349b20e750ee89662c758cc9c648f.zip
org.eclipse.jet-b7d35798cea349b20e750ee89662c758cc9c648f.tar.gz
org.eclipse.jet-b7d35798cea349b20e750ee89662c758cc9c648f.tar.bz2
[134583] File must be written before you can check it's default encoding - essential for writing UTF-8 BOMs.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java44
1 files changed, 20 insertions, 24 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
index 37894c9..3284a93 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
@@ -124,28 +124,30 @@ public final class ActionsUtil
{
return false;
}
+
+ // Step 1: make sure file exists - necessary for proper encoding handling...
+ if (!file.exists())
+ {
+ // can't set encoding until the file exists, create the file with null-contents
+ // now, and set it's contents later.
+ file.create(new ByteArrayInputStream(new byte [0]), false, new SubProgressMonitor(monitor, 1));
+ }
+ else
+ {
+ monitor.worked(1);
+ }
- // Step 1: set the encoding...
+ // Step 2: set the encoding...
if (encoding != null)
{
- if (!file.exists())
- {
- // can't set encoding until the file exists, create the file with null-contents
- // now, and set it's contents later.
- file.create(new ByteArrayInputStream(new byte [0]), false, new SubProgressMonitor(monitor, 1));
- }
- else
- {
- monitor.worked(1);
- }
file.setCharset(encoding.length() > 0 ? encoding : null, new SubProgressMonitor(monitor, 1));
}
else
{
- monitor.worked(2);
+ monitor.worked(1);
}
- // Step 2: convert the contents to a byte stream of the proper type
+ // Step 3: convert the contents to a byte stream of the proper type
InputStream source = new ByteArrayInputStream(contents.getBytes(file.getCharset()));
// work around SUN bug with UTF-8 encoding and byte-order marks.
@@ -155,7 +157,7 @@ public final class ActionsUtil
}
monitor.worked(1);
- // Step 3: ensure containing folder exists...
+ // Step 4: ensure containing folder exists...
if (file.getParent() instanceof IFolder)
{
ensureFolderExists((IFolder)file.getParent(), new SubProgressMonitor(monitor, 1));
@@ -165,17 +167,11 @@ public final class ActionsUtil
monitor.worked(1);
}
- // Step 4: write the contents
- if (file.exists())
- {
- file.setContents(source, false, true, new SubProgressMonitor(monitor, 2));
- }
- else
- {
- file.create(source, false, new SubProgressMonitor(monitor, 1));
- }
+ // Step 5: write the contents - we created the file in step 1, so we only need to set its proper contents
+ file.setContents(source, false, true, new SubProgressMonitor(monitor, 2));
+
// RuntimeLoggerContextExtender.log(context, fileMessage, tagInfo, templatePath);
- // Step 5: Apply generated file properties...
+ // Step 6: Apply generated file properties...
file.setDerived(derived);
return true;