Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavid_williams2005-07-08 18:48:42 +0000
committerdavid_williams2005-07-08 18:48:42 +0000
commit1742ee1b02068ce09b96d251901581f87d66df81 (patch)
tree5b21875a6ec82fca3de867fc993759f13df1e23d
parent09de8f87754f935349540a9cc6d69259f473cf38 (diff)
downloadwebtools.sourceediting-1742ee1b02068ce09b96d251901581f87d66df81.tar.gz
webtools.sourceediting-1742ee1b02068ce09b96d251901581f87d66df81.tar.xz
webtools.sourceediting-1742ee1b02068ce09b96d251901581f87d66df81.zip
[102070] property files in sse.core/config should be placed in nl fragment
-rw-r--r--bundles/org.eclipse.wst.dtd.core/contentmodel/org/eclipse/wst/dtd/core/internal/contentmodel/CMDocumentEncodingHelper.java87
-rw-r--r--bundles/org.eclipse.wst.dtd.core/contentmodel/org/eclipse/wst/dtd/core/internal/contentmodel/DTDImpl.java5
-rw-r--r--bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/CommonCharsetNames.java70
-rw-r--r--bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/EncodingHelper.java264
-rw-r--r--bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/util/CharsetResourceHandler.java67
-rw-r--r--bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/util/SupportedJavaEncoding.java286
-rw-r--r--bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMDocumentEncodingHelper.java100
-rw-r--r--bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDImpl.java4
8 files changed, 56 insertions, 827 deletions
diff --git a/bundles/org.eclipse.wst.dtd.core/contentmodel/org/eclipse/wst/dtd/core/internal/contentmodel/CMDocumentEncodingHelper.java b/bundles/org.eclipse.wst.dtd.core/contentmodel/org/eclipse/wst/dtd/core/internal/contentmodel/CMDocumentEncodingHelper.java
deleted file mode 100644
index 3731124d0e..0000000000
--- a/bundles/org.eclipse.wst.dtd.core/contentmodel/org/eclipse/wst/dtd/core/internal/contentmodel/CMDocumentEncodingHelper.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.dtd.core.internal.contentmodel;
-
-import java.io.InputStream;
-import java.net.URL;
-
-import org.eclipse.wst.sse.core.internal.encoding.EncodingHelper;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-
-public class CMDocumentEncodingHelper {
- protected static void setEncodingInfo(CMDocument cmDocument, String uri) {
- if (cmDocument != null) {
- uri = addImpliedFileProtocol(uri);
- InputStream inputStream = null;
- try {
- URL url = new URL(uri);
- inputStream = url.openStream();
- String[] encodingInfo = (String[]) cmDocument.getProperty("encodingInfo"); //$NON-NLS-1$
- if (encodingInfo != null) {
- // if (Display.getCurrent() != null)
- // {
- updateFromEncodingHelper(inputStream, encodingInfo);
- // }
- // else
- // {
- // encodingInfo[0] = "UTF8";
- // encodingInfo[1] = "UTF-8";
- // }
- }
- }
- catch (Exception e) {
- }
- finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- }
- catch (Exception e) {
- }
- }
- }
- }
- }
-
- private static void updateFromEncodingHelper(InputStream iStream, String[] encodingInfo) {
- EncodingHelper encodingHelper = new EncodingHelper(iStream);
- encodingInfo[0] = encodingHelper.getEncoding() != null ? encodingHelper.getEncoding() : EncodingHelper.getDefaultEncoding();
- encodingInfo[1] = encodingHelper.getEncodingTag() != null ? encodingHelper.getEncodingTag() : EncodingHelper.getDefaultEncodingTag();
- }
-
-
- // This code is taken from org.eclipse.wst.xml.uriresolver.util.URIHelper
- // I didn't want to add this plugin as a dependency
- // in order to simplify our xerces dependenies
- protected static final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$
- protected static final String PROTOCOL_PATTERN = ":"; //$NON-NLS-1$
-
- public static String addImpliedFileProtocol(String uri) {
- if (!hasProtocol(uri)) {
- uri = FILE_PROTOCOL + uri;
- }
- return uri;
- }
-
- public static boolean hasProtocol(String uri) {
- boolean result = false;
- if (uri != null) {
- int index = uri.indexOf(PROTOCOL_PATTERN);
- if (index != -1 && index > 2) // assume protocol with be length
- // 3 so that the'C' in 'C:/' is
- // not interpreted as a protocol
- {
- result = true;
- }
- }
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.dtd.core/contentmodel/org/eclipse/wst/dtd/core/internal/contentmodel/DTDImpl.java b/bundles/org.eclipse.wst.dtd.core/contentmodel/org/eclipse/wst/dtd/core/internal/contentmodel/DTDImpl.java
index 114b8b328f..75dace7a49 100644
--- a/bundles/org.eclipse.wst.dtd.core/contentmodel/org/eclipse/wst/dtd/core/internal/contentmodel/DTDImpl.java
+++ b/bundles/org.eclipse.wst.dtd.core/contentmodel/org/eclipse/wst/dtd/core/internal/contentmodel/DTDImpl.java
@@ -78,7 +78,10 @@ public class DTDImpl {
public static CMDocument buildCMDocument(String uri) {
DTDFile dtdFile = buildDTDModel(uri);
CMDocument cmDocument = (CMDocument) getAdapter(dtdFile);
- CMDocumentEncodingHelper.setEncodingInfo(cmDocument, uri);
+
+ // This method was accomplishing nothing, so removed.
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=102070
+ //CMDocumentEncodingHelper.setEncodingInfo(cmDocument, uri);
return cmDocument;
}
diff --git a/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/CommonCharsetNames.java b/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/CommonCharsetNames.java
index df09696f4b..10e08f95cc 100644
--- a/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/CommonCharsetNames.java
+++ b/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/CommonCharsetNames.java
@@ -21,14 +21,15 @@ import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Properties;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.wst.sse.core.internal.encoding.util.CharsetResourceHandler;
+import org.eclipse.wst.sse.core.internal.encoding.util.Logger;
import org.osgi.framework.Bundle;
-
/**
* CommonCharsets is a utility class to provide a central place to map some
* IANA charset name to a Java charset name. In 1.4 JRE's this mostly is a
@@ -81,7 +82,8 @@ public final class CommonCharsetNames {
try {
propertiesInputStream = location.openStream();
defaultIANAmappings.load(propertiesInputStream);
- } catch (IOException e) {
+ }
+ catch (IOException e) {
// if can't read, just assume there's no
// default IANA mappings
// and repeated attempts will not occur,
@@ -113,7 +115,8 @@ public final class CommonCharsetNames {
try {
Charset charset = Charset.forName(charsetName);
result = charset.displayName();
- } catch (UnsupportedCharsetException e) {
+ }
+ catch (UnsupportedCharsetException e) {
// if not supported, the display name is
// the least of clients concerns :)
}
@@ -139,9 +142,11 @@ public final class CommonCharsetNames {
if (charset.name() != null) {
preferredName = charset.name();
}
- } catch (IllegalCharsetNameException e) {
+ }
+ catch (IllegalCharsetNameException e) {
// just return input if illegal
- } catch (UnsupportedCharsetException e) {
+ }
+ catch (UnsupportedCharsetException e) {
// just return input if illegal
}
return preferredName;
@@ -160,9 +165,11 @@ public final class CommonCharsetNames {
String guessedName = charsetName;
try {
guessedName = CodedIO.getAppropriateJavaCharset(charsetName);
- } catch (IllegalCharsetNameException e) {
+ }
+ catch (IllegalCharsetNameException e) {
// just ignore if illegal
- } catch (UnsupportedCharsetException e) {
+ }
+ catch (UnsupportedCharsetException e) {
// just ignore if illegal
}
if (getEncodings().contains(guessedName))
@@ -190,23 +197,44 @@ public final class CommonCharsetNames {
supportedEncodingDisplayNames = new Hashtable();
encodings = new ArrayList();
- String totalNumString = CharsetResourceHandler.getString("totalnumber");//$NON-NLS-1$
- int totalNum = 0;
- if (totalNumString.length() != 0) {
- try {
- totalNum = Integer.valueOf(totalNumString).intValue();
+ ResourceBundle bundle = null;
+ InputStream bundleStream = null;
+ try {
+ URL bundleURL = Platform.find(Platform.getBundle(ICodedResourcePlugin.ID), Path.fromOSString("$nl$/config/charset.properties")); //$NON-NLS-1$
+ if (bundleURL != null) {
+ bundleStream = bundleURL.openStream();
+ bundle = new PropertyResourceBundle(bundleStream);
}
- catch (NumberFormatException e) {
- totalNum = 0;
+
+ String totalNumString = bundle.getString("totalnumber");//$NON-NLS-1$
+ int totalNum = 0;
+ if (totalNumString.length() != 0) {
+ try {
+ totalNum = Integer.valueOf(totalNumString).intValue();
+ }
+ catch (NumberFormatException e) {
+ totalNum = 0;
+ }
}
- }
- for (int i = 0; i < totalNum; i++) {
- String iana = CharsetResourceHandler.getString("codeset." + i + ".iana");//$NON-NLS-2$//$NON-NLS-1$
- String displayName = CharsetResourceHandler.getString("codeset." + i + ".label");//$NON-NLS-2$//$NON-NLS-1$
+ for (int i = 0; i < totalNum; i++) {
+ String iana = bundle.getString("codeset." + i + ".iana");//$NON-NLS-2$//$NON-NLS-1$
+ String displayName = bundle.getString("codeset." + i + ".label");//$NON-NLS-2$//$NON-NLS-1$
- encodings.add(iana);
- supportedEncodingDisplayNames.put(iana, displayName);
+ encodings.add(iana);
+ supportedEncodingDisplayNames.put(iana, displayName);
+ }
+ }
+ catch (IOException e) {
+ Logger.logException("invalid install or configuration", e); //$NON-NLS-1$
+ }
+ finally {
+ try {
+ if (bundleStream != null)
+ bundleStream.close();
+ }
+ catch (IOException x) {
+ }
}
}
}
diff --git a/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/EncodingHelper.java b/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/EncodingHelper.java
deleted file mode 100644
index 6aeba07cc6..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/EncodingHelper.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.encoding;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.StringTokenizer;
-
-
-/**
- * EncodingHelper is used to determine the IANA tag / java encoding from the
- * processing instruction. From this processing instruction: <?xml
- * version="1.0" encoding="UTF-8"?>getEncodingTag() would return "UTF-8" and
- * getEncoding() would return UTF8. The processing instruction is searched for
- * via an input stream, or a byte array, depending on the constructor used.
- *
- * @deprecated - users of this class should move to base support: see
- * iFile.getCharset (and related functions with bom detection in
- * IContentDescription
- *
- */
-public class EncodingHelper {
-
- protected static final int encodingNameSearchLimit = 1000;
- protected static final org.eclipse.wst.sse.core.internal.encoding.util.SupportedJavaEncoding javaEncodingConverterHelper = new org.eclipse.wst.sse.core.internal.encoding.util.SupportedJavaEncoding();
-
- /**
- * @deprecated Encoding preferences are stored on a per content type
- * basis. See the EncodingHelper.java class in b2butil for an
- * example of how to extract the default encoding for a given
- * content type.
- */
- static public String getDefaultEncoding() {
- return javaEncodingConverterHelper.getJavaConverterName(getDefaultEncodingTag());
- }
-
- /**
- * @deprecated Encoding preferences are stored on a per content type
- * basis. See the EncodingHelper.java class in b2butil for an
- * example of how to extract the default encoding for a given
- * content type.
- */
- static public String getDefaultEncodingTag() {
- return "UTF-8"; //$NON-NLS-1$
- }
-
- private String encodingName = null;
- private String encodingTag;
-
- /**
- * Method EncodingHelper. Determine the encoding based on the byte array
- * passed in.
- *
- * @param headerBytes
- * @param length
- */
- public EncodingHelper(byte[] headerBytes, int length) {
- determineEncoding(headerBytes, length);
- }
-
- /**
- * Method EncodingHelper. Determine the encoding based on the input
- * stream. Only the first 1000 bytes will be searched
- *
- * @param inStream
- */
- public EncodingHelper(InputStream inStream) {
- determineEncoding(inStream);
- }
-
- private void determineEncoding(byte[] headerBytes, int length) {
- try {
- if (headerBytes.length >= 4) {
- if ((headerBytes[0] == -2) && (headerBytes[1] == -1)) // Byte
- // Order
- // Mark
- // ==
- // 0xFEFF
- {
- // UTF-16, big-endian
- encodingName = "UnicodeBig"; //$NON-NLS-1$
- // encodingTag = "UTF-16";//$NON-NLS-1$
- } else if ((headerBytes[0] == -1) && (headerBytes[1] == -2)) // Byte
- // Order
- // Mark
- // ==
- // 0xFFFE
- {
- // UTF-16, little-endian
- encodingName = "UnicodeLittle"; //$NON-NLS-1$
- // encodingTag = "UTF-16";//$NON-NLS-1$
- } else if ((headerBytes[0] == -17) && (headerBytes[1] == -69) && (headerBytes[2] == -65)) // Byte
- // Order
- // Mark
- // ==
- // 0xEF
- // BB
- // BF
- {
- // UTF-8
- encodingName = "UTF8"; //$NON-NLS-1$
- }
-
- // // Otherwise, we need to check the document's content.
- // // ( UTF-8, US-ASCII, ISO-8859, Shift-JIS, EUC, ... )
- // if ((encodingName != null) && (encodingName.length() == 0))
- // // special
- // {
- // encodingName = getEncodingNameByAuto(smallBuffer,
- // smallBuffer.length);
- // }
- // else
- // XMLEncodingPlugin.getPlugin().getMsgLogger().write("encoding
- // name from BOM = " + encodingName);
- // System.out.println("encoding name from BOM = " +
- // encodingName);
- // Now determine the encoding tag
- encodingTag = getEncodingName(headerBytes, headerBytes.length);
- if (encodingName == null) {
- if (encodingTag != null) {
- encodingName = javaEncodingConverterHelper.getJavaConverterName(encodingTag);
- } else {
- encodingName = "UTF8"; //$NON-NLS-1$
- }
- }
-
- if (encodingTag == null || encodingTag.trim().equals("")) { //$NON-NLS-1$
- encodingTag = javaEncodingConverterHelper.getIANAEncodingName(encodingName);
- }
- // System.out.println("encodingTag = " + encodingTag);
- }
- } catch (UnsupportedEncodingException ex) {
- // if this classn't deprecated, this should not be ignored
- }
- }
-
- protected void determineEncoding(InputStream inStream) {
- try {
- // try and get at least first four bytes for auto encoding
- // detection
- byte[] headerBytes = getBytes(inStream, encodingNameSearchLimit);
- determineEncoding(headerBytes, encodingNameSearchLimit);
- } catch (IOException exception) {
- // if exception, no bytes}
- }
- }
-
- private byte[] getBytes(InputStream inputStream, int max) throws IOException {
- byte[] allHeaderBytes = new byte[max];
- int nRead = inputStream.read(allHeaderBytes, 0, max);
-
- byte[] headerBytes = null;
- if (nRead != max) {
- headerBytes = new byte[nRead];
- System.arraycopy(allHeaderBytes, 0, headerBytes, 0, nRead);
- } else {
- headerBytes = allHeaderBytes;
- }
- return headerBytes;
- }
-
- /**
- * <code>getEncoding</code> Retrieve the java converter name from the
- * document.
- *
- * @return a <code>String</code> value for the java converter
- */
- public String getEncoding() {
- return encodingName;
- }
-
- /**
- * Use the encoding information in the document.
- */
- protected String getEncodingName(byte[] string, int length) throws UnsupportedEncodingException {
- String enc = null;
- enc = getEncodingNameInDocument(string, length);
- return (enc);
- }
-
- protected String getEncodingNameInDocument(byte[] string, int length) throws UnsupportedEncodingException {
- String encoding = null;
- final String content;
- if (encodingName != null) {
- content = new String(string, encodingName);
- } else {
- content = new String(string); // use default Java encoder
- }
-
- String prologTag = "<?xml"; //$NON-NLS-1$
-
- String encodingKeyword = "encoding"; //$NON-NLS-1$
-
- int indexStart = content.indexOf(prologTag);
- if (indexStart != -1) {
- int indexEnd = content.indexOf(">", indexStart); //$NON-NLS-1$
- if (indexEnd != -1) {
- String prolog = content.substring(indexStart, indexEnd);
- int encodingStart = prolog.indexOf(encodingKeyword);
- if (encodingStart != -1) {
- String encodingString = prolog.substring(encodingStart + encodingKeyword.length());
- String delimiter = encodingString.indexOf("'") != -1 ? "'" : "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- StringTokenizer tokenizer = new StringTokenizer(encodingString, delimiter);
- String equalSign = "="; //$NON-NLS-1$
- while (tokenizer.hasMoreElements()) {
- String currToken = tokenizer.nextToken();
- if (currToken.trim().equals(equalSign)) {
- if (tokenizer.hasMoreElements()) {
- encoding = tokenizer.nextToken();
- }
- break;
- }
- }
- }
-
- }
- }
-
- if (encoding != null) {
- final int len = encoding.length();
- if (len > 0) {
- if ((encoding.charAt(0) == '"') && (encoding.charAt(len - 1) == '"')) {
- encoding = encoding.substring(1, len - 1);
- } else if ((encoding.charAt(0) == '\'') && (encoding.charAt(len - 1) == '\'')) {
- encoding = encoding.substring(1, len - 1);
- }
- }
- }
- return encoding;
- }
-
- /**
- * <code>getEncodingTag</code> Retrieve the encoding tag from the
- * document.
- *
- * @return a <code>String</code> value for the encoding tag
- */
- public String getEncodingTag() {
- return encodingTag;
- }
-
- public boolean isSameEncoding(String oldEncoding) {
- if (oldEncoding == null) {
- return false;
- }
-
- if (oldEncoding.equals(getEncoding())) {
- return true;
- }
-
- return false;
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/util/CharsetResourceHandler.java b/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/util/CharsetResourceHandler.java
deleted file mode 100644
index a1bfeead19..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/util/CharsetResourceHandler.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.encoding.util;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.wst.sse.core.internal.encoding.ICodedResourcePlugin;
-
-
-public class CharsetResourceHandler {
- private static ResourceBundle fgResourceBundle;
-
- /**
- * Returns the resource bundle used by all classes in this Project
- */
- public static ResourceBundle getResourceBundle() {
- try {
- URL configURI = Platform.getBundle(ICodedResourcePlugin.ID).getEntry("/"); //$NON-NLS-1$
- String configPathString = configURI + "config/charset"; //$NON-NLS-1$
- return ResourceBundleHelper.getResourceBundle(configPathString);
- }
- catch (MissingResourceException e) {
- Logger.logException("invalid install or configuration", e); //$NON-NLS-1$
- }
- catch (MalformedURLException e) {
- Logger.logException("invalid install or configuration", e); //$NON-NLS-1$
- }
- catch (IOException e) {
- Logger.logException("invalid install or configuration", e); //$NON-NLS-1$
- }
- return null;
- }
-
- public static String getString(String key) {
- String result = null;
- if (fgResourceBundle == null) {
- fgResourceBundle = getResourceBundle();
- }
- if (fgResourceBundle != null) {
- try {
- result = fgResourceBundle.getString(key);
- }
- catch (MissingResourceException e) {
- result = "!" + key + "!";//$NON-NLS-2$//$NON-NLS-1$
- }
- }
- else {
- result = "!" + key + "!";//$NON-NLS-2$//$NON-NLS-1$
- }
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/util/SupportedJavaEncoding.java b/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/util/SupportedJavaEncoding.java
deleted file mode 100644
index 63e32185f2..0000000000
--- a/bundles/org.eclipse.wst.sse.core/src-encoding/org/eclipse/wst/sse/core/internal/encoding/util/SupportedJavaEncoding.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.core.internal.encoding.util;
-
-import java.util.ArrayList;
-import java.util.Hashtable;
-
-/**
- * SupportedJavaEncoding is a utility class to provide IANA tag to java
- * encoding identifier mappings. It also contains the human readable
- * description for the IANA tag equivalent to be used in user interfaces. The
- * description is NL aware based on locale. The data is populated via the
- * charset.properties file only once, based on static initialization of the
- * hashtables.
- *
- * The IANA tags are based on reference information found at the
- * http://www.iana.org site. Specifically see
- * http://www.iana.org/assignments/character-sets
- *
- * @deprecated - hard deprecated. will be removed within days. see
- * CommonCharsetNames may need a similar class to allow
- * "overriding" of default mappings, but JRE 1.4 mappings seem to
- * suffice.
- */
-public class SupportedJavaEncoding {
-
-
- // Pair of supported alias IANA/real IANA names
- private static final String aliases[][] = {
- // the key (1st param) is the alias IANA name, names are case-insensitive
- // the value (2nd param) is the real IANA name, names are
- // case-insensitive
- // Japanese
- {"X-EUC-JP", "EUC-JP"}, //$NON-NLS-2$//$NON-NLS-1$
- {"X-SJIS", "SHIFT_JIS"}, //$NON-NLS-2$//$NON-NLS-1$
- {"ANSI_X3.4-1968", "US-ASCII"}}; //$NON-NLS-1$ //$NON-NLS-2$
- private static ArrayList ianaEncodings = null, javaEncodings = null;
-
- // The following is no longer used. Remove eventually
-
- // Pair of supported IANA/Java Encoding names
- // As for IANA name, see http://www.iana.org/assignments/character-sets
- /**
- * @deprecated - left here temporarily for documentation
- */
- static final String oldEncodings[][] = {
- // the key (1st param) is the XML encoding name, names are
- // case-insensitive
- // the value (2nd param) is the Java encoding name, names are
- // case-sensitive
- // One XML encoding names can be assigned to the one Java
- // Encoding, and
- // everything else needs to be alias. See
- // getIANAEncodingName().
- {"US-ASCII", "ASCII"}, // US ASCII//$NON-NLS-2$//$NON-NLS-1$
- // changed to Cp1252 for MS compatibility
- // {"ISO-8859-1", "ISO8859_1"} // ISO Latin-1
- // ISO Latin-1
- {"ISO-8859-1", "Cp1252"}, //$NON-NLS-2$//$NON-NLS-1$
- // Central/East European (Slavic: Czech, Croat, German,
- // Hungarian, Polish, Romanian, Slovak, Slovenian)
- {"ISO-8859-2", "ISO8859_2"}, //$NON-NLS-2$//$NON-NLS-1$
- // Southern European (Esperanto, Galician, Maltese, Turkish)
- {"ISO-8859-3", "ISO8859_3"}, //$NON-NLS-2$//$NON-NLS-1$
- // Cyrillic (Estonian, Latvian, Lithuanian)
- {"ISO-8859-4", "ISO8859_4"}, //$NON-NLS-2$//$NON-NLS-1$
- // Cyrillic (Bulgarian, Byelorussian, Macedonian, Serbian,
- // Ukrainian)
- {"ISO-8859-5", "ISO8859_5"}, //$NON-NLS-2$//$NON-NLS-1$
- {"ISO-8859-6", "ISO8859_6"}, // Arabic(Logical)//$NON-NLS-2$//$NON-NLS-1$
- {"WINDOWS-1256", "Cp1256"}, // Arabic//$NON-NLS-2$//$NON-NLS-1$
- {"ISO-8859-7", "ISO8859_7"}, // Greek//$NON-NLS-2$//$NON-NLS-1$
- {"ISO-8859-8-I", "ISO8859_8"}, // Hebrew(Logical)//$NON-NLS-2$//$NON-NLS-1$
- // The above is tricky. but in the code conversion point of
- // view,
- // ISO-8 and ISO-8-I are same.
- {"WINDOWS-1255", "Cp1255"}, // Hebrew//$NON-NLS-2$//$NON-NLS-1$
- {"ISO-8859-9", "ISO8859_9"}, // Turkish//$NON-NLS-2$//$NON-NLS-1$
- // Japanese
- // EUC encoding, Japanese
- {"EUC-JP", "EUC_JP"}, //$NON-NLS-2$//$NON-NLS-1$
- // ISO 2022, Japanese
- {"ISO-2022-JP", "ISO2022JP"}, //$NON-NLS-2$//$NON-NLS-1$
- // changed for MS compatibility
- // {"SHIFT_JIS", "SJIS"}, // Shift-JIS, Japanese
- // Shift-JIS, Japanese
- {"SHIFT_JIS", "MS932"}, //$NON-NLS-2$//$NON-NLS-1$
- // Korean
- // changed for MS compatibility
- // {"EUC-KR", "EUC_KR"}, // EUC encoding, Korean
- // EUC encoding, Korean
- {"EUC-KR", "MS949"}, //$NON-NLS-2$//$NON-NLS-1$
- // ISO 2022, Korean
- {"ISO-2022-KR", "ISO2022KR"}, //$NON-NLS-2$//$NON-NLS-1$
- // Traditional Chinese
- // changed for MS compatibility
- // {"BIG5", "Big5"}, // Big5, Traditional Chinese
- // Big5, Traditional Chinese
- {"BIG5", "MS950"}, //$NON-NLS-2$//$NON-NLS-1$
- // Simplified Chinese(Use IANA MIME preferred name)
- // {"GB_2312-80", "GBK"}, // GBK, Simplified Chinese
- // GBK, Simplified Chinese
- {"GB2312", "MS936"}, //$NON-NLS-2$//$NON-NLS-1$
- // GB18030, new Chinese encoding
- {"GB18030", "GB18030"}, //$NON-NLS-1$ //$NON-NLS-2$
- // Thai
- // Thai. Thai Industrial Standards
- // Institute(TISI)
- {"TIS-620", "TIS620"}, //$NON-NLS-2$//$NON-NLS-1$
- // Microsoft Thai
- {"WINDOWS-874", "MS874"}, //$NON-NLS-2$//$NON-NLS-1$
- // Unicode
- // ISO 10646/Unicode, one-byte
- // encoding
- {"UTF-8", "UTF8"}, //$NON-NLS-2$//$NON-NLS-1$
- // ISO 10646/Unicode, two-byte
- // encoding
- {"UTF-16", "UnicodeBig"},//$NON-NLS-2$//$NON-NLS-1$
- // Unicode BigEndian
- {"UTF-16BE", "UnicodeBig"}, //$NON-NLS-2$//$NON-NLS-1$
- // Unicode LittleEndian
- {"UTF-16LE", "UnicodeLittle"} //$NON-NLS-2$//$NON-NLS-1$
- };
- private static Hashtable supportedAliasNames = null;
- private static Hashtable supportedEncodingDisplayNames = null;
- private static Hashtable supportedEncodingNames = null;
- private static Hashtable supportedIANAEncodingNames = null;
-
- /**
- * SupportedJavaEncoding constructor comment.
- */
- public SupportedJavaEncoding() {
- super();
- initHashTables();
- initSupportedAliasNames();
- }
-
- /**
- * Returns display (translated) string for IANA encoding name
- *
- * @param String
- * IANA encoding name
- * @return String translated encoding name from CharsetResourceHandler
- */
- public String getDisplayString(String name) {
- if (name == null)
- return null;
-
- return (String) supportedEncodingDisplayNames.get(name);
- }
-
- /**
- * @return java.lang.String
- * @param iana
- * java.lang.String
- *
- * Convert Java Converter name to IANA encoding Name.
- */
- public String getIANAEncodingName(String javaenc) {
- if (javaenc != null) {
- return ((String) supportedIANAEncodingNames.get(javaenc.toUpperCase()));
- }
- return null;
- }
-
- /**
- * @return java.lang.String
- * @param iana
- * java.lang.String
- *
- * Convert IANA encoding name to Java Converter Name.
- */
- public String getJavaConverterName(String iana) {
- String iana_name = getUniquefromAlias(iana); // to see if iana is
- // an
- // alias
- if (iana_name != null) {
- return ((String) supportedEncodingNames.get(iana_name.toUpperCase()));
- }
- return null;
- }
-
- /**
- * Returns list of all supported IANA encodings
- *
- * @return String[]
- */
- public String[] getSupportedIANAEncodings() {
- String[] iana = new String[ianaEncodings.size()];
- ianaEncodings.toArray(iana);
- return iana;
- }
-
- /**
- * Returns list of all supported Java encodings
- *
- * @return String[]
- */
- public String[] getSupportedJavaEncodings() {
- String[] java = new String[javaEncodings.size()];
- javaEncodings.toArray(java);
- return java;
- }
-
- /**
- * @return java.lang.String unique IANA name
- * @param java.lang.String
- * possibly alias IANA name (ex: x-..)
- */
- public String getUniquefromAlias(String string) {
- String real = null;
- if (string != null) {
- // convert alias IANA(x-...) to 'real' IANA name
- real = (String) supportedAliasNames.get(string.toUpperCase());
- }
- if (real != null)
- return real;
- return string;
- }
-
- private void initHashTables() {
- if (supportedEncodingNames == null) {
- // Initialize hash table for encoding table
- supportedEncodingNames = new Hashtable();
- supportedIANAEncodingNames = new Hashtable();
- supportedEncodingDisplayNames = new Hashtable();
- ianaEncodings = new ArrayList();
- javaEncodings = new ArrayList();
-
- String totalNumString = CharsetResourceHandler.getString("totalnumber");//$NON-NLS-1$
- int totalNum = 0;
- if (totalNumString.length() != 0) {
- totalNum = Integer.valueOf(totalNumString).intValue();
- }
-
- for (int i = 0; i < totalNum; i++) {
- String enc = CharsetResourceHandler.getString("codeset." + i + ".java");//$NON-NLS-2$//$NON-NLS-1$
- String iana = CharsetResourceHandler.getString("codeset." + i + ".iana");//$NON-NLS-2$//$NON-NLS-1$
- String displayName = CharsetResourceHandler.getString("codeset." + i + ".label");//$NON-NLS-2$//$NON-NLS-1$
-
- ianaEncodings.add(iana);
- supportedEncodingNames.put(iana, enc);
- supportedEncodingDisplayNames.put(iana, displayName);
-
- // if ianaenc == UTF-16BE, skip this. Dirty ?
- // agreeed. but...
- if (iana.compareToIgnoreCase("UTF-16BE") != 0)//$NON-NLS-1$
- {
- // note that the same java encoding can be used my
- // multiple iana tags (eg, aliases or codepages that
- // have the same codepoints) thus we only add the first
- // one as that is the most popular
- if (!supportedIANAEncodingNames.containsKey(enc.toUpperCase())) {
- supportedIANAEncodingNames.put(enc.toUpperCase(), iana);
- javaEncodings.add(enc);
- }
- }
- }
- }
- }
-
- /**
- */
- private void initSupportedAliasNames() {
- if (supportedAliasNames == null) {
- supportedAliasNames = new Hashtable();
- int langs = aliases.length;
- for (int i = 0; i < langs; i++) {
- String aliasenc = aliases[i][0];
- String realenc = aliases[i][1];
- supportedAliasNames.put(aliasenc, realenc);
- }
- }
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMDocumentEncodingHelper.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMDocumentEncodingHelper.java
deleted file mode 100644
index 213a919f29..0000000000
--- a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/CMDocumentEncodingHelper.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.xsd.contentmodel.internal;
-
-import java.io.InputStream;
-import java.net.URL;
-
-import org.eclipse.wst.sse.core.internal.encoding.EncodingHelper;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-
-public class CMDocumentEncodingHelper
-{
- protected static void setEncodingInfo(CMDocument cmDocument, String uri)
- {
- if (cmDocument != null)
- {
- uri = addImpliedFileProtocol(uri);
- InputStream inputStream = null;
- try
- {
- URL url = new URL(uri);
- inputStream = url.openStream();
- String[] encodingInfo = (String[])cmDocument.getProperty("encodingInfo");
- if (encodingInfo != null)
- {
- //if (Display.getCurrent() != null)
- //{
- updateFromEncodingHelper(inputStream, encodingInfo);
- //}
- //else
- // {
- // encodingInfo[0] = "UTF8";
- // encodingInfo[1] = "UTF-8";
- // }
- }
- }
- catch (Exception e)
- {
- }
- finally
- {
- if (inputStream != null)
- {
- try
- {
- inputStream.close();
- }
- catch (Exception e)
- {
- }
- }
- }
- }
- }
-
- private static void updateFromEncodingHelper(InputStream iStream, String[] encodingInfo)
- {
- EncodingHelper encodingHelper = new EncodingHelper(iStream);
- encodingInfo[0] = encodingHelper.getEncoding() != null ? encodingHelper.getEncoding() : EncodingHelper.getDefaultEncoding();
- encodingInfo[1] = encodingHelper.getEncodingTag() != null ? encodingHelper.getEncodingTag() : EncodingHelper.getDefaultEncodingTag();
- }
-
-
- // This code is taken from org.eclipse.wst.xml.uriresolver.util.URIHelper
- // I didn't want to add this plugin as a dependency this plugin
- // in order to simplify our xerces dependenies
- protected static final String FILE_PROTOCOL = "file:";
- protected static final String PROTOCOL_PATTERN = ":";
-
- public static String addImpliedFileProtocol(String uri)
- {
- if (!hasProtocol(uri))
- {
- uri = FILE_PROTOCOL + uri;
- }
- return uri;
- }
-
- public static boolean hasProtocol(String uri)
- {
- boolean result = false;
- if (uri != null)
- {
- int index = uri.indexOf(PROTOCOL_PATTERN);
- if (index != -1 && index > 2) // assume protocol with be length 3 so that the'C' in 'C:/' is not interpreted as a protocol
- {
- result = true;
- }
- }
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDImpl.java b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDImpl.java
index 2ef86d2a4e..5971d45fcf 100644
--- a/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDImpl.java
+++ b/bundles/org.eclipse.wst.xsd.core/src-contentmodel/org/eclipse/wst/xsd/contentmodel/internal/XSDImpl.java
@@ -172,7 +172,9 @@ public class XSDImpl
if (xsdSchema != null)
{
cmDocument = (CMDocument) getAdapter(xsdSchema);
- CMDocumentEncodingHelper.setEncodingInfo(cmDocument, uri);
+ // This and related methods were doing nothing, so removed.
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=102070
+ // CMDocumentEncodingHelper.setEncodingInfo(cmDocument, uri);
}
return cmDocument;
}

Back to the top