ICU-2055 tool for fixing eras
X-SVN-Rev: 16660
This commit is contained in:
parent
e3dbdda10a
commit
ba9c6bf6d6
114
icu4j/src/com/ibm/icu/dev/tool/cldr/FixEras.java
Normal file
114
icu4j/src/com/ibm/icu/dev/tool/cldr/FixEras.java
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Created on Sep 17, 2004
|
||||
*
|
||||
* TODO To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
package com.ibm.icu.dev.tool.cldr;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.ibm.icu.dev.tool.UOption;
|
||||
|
||||
/**
|
||||
* @author ram
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
public class FixEras {
|
||||
/**
|
||||
* These must be kept in sync with getOptions().
|
||||
*/
|
||||
private static final int HELP1 = 0;
|
||||
private static final int HELP2 = 1;
|
||||
private static final int DESTFILE = 2;
|
||||
|
||||
private static final UOption[] options = new UOption[] {
|
||||
UOption.HELP_H(),
|
||||
UOption.HELP_QUESTION_MARK(),
|
||||
UOption.DESTDIR(),
|
||||
|
||||
};
|
||||
private String destfile = null;
|
||||
|
||||
public static void main(String[] args) {
|
||||
FixEras cnv = new FixEras();
|
||||
cnv.processArgs(args);
|
||||
}
|
||||
|
||||
private void usage() {
|
||||
System.out.println("\nUsage: FixEras [OPTIONS] [XPATH1] [XPATH2]\n\n"+
|
||||
"This program is used to extract nodes from extract LDML file and merge \n"+
|
||||
"the extracted nodes with the main LDML file\n"+
|
||||
"Please refer to the following options. Options are not case sensitive.\n"+
|
||||
"Options:\n"+
|
||||
"-d or --destination destination directory, followed by the path, default is current directory.\n"+
|
||||
"-h or -? or --help this usage text.\n"+
|
||||
"example: com.ibm.icu.dev.tool.cldr.FixErs ar.xml\n"
|
||||
); System.exit(-1);
|
||||
}
|
||||
|
||||
private void processArgs(String[] args) {
|
||||
int remainingArgc = 0;
|
||||
try{
|
||||
remainingArgc = UOption.parseArgs(args, options);
|
||||
}catch (Exception e){
|
||||
System.err.println("ERROR: "+ e.toString());
|
||||
e.printStackTrace();
|
||||
usage();
|
||||
}
|
||||
if(args.length==0 || options[HELP1].doesOccur || options[HELP2].doesOccur) {
|
||||
usage();
|
||||
}
|
||||
|
||||
if(options[DESTFILE].doesOccur) {
|
||||
destfile = options[DESTFILE].value;
|
||||
}
|
||||
if(destfile==null){
|
||||
throw new RuntimeException("Destination not specified");
|
||||
}
|
||||
if(remainingArgc<1){
|
||||
usage();
|
||||
System.exit(-1);
|
||||
}
|
||||
try{
|
||||
Document maindoc = LDMLUtilities.parse(args[0], false);
|
||||
System.out.println("INFO: Fixing eras");
|
||||
fixEras(maindoc);
|
||||
maindoc.normalize();
|
||||
OutputStreamWriter writer = new
|
||||
OutputStreamWriter(new FileOutputStream(destfile),"UTF-8");
|
||||
PrintWriter pw = new PrintWriter(writer);
|
||||
LDMLUtilities.printDOMTree(maindoc,pw);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}catch( Exception e){
|
||||
e.printStackTrace();
|
||||
//System.exit(-1);
|
||||
}
|
||||
}
|
||||
private void fixEras(Document doc){
|
||||
Node[] nodes = LDMLUtilities.getElementsByTagName(doc, LDMLConstants.ERA);
|
||||
if(nodes!=null){
|
||||
for(int i=0; i<nodes.length; i++){
|
||||
NamedNodeMap attr = nodes[i].getAttributes();
|
||||
Node type = attr.getNamedItem(LDMLConstants.TYPE);
|
||||
if(type!=null){
|
||||
String val = type.getNodeValue();
|
||||
int j = Integer.parseInt(val);
|
||||
if(j>0){
|
||||
j--;
|
||||
}
|
||||
type.setNodeValue(Integer.toString(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user