1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package com.sun.star.filter.config.tools.merge;
25 
26 //_______________________________________________
27 
28 import java.lang.*;
29 import java.util.*;
30 import java.io.*;
31 import com.sun.star.filter.config.tools.utils.*;
32 
33 //_______________________________________________
34 
35 /**
36  *  Its a simple command line tool, which can merge different XML fragments
37  *  together. Such fragments must exist as files on disk, will be moved into
38  *  one file together on disk.
39  *
40  *
41  */
42 public class FCFGMerge
43 {
44     //___________________________________________
45     // const
46 
47     private static final java.lang.String CFGFILE = "com/sun/star/filter/config/tools/merge/FCFGMerge.cfg";
48     private static final java.lang.String PROP_LOGLEVEL = "loglevel";
49 
50     //___________________________________________
51     // main
52 
main(java.lang.String[] sCmdLine)53     public static void main(java.lang.String[] sCmdLine)
54     {
55         FCFGMerge.printCopyright();
56 
57         // create log object in default mode "WARNINGS"
58         // If a command line parameter indicates another
59         // level - change it!
60         Logger aLog = new Logger();
61 
62         try
63         {
64             // merge config file and overwrite properties
65             // via command line
66             ConfigHelper aCfg = null;
67             aCfg = new ConfigHelper(CFGFILE, sCmdLine);
68 
69             // update log level
70             int nLogLevel = aCfg.getInt(PROP_LOGLEVEL, Logger.LEVEL_WARNINGS);
71             aLog = new Logger(nLogLevel);
72 
73             // help requested?
74             if (aCfg.isHelp())
75             {
76                 FCFGMerge.printHelp();
77                 System.exit(-1);
78             }
79 
80             // create new merge object and start operation
81             Merger aMerger = new Merger(aCfg, aLog);
82             aMerger.merge();
83         }
84         catch(java.lang.Throwable ex)
85         {
86             aLog.setException(ex);
87             System.exit(-1);
88         }
89 
90         System.exit(0);
91     }
92 
93     //___________________________________________
94 
95     /** prints out a copyright message on stdout.
96      */
printCopyright()97     private static void printCopyright()
98     {
99         java.lang.StringBuffer sOut = new java.lang.StringBuffer(256);
100         sOut.append("FCFGMerge\n");
101         sOut.append("Copyright: 2003 by Sun Microsystems, Inc.\n");
102         sOut.append("All Rights Reserved.\n");
103         System.out.println(sOut.toString());
104     }
105 
106     //___________________________________________
107 
108     /** prints out a help message on stdout.
109      */
printHelp()110     private static void printHelp()
111     {
112         java.lang.StringBuffer sOut = new java.lang.StringBuffer(256);
113         sOut.append("____________________________________________________________\n");
114         sOut.append("usage: FCFGMerge cfg=<file name>\n"                            );
115         sOut.append("parameters:\n"                                                 );
116         sOut.append("\tcfg=<file name>\n"                                           );
117         sOut.append("\t\tmust point to a system file, which contains\n"             );
118         sOut.append("\t\tall neccessary configuration data for the merge process.\n");
119         sOut.append("\n\tFurther cou can specify every parameter allowed in the\n"  );
120         sOut.append("\n\tconfig file as command line parameter too, to overwrite\n" );
121         sOut.append("\n\tthe value from the file.\n"                                );
122         System.out.println(sOut.toString());
123     }
124 }
125