Pessoal fiz um programa que esta dezipando um arquivo .odt salvando todo o conteudo desse arquivo + um conteudo que eh inserdio no comeco, num novo arquivo
soh que os acentos estao se perdendo quando eu salvo no novo documento (SOH NO LINUX) … quando eu rodo o programa no windows ele mante os acentos mas quando eu rodo a aplicacao no linux os acentos esta se transformando em ??
jah tentei mudar TODOS os encodings do projeto alternei entre ISO-8859-1 e UTF-8 … nenhum dos dois funcionou
estou usando para desenvolver o netbeans 6.1 a jvm aqui eh a versao 1.6.alguma coisa, versao do servidor de aplicacao eh o tamcat 6
vou o trecho do codigo onde ele esta fazendo a copia
[code]public boolean InsertDocNumber(String fileName, String docnumber) {
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(fileName));
String aux = "";
String replace = "";
String newcontent = "";
String oldcontent = "";
String regex = "";
int[] vectorStartIndex = new int[2];
Pattern pattern;
Matcher matcher;
while ((aux = in.readLine()) != null) {
oldcontent += aux;
}
in.close();
newcontent = oldcontent;
regex = "</office:automatic-styles>";
pattern = Pattern.compile(regex);
matcher = pattern.matcher(newcontent);
replace =
new StringBuilder()
.append("<style:style style:name=\"primeiraPaginaNumero8745\" style:family=\"text\">")
.append(" <style:text-properties fo:font-variant=\"normal\" fo:text-transform=\"none\"")
.append(" fo:color=\"#000000\" style:text-line-through-style=\"none\"")
.append(" style:text-position=\"0% 100%\" style:font-name=\"Times New Roman7\"")
.append(" fo:font-size=\"12pt\" fo:letter-spacing=\"normal\" fo:language=\"pt\" fo:country=\"BR\"")
.append(" fo:font-style=\"normal\" style:text-underline-style=\"none\" fo:font-weight=\"normal\"")
.append(" fo:background-color=\"transparent\" style:text-rotation-angle=\"0\"")
.append(" style:text-rotation-scale=\"line-height\" style:font-relief=\"none\"/>")
.append("</style:style>")
.append(regex)
.toString();
newcontent = matcher.replaceFirst(replace);
vectorStartIndex[0] = oldcontent.indexOf("<text:p");
vectorStartIndex[1] = oldcontent.indexOf("<text:h");
int first = firstIndex(vectorStartIndex);
switch (first) {
case 0:
//System.out.println("Caso 1");
regex = "<text:p[^>]*>";
pattern = Pattern.compile(regex);
matcher = pattern.matcher(newcontent);
if (matcher.find()) {
String group = matcher.group();
int start = matcher.start();
if (group.contains("/>")) {
//System.out.println("START: " + matcher.start());
//System.out.println("END: " + matcher.end());
//System.out.println(group.substring(0, group.indexOf("/>")));
replace =
new StringBuilder()
.append(group.substring(0, group.indexOf("/>")))
.append("><text:span text:style-name=\"primeiraPaginaNumero8745\">")
.append("Numero do Documento: ")
.append(docnumber)
.append("<text:line-break/></text:span></text:p>")
.toString();
//System.out.println("REPLACE: " + replace);
newcontent = newcontent.replaceFirst(group, replace);
} else {
replace =
new StringBuilder()
.append(group)
.append("<text:span text:style-name=\"primeiraPaginaNumero8745\">")
.append("Numero do Documento: ")
.append(docnumber)
.append("<text:line-break/></text:span>")
.toString();
//System.out.println("REPLACE: " + replace);
newcontent = newcontent.replaceFirst(group, replace);
int endParagraph = newcontent.indexOf("</text:p", start);
int firstPicture = newcontent.indexOf("<draw", start);
if (firstPicture < endParagraph) {
replace = "anchor-type=\"text\"";
//System.out.println(replace);
newcontent = newcontent.replaceFirst("anchor-type=\"paragraph\"", replace);
}
}
}
break;
case 1:
//System.out.println("Caso 2");
regex = "<text:h[^>]*>";
pattern = Pattern.compile(regex);
matcher = pattern.matcher(newcontent);
if (matcher.find()) {
String group = matcher.group();
int start = matcher.start();
if (group.contains("/>")) {
//System.out.println("START: " + start);
//System.out.println("END: " + matcher.end());
//System.out.println(group.substring(0, group.indexOf("/>")));
replace =
new StringBuilder()
.append(group.substring(0, group.indexOf("/>")))
.append("><text:span text:style-name=\"primeiraPaginaNumero8745\">")
.append("Numero do Documento: ")
.append(docnumber)
.append("<text:line-break/></text:span></text:h>")
.toString();
//System.out.println("REPLACE: " + replace);
newcontent = newcontent.replaceFirst(group, replace);
} else {
replace =
new StringBuilder()
.append(group)
.append("<text:span text:style-name=\"primeiraPaginaNumero8745\">")
.append("Numero do Documento: ")
.append(docnumber)
.append("<text:line-break/></text:span>")
.toString();
//System.out.println("REPLACE: " + replace);
newcontent = newcontent.replaceFirst(group, replace);
int endParagraph = newcontent.indexOf("</text:h", start);
int firstPicture = newcontent.indexOf("<draw", start);
if (firstPicture < endParagraph) {
replace = "anchor-type=\"text\"";
//System.out.println(replace);
newcontent = newcontent.replaceFirst("anchor-type=\"paragraph\"", replace);
}
}
}
break;
default:
//System.out.println("Caso 3");
break;
}
BufferedWriter on = new BufferedWriter(new FileWriter(fileName));
on.write(newcontent);
on.close();
return true;
} catch (FileNotFoundException ex) {
Logger.getLogger(OdtNumberGenerator.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (IOException ex) {
Logger.getLogger(OdtNumberGenerator.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
}[/code]