Eclipse won't save html file with dynamic charset - java

I'm using Thymeleaf template engine, and want to get the charset attribute value for the meta tag on the head block from my project properties, i.e :
<meta th:charset="${#environment.getProperty('html.charset')}">
But when I want to save my html file I get this pop-up error :
Save could not be completed. Try File > Save As... if the problem persists.
Reason:
Character encoding "${#environment.getProperty('html.charset')}" is not a legal character encoding.
I even tried to save the file from outside of eclipse, but when back on eclipse and want to open the file, I couldn't access it and got this error :
Unsupported Character Encoding
Character encoding "${#environment.getProperty('html.charset')}" is not supported by this platform.
Set Encoding...
I tried to suspend all validators on eclipse Preferences but this doesn't resolve the problem.
Any ideas for help ? Thanks in advance.
I'm on Mac OS and using Eclipse IDE for Enterprise Java and Web Developers, Version: 2021-09 (4.21.0).

The charset value is being used, regardless of the prefix, to read and write the file correctly. That there is a prefix on the attribute in a non-prefixed meta tag is a clue that it should be ignored by the normal encoding detection. Please open a bug report for this.
For a workaround, force the use of the encoding you want using the file's Properties dialog's Resource page (get there by right-clicking on the file).

Related

How to append text into an existing file using java 1.4

I want to append into the existing text file. For that I have tried all this in plenty of way FileWriter,BufferedWriter,PrintWriter,RandomAccessFile,OutputStream,FileOutputStream,PrintStream but I can't get my desired output.
This error java.io.FileNotFoundException: could not open file '//file:/usr/backupdata/5605.txt' using mode 'a+' sucks. (I am working with ewon flexy hardware which supports javaetk 1.4 only)
You are trying to use a url as a file name. That won’t work.
Use
/use/backupdata/5605.txt
as the file name.

Jaspersoft studio: UTF-8 encoding issue

