This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 97871 - Use FileEncodingQuery
Summary: Use FileEncodingQuery
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: JSP (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: J Bachorik
URL:
Keywords:
: 106004 (view as bug list)
Depends on:
Blocks: 97848
  Show dependency tree
 
Reported: 2007-03-14 16:57 UTC by Tomas Zezula
Modified: 2007-07-25 14:30 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Zezula 2007-03-14 16:57:21 UTC
The JSP data object should provide or at least use FileEncodingQuery to read
store in correct encoding. 
The best solution is not to overide loadStreamToKit and saveKitToStream and
provide implementation of the FileEncodingQueryImplementation which detects an
encoding inside the JSP file when available. This allows not only editor but all
other features like search and other which works directly on FileObject level to
read the file in the correct encoding.

The minimal change for NB 6.0 should be to use FEQ in case when no encoding has
been found in the loadFromStreamToKit or saveFromKitToStream. (When no encoding
is inside the HTML file the project encoding should be used.)
Comment 1 J Bachorik 2007-06-01 13:29:03 UTC
I have a patch ready for FileEncodingQuery functionality. It removes
loadStreamToKit and saveKitToStream overrides and relies on the
FileEncodingQuery implementation completely.

The correct encoding is determined as follows:
1. When a JSP is being loaded the "ENCODING" FileObject property is consulted
for the encoding - JSP content analysis can not be used because it causes
infinite loop (for finding out the encoding the JSP needs to be loaded what in
turn results  in request for the correct encoding and so on and so forth)
2. Upon save the encoding derived from all possible source (encoding tag, JSP
property group, include-prelude etc.) is propagated to the "ENCODING" property.

The only downside is that modifying any part needed to resolve the correct
encoding outside of NB can result into loading the JSP with incorrect encoding.

Any comments welcome
Comment 2 Ken Frank 2007-06-03 20:09:55 UTC
if jsp charset notes an encoding different from project encoding,
which one is used ?

or is it that the jsp charset tag is for runtime only and does not impact view
of encoding
used by working in jsp editor, etc ?

ken.frank@sun.com
Comment 3 J Bachorik 2007-06-04 08:31:13 UTC
The encoding used while editing JSP mimics the encoding to be used in runtime.
The implication of this is the fact that for a JSP file the project defined
encoding is ignored. 
Comment 4 J Bachorik 2007-06-06 11:57:00 UTC
Fixed using the proposed implementation

Checking in nbproject/project.xml;
/cvs/web/core/nbproject/project.xml,v  <--  project.xml
new revision: 1.27; previous revision: 1.26
done
Checking in src/org/netbeans/modules/web/core/jsploader/BaseJspEditorSupport.java;
/cvs/web/core/src/org/netbeans/modules/web/core/jsploader/BaseJspEditorSupport.java,v
 <--  BaseJspEditorSupport.java
new revision: 1.59; previous revision: 1.58
done
Checking in src/org/netbeans/modules/web/core/jsploader/JspNode.java;
/cvs/web/core/src/org/netbeans/modules/web/core/jsploader/JspNode.java,v  <-- 
JspNode.java
new revision: 1.31; previous revision: 1.30
done
Checking in src/org/netbeans/modules/web/core/jsploader/JspDataObject.java;
/cvs/web/core/src/org/netbeans/modules/web/core/jsploader/JspDataObject.java,v 
<--  JspDataObject.java
new revision: 1.65; previous revision: 1.64
Comment 5 Jiri Skrivanek 2007-06-07 09:34:28 UTC
The fix probably caused that a warning dialog appears when you create a web
project and it opens index.jsp file. Message is: 

The "ISO-8559-1" character set that is used in index.jsp is not a valid
character set for JSP Pages. Do you want to open the file using the UTF-8
character set?

Please, fix it ASAP. It breaks automated tests. Thanks.
Comment 6 J Bachorik 2007-06-07 10:31:30 UTC
sorry for that

this will fix it

Checking in JspDataObject.java;
/cvs/web/core/src/org/netbeans/modules/web/core/jsploader/JspDataObject.java,v 
<--  JspDataObject.java
new revision: 1.66; previous revision: 1.65
done
Checking in JspLoader.java;
/cvs/web/core/src/org/netbeans/modules/web/core/jsploader/JspLoader.java,v  <--
 JspLoader.java
new revision: 1.24; previous revision: 1.23
done
Comment 7 Marek Fukala 2007-06-07 13:39:55 UTC
*** Issue 106004 has been marked as a duplicate of this issue. ***
Comment 8 Ken Frank 2007-07-24 20:24:38 UTC
does the fix work as per info I'd gotten from Peter  ?  I want to be clear so can then
verify it.

this is for already created jsp files

- if encoding tag exists, it is used instead of project encoding
- if no encoding tag

In the jsp case, if there is not an encoding mentioned in the file, it
doesn't mean that the the project encoding should be used. The file
object feq is implemented according jsp specification, so in such case
the encoding can be mentioned in the web.xml or in a preloaded jsp file.
If there is not defined encoding for a jsp file then according jsp
specification the default encoding is iso-8859-1. So the jsp file object
feq always returns an encoding, even if is not defined (the iso-8859-1)
and the project encoding will be never used for jsp files.

ken.frank@sun.com
Comment 9 J Bachorik 2007-07-25 14:30:54 UTC
yes, exactly. the resolution of FE for JSP is delegated to the TagLibParseSupport class which does all the magic -
handles encoding tags, encoding definitions in web.xml, preludes etc. it should also handle the correct default encoding
if there is none specified.