Lines 19-28
Link Here
|
19 |
import java.util.Enumeration; |
19 |
import java.util.Enumeration; |
20 |
import java.util.HashMap; |
20 |
import java.util.HashMap; |
21 |
import java.util.Date; |
21 |
import java.util.Date; |
|
|
22 |
import java.util.Locale; |
22 |
import java.beans.PropertyChangeListener; |
23 |
import java.beans.PropertyChangeListener; |
23 |
import java.beans.PropertyChangeEvent; |
24 |
import java.beans.PropertyChangeEvent; |
24 |
import java.io.IOException; |
25 |
import java.io.IOException; |
25 |
import java.io.File; |
26 |
import java.io.File; |
|
|
27 |
import java.nio.charset.Charset; |
28 |
import javax.swing.text.BadLocationException; |
29 |
import javax.swing.text.StyledDocument; |
26 |
|
30 |
|
27 |
import org.openide.*; |
31 |
import org.openide.*; |
28 |
import org.openide.cookies.EditorCookie; |
32 |
import org.openide.cookies.EditorCookie; |
Lines 71-77
Link Here
|
71 |
|
75 |
|
72 |
public static final String EA_CONTENT_LANGUAGE = "AttrJSPContentLanguage"; // NOI18N |
76 |
public static final String EA_CONTENT_LANGUAGE = "AttrJSPContentLanguage"; // NOI18N |
73 |
public static final String EA_SCRIPTING_LANGUAGE = "AttrJSPScriptingLanguage"; // NOI18N |
77 |
public static final String EA_SCRIPTING_LANGUAGE = "AttrJSPScriptingLanguage"; // NOI18N |
74 |
// public static final String EA_ENCODING = "AttrEncoding"; // NOI18N |
|
|
75 |
public static final String EA_JSP_ERRORPAGE = "jsp_errorpage"; // NOI18N |
78 |
public static final String EA_JSP_ERRORPAGE = "jsp_errorpage"; // NOI18N |
76 |
// property for the servlet dataobject corresponding to this page |
79 |
// property for the servlet dataobject corresponding to this page |
77 |
public static final String PROP_SERVLET_DATAOBJECT = "servlet_do"; // NOI18N |
80 |
public static final String PROP_SERVLET_DATAOBJECT = "servlet_do"; // NOI18N |
Lines 673-690
Link Here
|
673 |
firePropertyChange(PROP_SCRIPTING_LANGUAGE, null, scriptingLanguage); |
676 |
firePropertyChange(PROP_SCRIPTING_LANGUAGE, null, scriptingLanguage); |
674 |
} |
677 |
} |
675 |
|
678 |
|
676 |
/* public String getEncoding() { |
|
|
677 |
try { |
678 |
String encoding = (String)getPrimaryFile ().getAttribute (EA_ENCODING); |
679 |
if (encoding != null) { |
680 |
return encoding; |
681 |
} |
682 |
} catch (Exception ex) { |
683 |
// null pointer or IOException |
684 |
} |
685 |
return getDefaultEncoding(); |
686 |
}*/ |
687 |
|
688 |
/** Gets the raw encoding from the fileobject, |
679 |
/** Gets the raw encoding from the fileobject, |
689 |
* ensures beckward compatibility. |
680 |
* ensures beckward compatibility. |
690 |
**/ |
681 |
**/ |
Lines 707-714
Link Here
|
707 |
|
698 |
|
708 |
|
699 |
|
709 |
public static String getDefaultEncoding() { |
700 |
public static String getDefaultEncoding() { |
710 |
String language = System.getProperty("user.language"); |
701 |
String language = Locale.getDefault().getLanguage(); |
711 |
if ("ja".equals(language)) { // NOI18N |
702 |
if (language.startsWith("en")) { |
|
|
703 |
// we are English |
704 |
return "ISO-8859-1"; // NOI18N |
705 |
// per JSP 1.2 specification, the default encoding is always ISO-8859-1, |
706 |
// regardless of the setting of the file.encoding property |
707 |
//return System.getProperty("file.encoding", "ISO-8859-1"); |
708 |
} |
709 |
return canonizeEncoding(System.getProperty("file.encoding", "ISO-8859-1")); |
710 |
|
711 |
/* if ("ja".equals(language)) { // NOI18N |
712 |
// we are Japanese |
712 |
// we are Japanese |
713 |
if (org.openide.util.Utilities.isUnix()) |
713 |
if (org.openide.util.Utilities.isUnix()) |
714 |
return "EUC-JP"; // NOI18N |
714 |
return "EUC-JP"; // NOI18N |
Lines 717-733
Link Here
|
717 |
} |
717 |
} |
718 |
else |
718 |
else |
719 |
// we are English |
719 |
// we are English |
720 |
return "ISO-8859-1"; // NOI18N |
720 |
return "ISO-8859-1"; // NOI18N*/ |
721 |
// per JSP 1.2 specification, the default encoding is always ISO-8859-1, |
|
|
722 |
// regardless of the setting of the file.encoding property |
723 |
//return System.getProperty("file.encoding", "ISO-8859-1"); |
724 |
} |
721 |
} |
725 |
|
|
|
726 |
/* public void setEncoding(String encoding) throws IOException { |
727 |
getPrimaryFile ().setAttribute (EA_ENCODING, encoding); |
728 |
firePropertyChange(PROP_ENCODING, null, encoding); |
729 |
} */ |
730 |
|
722 |
|
|
|
723 |
private static final String CORRECT_WINDOWS_31J = "windows-31j"; |
724 |
private static final String CORRECT_EUC_JP = "EUC-JP"; |
725 |
|
726 |
private static String canonizeEncoding(String encodingAlias) { |
727 |
// this does not work correctly on JDK 1.4.1 |
728 |
if (encodingAlias.equalsIgnoreCase("MS932")) { |
729 |
return CORRECT_WINDOWS_31J; |
730 |
} |
731 |
// this is not a correct charset by http://www.iana.org/assignments/character-sets |
732 |
if (encodingAlias.equalsIgnoreCase("EUC-JP-LINUX")) { |
733 |
return CORRECT_EUC_JP; |
734 |
} |
735 |
|
736 |
if (Charset.isSupported(encodingAlias)) { |
737 |
Charset cs = Charset.forName(encodingAlias); |
738 |
return cs.name(); |
739 |
} else { |
740 |
return encodingAlias; |
741 |
} |
742 |
} |
743 |
|
731 |
private void printJob(CompilerJob job) { |
744 |
private void printJob(CompilerJob job) { |
732 |
/* System.out.println("-- compilers --"); // NOI18N |
745 |
/* System.out.println("-- compilers --"); // NOI18N |
733 |
java.util.Iterator compilers = job.compilers().iterator(); |
746 |
java.util.Iterator compilers = job.compilers().iterator(); |
Lines 1008-1013
Link Here
|
1008 |
public void removeSaveCookie(){ |
1021 |
public void removeSaveCookie(){ |
1009 |
Node.Cookie cookie = getCookie(SaveCookie.class); |
1022 |
Node.Cookie cookie = getCookie(SaveCookie.class); |
1010 |
if (cookie!=null) getCookieSet().remove(cookie); |
1023 |
if (cookie!=null) getCookieSet().remove(cookie); |
|
|
1024 |
} |
1025 |
|
1026 |
/* Creates new object from template. Inserts the correct ";charset=..." clause to the object |
1027 |
* @exception IOException |
1028 |
*/ |
1029 |
protected DataObject handleCreateFromTemplate ( |
1030 |
DataFolder df, String name |
1031 |
) throws IOException { |
1032 |
|
1033 |
DataObject dobj = super.handleCreateFromTemplate(df, name); |
1034 |
if (dobj instanceof JspDataObject) { |
1035 |
JspDataObject jspDO = (JspDataObject)dobj; |
1036 |
FileObject prim = jspDO.getPrimaryFile(); |
1037 |
String encoding = jspDO.getFileEncoding(prim); |
1038 |
if (!"ISO-8859-1".equals(encoding)) { |
1039 |
// write the encoding to file |
1040 |
sun.io.CharToByteConverter.getConverter(encoding); |
1041 |
Util.setFileEncoding(prim, encoding); |
1042 |
|
1043 |
// change in the file |
1044 |
// warning: the following approach will only work if the page does not |
1045 |
// contain any strange characters. That's the case right after creation |
1046 |
// from template, so we are safe here |
1047 |
EditorCookie edit = (EditorCookie)jspDO.getCookie(EditorCookie.class); |
1048 |
if (edit != null) { |
1049 |
try { |
1050 |
StyledDocument doc = edit.openDocument(); |
1051 |
int offset = findEncodingOffset(doc); |
1052 |
if (offset != -1) { |
1053 |
doc.insertString(offset, ";charset=" + encoding, null); |
1054 |
SaveCookie sc = (SaveCookie)jspDO.getCookie(SaveCookie.class); |
1055 |
if (sc != null) { |
1056 |
sc.save(); |
1057 |
} |
1058 |
} |
1059 |
} |
1060 |
catch (BadLocationException e) { |
1061 |
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); |
1062 |
} |
1063 |
} |
1064 |
} |
1065 |
} |
1066 |
return dobj; |
1067 |
} |
1068 |
|
1069 |
private int findEncodingOffset(StyledDocument doc) throws BadLocationException { |
1070 |
String text = doc.getText(0, doc.getLength()); |
1071 |
String toFind = "contentType=\""; |
1072 |
int index1 = text.indexOf(toFind); |
1073 |
if (index1 == -1) return -1; |
1074 |
int index2 = text.indexOf("\"", index1 + toFind.length()); |
1075 |
return index2; |
1011 |
} |
1076 |
} |
1012 |
|
1077 |
|
1013 |
////// -------- INNER CLASSES --------- |
1078 |
////// -------- INNER CLASSES --------- |