01: /*
02: * JavuX - Java Component Set
03: * Copyright (c) 2005-2007 Krzysztof A. Sadlocha
04: * e-mail: ksadlocha@programics.com
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: package com.javujavu.tools.ptdoc;
22:
23: import java.util.StringTokenizer;
24: import com.javujavu.javux.proptree.PropTree;
25: import com.javujavu.javux.proptree.PropTreeDocReader;
26: import com.javujavu.javux.proptree.PropTreeDocWriter;
27: import com.javujavu.javux.util.MainParams;
28:
29: public class PTDoc extends PropTreeDocWriter {
30: private String[] execlude;
31:
32: void setExeclude(String execldePattern) {
33: if (execldePattern == null) {
34: execlude = null;
35: } else {
36: StringTokenizer t = new StringTokenizer(execldePattern, ";");
37: execlude = new String[t.countTokens()];
38: for (int i = 0; t.hasMoreTokens(); i++)
39: execlude[i] = "." + t.nextToken() + ".";
40: }
41: }
42:
43: public void dataNode(String fullKey, String value) {
44: if (execlude != null) {
45: String k2 = "." + fullKey + ".";
46: for (int i = 0; i < execlude.length; i++) {
47: if (k2.indexOf(execlude[i]) != -1)
48: return;
49: }
50: }
51: super .dataNode(fullKey, value);
52: }
53:
54: public static void main(String[] args) {
55: MainParams params = new MainParams("nc;ni", "rd;ao;in;lw;ex");
56: params.procArgs(args);
57: String[] pp = params.getParams();
58:
59: if (pp.length < 1) {
60: System.out.println("PropTreeDoc Formatter");
61: System.out
62: .println("Using: ptdoc [options] source [destination]");
63: System.out.println("Options:");
64: System.out.println(" -nc | no comments");
65: System.out
66: .println(" -rd <n> | relative dot count <n> | default 0");
67: System.out
68: .println(" -ao <a> | assignment operator <a> | default \"= \"");
69: System.out
70: .println(" -in <i> | indent <i> | default \" \"");
71: System.out.println(" -ni | no indent");
72: System.out
73: .println(" -lw <lw> | line width <l> | default 1000");
74: System.out
75: .println(" -ex <p> | execlude keys containing node from semicolon");
76: System.out.println(" | separated pattern <p> ");
77: System.out.println("Example:");
78: System.out
79: .println("java -jar ptdoc.jar -cd 2 -ex table;button.on wings.ini wings2.ini");
80: System.out
81: .println("java -jar ptdoc.jar -cd 9 -ao = -ni -nc wings.ini");
82: return;
83: }
84:
85: PropTreeDocReader r = new PropTreeDocReader();
86: r.setSkipComments(params.isSet("nc"));
87: PropTree pt = r.load(pp[0]);
88: PTDoc w = new PTDoc();
89: w.setAssignment(params.getOption("ao", "= "));
90: w.setRelativeDots(params.getOptionInt("rd", 0));
91: w.setIndent(params.isSet("ni") ? "" : params.getOption("in",
92: " "));
93: w.setLine(params.getOptionInt("lw", 1000));
94: w.setExeclude(params.getOption("ex", null));
95: w.save((pp.length > 1) ? pp[1] : pp[0], pt);
96: }
97:
98: }
|