Grundaufbau der App
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / network / XmlEntry.java
1 package de.dhbwloe.campusapp.network;
2
3 import android.os.Bundle;
4 import android.util.Log;
5 import android.util.Xml;
6
7 import java.util.ArrayList;
8
9 /**
10  * Created by pk910 on 22.01.2016.
11  */
12 public class XmlEntry {
13     public static XmlEntry FindXmlEntryByName(XmlEntry root, String name) {
14         if(root.getName().equalsIgnoreCase(name))
15             return root;
16         for(XmlEntry entry : root.getChildren()) {
17             entry = FindXmlEntryByName(entry, name);
18             if(entry != null)
19                 return entry;
20         }
21         return null;
22     }
23
24     public static XmlEntry[] FindXmlEntriesByName(XmlEntry root, String name) {
25         Log.i("XMLFind", "Search "+name+"  have: "+root.getName());
26         if(root.getName().equalsIgnoreCase(name))
27             return new XmlEntry[] { root };
28
29         ArrayList<XmlEntry> entries = new ArrayList<XmlEntry>();
30         for(XmlEntry entry : root.getChildren()) {
31             XmlEntry[] centries = FindXmlEntriesByName(entry, name);
32             for(XmlEntry centry : centries)
33                 entries.add(centry);
34         }
35         XmlEntry[] entriesArr = new XmlEntry[entries.size()];
36         entriesArr = entries.toArray(entriesArr);
37         return entriesArr;
38     }
39
40
41     private String name;
42     private String value;
43     private ArrayList<XmlEntry> children = new ArrayList<XmlEntry>();
44     private Bundle attributes = new Bundle();
45
46     public XmlEntry(String name) {
47         this.name = name;
48     }
49
50     public void setValue(String value) {
51         this.value = value;
52     }
53
54     public String getName() {
55         return name;
56     }
57
58     public String getValue() {
59         return value;
60     }
61
62     public void addChild(XmlEntry child) {
63         children.add(child);
64     }
65
66     public XmlEntry[] getChildren() {
67         XmlEntry childs[] = new XmlEntry[children.size()];
68         childs = children.toArray(childs);
69         return childs;
70     }
71
72     public void setAttribute(String name, String value) {
73         attributes.putString(name, value);
74     }
75
76     public void setAttributes(Bundle bundle) {
77         attributes.putAll(bundle);
78     }
79
80     public Bundle getAttributes() {
81         return attributes;
82     }
83
84     public String getAttribute(String name) {
85         return attributes.getString(name);
86     }
87
88 }