aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2013-01-31 01:14:26 (EST)
committerzzhongwei2013-01-31 01:18:09 (EST)
commit961745e2cbe925a059e1271b28ba520b69e8f2fa (patch)
tree9e5717292a9901ca7959aec723d53d7bba318f39
parentf5aeb8aeb1dec16ad062c914b728ba82bc7ceed2 (diff)
downloadorg.eclipse.pdt-961745e2cbe925a059e1271b28ba520b69e8f2fa.zip
org.eclipse.pdt-961745e2cbe925a059e1271b28ba520b69e8f2fa.tar.gz
org.eclipse.pdt-961745e2cbe925a059e1271b28ba520b69e8f2fa.tar.bz2
357650: broken special chars in PHP code templates
https://bugs.eclipse.org/bugs/show_bug.cgi?id=357650
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPFileCreationWizard.java25
1 files changed, 22 insertions, 3 deletions
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPFileCreationWizard.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPFileCreationWizard.java
index f96c69f..fbcd5e3 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPFileCreationWizard.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPFileCreationWizard.java
@@ -14,6 +14,7 @@ package org.eclipse.php.internal.ui.wizards;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.*;
@@ -195,7 +196,8 @@ public class PHPFileCreationWizard extends Wizard implements INewWizard {
}
try {
- InputStream stream = openContentStream(contents);
+ InputStream stream = openContentStream(contents,
+ getCharSetValue(container));
if (file.exists()) {
file.setContents(stream, true, true, monitor);
} else {
@@ -248,12 +250,29 @@ public class PHPFileCreationWizard extends Wizard implements INewWizard {
/**
* We will initialize file contents with a sample text.
*/
- private static InputStream openContentStream(String contents) {
+ private static InputStream openContentStream(String contents,
+ String charSet) {
if (contents == null) {
contents = ""; //$NON-NLS-1$
}
+ byte[] bytes;
+ try {
+ bytes = contents.getBytes(charSet);
+ } catch (UnsupportedEncodingException e) {
+ bytes = contents.getBytes();
+ }
+
+ return new ByteArrayInputStream(bytes);
+ }
+
+ protected String getCharSetValue(IContainer container) {
+ try {
+ return container.getDefaultCharset(true);
+ } catch (CoreException e) {// If there is an error return the
+ // default
+ return WorkbenchEncoding.getWorkbenchDefaultEncoding();
+ }
- return new ByteArrayInputStream(contents.getBytes());
}
private static void throwCoreException(String message)