I am using Jaspersoft Studio final version (v6.1.1). I have designed my report and it contains Turkish characters. When exporting the report from Studio as PDF Turkish characters are not shown although I've set the Studio workspace encoding to UTF-8. Also I have embed the jrxml report file in my JSF app and export the report, the result is the same.
Do I have to configure something more?
I was able to solve the problem. In the Jaspersoft Studio IDE, change encoding to UTF-8 in Window/Prefrences/General/Workspace. Afterwards click any field, parameter, or text in the IDE and from the Properties/Advanced menu select PDF/PDF Encoding. I hope it will help.
I think i have found an easier and more general solution. Instead of changing encoding of every field, you can do it using java coding from your web application`s controller. Below is my solution, i hope it helps a bit. Just put the font to your webapp folder. And change the encoding programatically. BTW greetings from turkey :)
JRDesignStyle jrDesignStyle = new JRDesignStyle();
/*Set the Encoding to UTF-8 for pdf and embed font to arial*/
jrDesignStyle.setDefault(true);
String fontPath = req.getSession().getServletContext().getRealPath("/jasper/arial.ttf");
jrDesignStyle.setPdfFontName(fontPath);
jrDesignStyle.setPdfEncoding("Identity-H");
jrDesignStyle.setPdfEmbedded(true);
jasperPrint.addStyle(jrDesignStyle);
JRPdfExporter exporter = new JRPdfExporter();

Invalid Header Field Name when adding manifest to JAR using Eclipse

I'm using eclipse to develop a java applet and need to add an external jar to Class-Path in the manifest. I created the manifest file using notepad, used UTF-8 encoding and added the line break at the end, but attempting to add even a simple example manifest during jar creation results in the following error from Eclipse.
invalid header field name: ï>¿Manifest-Version
invalid header field name: ï>¿Manifest-Version
I have a feeling that it's some simple configuration issue, but I can't figure out what.
To test it, my manifest consists of the single line
Manifest-Version: 1.0
Notepad save your file with a special mark named 'BOM' at the beginning : 2 bytes (U+FEFF) which identify UTF-8 format.
You have to edit the file with Notepad++ (or vi) and encode it as UTF-8 (without BOM).
Next steps to make JARs:
Using eclipse
Using Apache ANT
Using Apache Maven
In Notepad++ , from the encoding menu , choose encode in UTF-8 without BOM .
In eclipse, right click in file properties and choose text file encoding to ISO-8859-1
Back in editor delete the special chars.

Saving JSP as UTF-8 in NetBeans

i've got some jsp files from another developers and now need to work with them. When i add to the document any UTF-8 char and want to save the document, NetBeans automatically offers me saving in ISO-8859-1.
Actually i'm getting this message from NetBeans:
The index.jsp contains characters
which will probably be damaged during
conversion to the ISO-8859-1 character
set. Do you want to save the file
using this character set? (Yes/No)
NB didn't offer me any other option like saving the file as UTF-8 (as it should be already written in).
I don't know how to save those jsp files in the character set they are already written in.
And don't tell me, that changing the content of the file itself (which is uneffective due to including headers etc. from other files) is the only way...
http://forums.netbeans.org/topic8750.html
Firstly; don't forget to consider this line at top:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
Secondly;
In the NetBeans folder there is a config file. There should be a line like that:
netbeans_default_options="-J-Xms32m -J-Xmx128m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true"
Add this to the end of the line:
-J-Dfile.encoding=UTF-8
Thirdly:
NetBeans implements a project encoding setting.
To change the language encoding for a project:
Right-click a project node in the Projects windows and choose Properties.
Under Sources, select an encoding value from the Encoding drop-down field.
The encoding affects at least:
* how non-ASCII characters are displayed in the editor window when you open files
* Java file compilation of sources containing non-ASCII identifiers, string literals, or comments
* textual search for international characters over the project
Starting from NetBeans IDE 6.8, you can also specify the encoding that will be used at runtime. For example, this can be useful when the encoding for the operating system on which the application will run is different from your project's encoding.
To specify the encoding to be used at runtime:
In the Files window for your project, open nbproject > private > private.properties
Add the following line to the private.properties file and save changes:
runtime.encoding = < encoding >
This encoding will override the encoding setting for your project and will be used when running your application.
In general,
*.properties files always use ISO-8859-1 encoding plus \uXXXX escapes. (International characters will be displayed natively in the editor but stored as an escape on disk.)
*.xml files and some *.html files can specify their own encodings, regardless of the project encoding. For such files, the IDE's editor ignores the project encoding.
These may help you.
Sources for my answer that I used:
Link1: http://forums.netbeans.org/topic33.html
Link2: http://wiki.netbeans.org/FaqI18nProjectEncoding

Maven filter garbling special characters

I have a resource file with the following string in it, note the special characters:
Questa funzionalità non è sostenuta: {0} {1}
After Maven does its process-resources (which I need for something else) I get:
Questa funzionalit� non � sostenuta: {0} {1}
Please tell me there is an easy fix to this?
The text files that held the strings were Java properties files. By default, most files in an Eclipse project inherit the default encoding scheme from the container (Eclipse) -- in my case that is UTF-8. If you just manually add a text file to the project it does not set it to UTF-8!!
So my properties files were actually encoded as ISO-8859-1. I changed the default encoding in Eclipse by clicking right on the file and selecting properties. I then was forced to re-enter ALL the special characters.
The other part of the fix was to tell the Maven process resource plug-in to use UTF-8 encoding while processing resources. Instructions for that are here:
http://maven.apache.org/plugins/maven-resources-plugin/examples/encoding.html
And of course I had to implement a UTF-8 ResourceBundle.Control because (for backwards compatibility) the detault ResourceBundle is still ISO-8859-1. Details on that class can be found here:
http://www.mail-archive.com/stripes-users#lists.sourceforge.net/msg03972.html
Hope this helps somebody someday.

Categories

Resources