~slub.team/goobi-production/bug-1013622

« back to all changes in this revision

Viewing changes to src/de/unigoettingen/sub/commons/util/datasource/StructureDumper.java

  • Committer: Ralf Claussnitzer
  • Date: 2012-05-29 10:55:34 UTC
  • mfrom: (66.1.1 integrate-util)
  • Revision ID: ralf.claussnitzer@slub-dresden.de-20120529105534-t5u5vxj9x5v2vifb
fixes lp:1005844 integrate sub-commons util library

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is a contribution to the the ContentServer project, mainly for research purposes.
 
3
 * 
 
4
 * Copyright 2009, Christian Mahnke<cmahnke@gmail.com>.
 
5
 * 
 
6
 * Licensed under the Apache License, Version 2.0 (the “License”);
 
7
 * you may not use this file except in compliance with the License.
 
8
 * You may obtain a copy of the License at
 
9
 * 
 
10
 *  http://www.apache.org/licenses/LICENSE-2.0
 
11
 * 
 
12
 * Unless required by applicable law or agreed to in writing, software
 
13
 * distributed under the License is distributed on an “AS IS” BASIS,
 
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
15
 * See the License for the specific language governing permissions and
 
16
 * limitations under the License.
 
17
 */
 
18
 
 
19
package de.unigoettingen.sub.commons.util.datasource;
 
20
 
 
21
import java.util.ArrayList;
 
22
import java.util.List;
 
23
 
 
24
/**
 
25
 * The Class StructureDumper. A simple class for tests and debugging.
 
26
 */
 
27
public class StructureDumper {
 
28
        
 
29
        /** The struct. */
 
30
        List<Structure> structList = null;
 
31
        
 
32
        
 
33
        public StructureDumper (Structure struct) {
 
34
                structList = new ArrayList<Structure>();
 
35
                structList.add(struct);
 
36
        }
 
37
        
 
38
 
 
39
        @SuppressWarnings("unchecked")
 
40
        public StructureDumper (StructureSource structSource) {
 
41
                this.structList = (List<Structure>) structSource.getStructureList();
 
42
        }
 
43
        
 
44
        
 
45
        /**
 
46
         * Dump.
 
47
         */
 
48
        public void dump () {
 
49
                for (Structure struct: structList) {
 
50
                        System.out.println("ROOT: " + struct.getContent());
 
51
                        dump(struct, 1);
 
52
                }
 
53
        }
 
54
        
 
55
        /**
 
56
         * Dump.
 
57
         * 
 
58
         * @param struct the struct
 
59
         * @param level the level
 
60
         */
 
61
        protected void dump (Structure struct, Integer level) {
 
62
                for (Structure child: struct.getChildren()) {
 
63
                        StringBuffer ident = new StringBuffer();
 
64
                        for (int i = 0; i < level; i++) {
 
65
                                ident.append(" ");
 
66
                        }       
 
67
                        System.out.println(ident.toString() + "+ "  + child.getContent());
 
68
                        if (struct.getChildren().size() != 0) {
 
69
                                dump(struct, level + 1);
 
70
                        }
 
71
                }
 
72
        }
 
73
 
 
74
}