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 package com.sun.star.wizards.table;
24 
25 import com.sun.star.container.XNameAccess;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.wizards.common.Configuration;
28 import com.sun.star.wizards.common.Desktop;
29 import com.sun.star.wizards.common.PropertyNames;
30 
31 public class CGTable
32 {
33 
34     XMultiServiceFactory xMSF;
35     XNameAccess xNameAccessFieldsNode;
36     XNameAccess xNameAccessTableNode;
37     public String Index;
38     public String Name;
39     private Object oconfigView;
40     private final String CGROOTPATH = "/org.openoffice.Office.TableWizard/TableWizard/";
41 
CGTable(XMultiServiceFactory _xMSF)42     public CGTable(XMultiServiceFactory _xMSF)
43     {
44         xMSF = _xMSF;
45     }
46 
initialize(XNameAccess _xNameAccessParentNode, int _index)47     public void initialize(XNameAccess _xNameAccessParentNode, int _index)
48     {
49         try
50         {
51             xNameAccessTableNode = Configuration.getChildNodebyIndex(_xNameAccessParentNode, _index);
52             xNameAccessFieldsNode = Configuration.getChildNodebyName(xNameAccessTableNode, "Fields");
53         }
54         catch (Exception e)
55         {
56             e.printStackTrace(System.out);
57         }
58     }
59 
getFieldNames(boolean _bgetbyShortName, int _imaxcolumnchars)60     public String[] getFieldNames(boolean _bgetbyShortName, int _imaxcolumnchars)
61     {
62         try
63         {
64             String[] fieldnames = null;
65             if (_bgetbyShortName)
66             {
67                 fieldnames = Configuration.getNodeChildNames(xNameAccessFieldsNode, "ShortName");
68                 for (int i = 0; i < fieldnames.length; i++)
69                 {
70                     if (fieldnames[i].length() > _imaxcolumnchars)
71                     {
72                         fieldnames[i] = fieldnames[i].substring(0, _imaxcolumnchars);
73                     }
74                 }
75             }
76             else
77             {
78                 fieldnames = Configuration.getNodeChildNames(xNameAccessFieldsNode, PropertyNames.PROPERTY_NAME);
79             }
80             for (int i = 0; i < fieldnames.length; i++)
81             {
82                 fieldnames[i] = Desktop.removeSpecialCharacters(xMSF, Configuration.getOfficeLocale(xMSF), fieldnames[i]);
83             }
84             return fieldnames;
85         }
86         catch (Exception e)
87         {
88             e.printStackTrace(System.out);
89             return null;
90         }
91     }
92 }
93