File: ShowCumulatedLowlevelParams.java

package info (click to toggle)
hbci4java 4.1.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,256 kB
  • sloc: java: 52,465; xml: 34,233; cpp: 3,264; makefile: 153; sh: 11
file content (151 lines) | stat: -rw-r--r-- 6,024 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**********************************************************************
 *
 * This file is part of HBCI4Java.
 * Copyright (c) 2001-2008 Stefan Palme
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 **********************************************************************/

package org.kapott.hbci.tools;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/** Dieses Tool ist nur für interne Verwendung bei der Entwicklung von HBCI4Java
 * gedacht. Damit lässt sich prüfen, ob die Highlevel-Klassen für die einzelnen
 * GVs tatsächlich alle möglichen Lowlevel-Parameter eines bestimmten GV
 * kennen und mit richtigen Werten füllen (jeweils abhängig von den bankseitig
 * unterstützten GV-Versionen) */
public class ShowCumulatedLowlevelParams 
{
    private static void extractParams(Document doc, Element node, String path, List<String> params)
    {
        NodeList childs=node.getChildNodes();
        int      l=childs.getLength();
        for (int i=0; i<l; i++) {
            Node child=childs.item(i);
            if (child.getNodeType()==Node.ELEMENT_NODE) {
                Element ref=(Element)child;
                String  refnode=ref.getNodeName();
                String  reftype=ref.getAttribute("type");
                String  refname=ref.getAttribute("name");
                String  refbez=(refname!=null && refname.length()!=0)?refname:reftype;
                
                String localPath=path;
                if (localPath.length()!=0) {
                    localPath+=".";
                }
                localPath+=refbez;

                if (refnode.equals("DE")) {
                    if (!params.contains(localPath)) {
                        params.add(localPath);
                    }
                } else if (refnode.equals("DEG")) {
                    Element def=doc.getElementById(reftype);
                    if (def==null) {
                        // System.out.println("warning: type '"+reftype+"' referenced in '"+localPath+"' not found");
                        String p=localPath+" (+)";
                        if (!params.contains(p)) {
                            params.add(p);
                        }
                    } else {
                        extractParams(doc,def,localPath,params);
                    }
                }
            }
        }
    }
    
    public static void main(String[] args) 
        throws Exception
    {
        DocumentBuilderFactory fac=DocumentBuilderFactory.newInstance();
        fac.setIgnoringComments(true);
        fac.setIgnoringElementContentWhitespace(true);
        fac.setNamespaceAware(false);
        fac.setValidating(false);
        
        DocumentBuilder builder=fac.newDocumentBuilder();
        File            f=new File(args[0]);
        Document        doc=builder.parse(f);
        
        Element  root=doc.getDocumentElement();
        NodeList segdefs=root.getElementsByTagName("SEGdef");
        int      l=segdefs.getLength();
        Map<String, List<String>>      paramsByJob=new Hashtable<String, List<String>>();
        for (int i=0; i<l; i++) {
            Element  segdef=(Element)segdefs.item(i);
            String   segdefid=segdef.getAttribute("id");
            
            String   segcode=null;
            String   segversion=null;
            
            NodeList values=segdef.getElementsByTagName("value");
            int      l2=values.getLength();
            for (int j=0; j<l2; j++) {
                Element value=(Element)values.item(j);
                String  path=value.getAttribute("path");
                if (path.equals("SegHead.code")) {
                    segcode=value.getFirstChild().getNodeValue();
                } else if (path.equals("SegHead.version")) {
                    segversion=value.getFirstChild().getNodeValue();
                }
            }
            
            if (segcode==null || segversion==null) {
                System.out.println("warning: SEGdef with id "+segdefid+" has no segcode or segversion");
                continue;
            }
            
            String plainJobName=segdefid.substring(0,segdefid.length()-segversion.length());
            List<String>   params= paramsByJob.get(plainJobName);
            if (params==null) {
                params=new ArrayList<String>();
                paramsByJob.put(plainJobName,params);
            }
            extractParams(doc, segdef,"",params);
        }
        
        String[] jobnames=paramsByJob.keySet().toArray(new String[0]);
        Arrays.sort(jobnames);
        l=jobnames.length;
        for (int i=0; i<l; i++) {
            String jobname=jobnames[i];
            System.out.println(jobname+":");
            
            List<String>     params=paramsByJob.get(jobname);
            String[] _params= params.toArray(new String[0]);
            Arrays.sort(_params);
            int l2=_params.length;
            for (int j=0; j<l2; j++) {
                System.out.println("  "+_params[j]);
            }
        }
    }
}