Author: dmaliarevich
Date: 2011-06-23 09:49:58 -0400 (Thu, 23 Jun 2011)
New Revision: 32315
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java
Log:
https://issues.jboss.org/browse/JBIDE-9203 , \t\r\n -- escaped, non-ascii relaced by
\uXXXX
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java 2011-06-23
13:17:57 UTC (rev 32314)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java 2011-06-23
13:49:58 UTC (rev 32315)
@@ -17,6 +17,8 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -95,10 +97,12 @@
*/
public class ExternalizeStringsUtils {
+ public static final String NONAME = "noname"; //$NON-NLS-1$
public static final char[] REPLACED_CHARACTERS = new char[] {'~', '!',
'@', '#',
'$', '%', '^', '&', '*', '(',
')', '-', '+', '=', '{', '}', '[',
']', ':', ';', ',', '.', '?',
'\\', '/', '"', '\''};
public static final char[] LINE_DELEMITERS = new char[] {'\r', '\n',
'\t'};
-
+ private static CharsetEncoder asciiEncoder;
+
/**
* Checks that the user has selected a correct string.
*
@@ -340,11 +344,7 @@
} finally {
in = null;
}
-
- } else {
- JspEditorPlugin.getDefault().logError(
- "Bundle File '" + propertiesFile + "' does not
exist!"); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ }
return properties;
}
@@ -377,9 +377,6 @@
} finally {
fr = null;
}
- } else {
- JspEditorPlugin.getDefault().logError(
- "Bundle File '" + propertiesFile + "' does not exist!");
//$NON-NLS-1$ //$NON-NLS-2$
}
return properties;
}
@@ -434,6 +431,17 @@
* @return the result string
*/
public static String generatePropertyKey(String text) {
+ /*
+ * If text cannot be represented in standard eclipse encoding
+ * change the key name to "noname"
+ */
+ if (null == asciiEncoder) {
+ asciiEncoder = Charset.forName("ISO-8859-1").newEncoder(); //$NON-NLS-1$
+ }
+ if (!asciiEncoder.canEncode(text)) {
+ text = NONAME;
+ }
+
String result = text.trim();
/*
* Update text string field.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java 2011-06-23
13:17:57 UTC (rev 32314)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java 2011-06-23
13:49:58 UTC (rev 32315)
@@ -45,6 +45,7 @@
import org.eclipse.swt.widgets.Text;
import org.eclipse.wst.xml.core.internal.document.AttrImpl;
import org.eclipse.wst.xml.core.internal.document.TextImpl;
+import org.jboss.tools.common.model.loaders.impl.EncodedProperties;
import org.jboss.tools.common.model.ui.ModelUIImages;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.bundle.BundleMap;
@@ -384,8 +385,13 @@
text = stringToUpdate;
}
}
- propsValue.setText(text);
+ /*
+ *
https://issues.jboss.org/browse/JBIDE-9203
+ * Replace special characters with their string representation.
+ * Key should be generated first.
+ */
propsKey.setText(ExternalizeStringsUtils.generatePropertyKey(text));
+ propsValue.setText(EncodedProperties.saveConvert(text, true));
/*
* Initialize bundle messages field
*/