summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-03-30 14:15:30 (EST)
committer pelder2006-03-30 14:15:30 (EST)
commit28a0fc4bada307c37322148a13a1bf541641f133 (patch)
tree443e258092a381bb2ae92e0a979967f4a9065d43
parent4cf6b31bd6eb237678e6a99ca9135c56562fc5de (diff)
downloadorg.eclipse.jet-28a0fc4bada307c37322148a13a1bf541641f133.zip
org.eclipse.jet-28a0fc4bada307c37322148a13a1bf541641f133.tar.gz
org.eclipse.jet-28a0fc4bada307c37322148a13a1bf541641f133.tar.bz2
[134093] Enabled JET templates to contain and correctly writen all Unicode characters.
-rw-r--r--plugins/org.eclipse.jet/plugin.properties2
-rw-r--r--plugins/org.eclipse.jet/plugin.xml10
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java14
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java64
4 files changed, 53 insertions, 37 deletions
diff --git a/plugins/org.eclipse.jet/plugin.properties b/plugins/org.eclipse.jet/plugin.properties
index dc8092e..0cda437 100644
--- a/plugins/org.eclipse.jet/plugin.properties
+++ b/plugins/org.eclipse.jet/plugin.properties
@@ -30,3 +30,5 @@ tagLibraries.f.name = Standard JET Format Tags
markers.runtimeProblem.name = JET Transform Runtime Problem
markers.compileProblem.name = JET Template Compile Problem
markers.taskmarker.name = Task
+
+contentTypes.template.name = JET Template
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 32a65b7..58cbdc4 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -1153,5 +1153,15 @@ if 'length' is specified, convert only the specified number of characters, other
<super type="org.eclipse.core.resources.taskmarker"/>
<persistent value="true"/>
</extension>
+ <extension
+ point="org.eclipse.core.runtime.contentTypes">
+ <content-type
+ base-type="org.eclipse.core.runtime.text"
+ default-charset="UTF-8"
+ file-extensions="jet"
+ id="template"
+ name="%contentTypes.template.name"
+ priority="normal"/>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java
index ea442cf..b104cb8 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/MethodBodyCreator.java
@@ -178,7 +178,19 @@ public class MethodBodyCreator extends DefaultJET2ASTVisitor
encoded.append("\\\\"); //$NON-NLS-1$
break;
default:
- encoded.append(text[i]);
+ if(text[i] > 127)
+ {
+ String hex = Integer.toHexString(text[i]);
+ encoded.append("\\u"); //$NON-NLS-1$
+ for(int j = hex.length(); j < 4; j++)
+ {
+ encoded.append("0"); //$NON-NLS-1$
+ }
+ encoded.append(hex);
+ }
+ else {
+ encoded.append(text[i]);
+ }
}
}
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 7fb36ab..94d8ab0 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
@@ -28,6 +28,9 @@ import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.text.MessageFormat;
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -112,38 +115,15 @@ public final class ActionsUtil
JET2Messages.WsFileFromWriterAction_WritingFile,
new Object []{ file.getFullPath().toString() });
- monitor.beginTask(fileMessage, 5);
+ monitor.beginTask(fileMessage, 4);
+
if (file.exists() && !replace)
{
return false;
}
- // Step 1: 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);
- }
-
- // Step 2: convert the contents to a byte stream of the proper type
- ByteArrayInputStream source = new ByteArrayInputStream(contents.getBytes(file.getCharset()));
- monitor.worked(1);
-
- // Step 3: ensure containing folder exists...
+ // Step 1: ensure containing folder exists...
if (file.getParent() instanceof IFolder)
{
ensureFolderExists((IFolder)file.getParent(), new SubProgressMonitor(monitor, 1));
@@ -152,26 +132,38 @@ public final class ActionsUtil
{
monitor.worked(1);
}
+ if(!file.exists())
+ {
+ file.create(new ByteArrayInputStream(new byte [0]), false, new SubProgressMonitor(monitor, 1));
+ }
- // Step 4: write the contents
- if (file.exists())
+ final ITextFileBufferManager mgr = FileBuffers.getTextFileBufferManager();
+
+ // Step 2: connect to the file manager, set the contents and the encoding...
+ mgr.connect(file.getLocation(), new SubProgressMonitor(monitor, 1));
+ try
{
- file.setContents(source, false, true, new SubProgressMonitor(monitor, 2));
+ final ITextFileBuffer textFileBuffer = mgr.getTextFileBuffer(file.getLocation());
+
+ textFileBuffer.getDocument().set(contents);
+
+ if (encoding != null)
+ {
+ textFileBuffer.setEncoding(encoding);
+ }
+
+ textFileBuffer.commit(new SubProgressMonitor(monitor, 1), false);
}
- else
+ finally
{
- file.create(source, false, new SubProgressMonitor(monitor, 1));
+ mgr.disconnect(file.getLocation(), new SubProgressMonitor(monitor, 1));
}
- // RuntimeLoggerContextExtender.log(context, fileMessage, tagInfo, templatePath);
+
// Step 5: Apply generated file properties...
file.setDerived(derived);
return true;
}
- catch (UnsupportedEncodingException e)
- {
- throw new JET2TagException(e);
- }
catch (CoreException e)
{
throw new JET2TagException(e);