comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java @ 683:8a9456d5a081

DistanceInfoService: Got rid of namespace in result document. flys-artifacts/trunk@2117 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 14 Jun 2011 16:26:59 +0000
parents bcd62609c936
children eab5e5089d77
comparison
equal deleted inserted replaced
682:591249171c32 683:8a9456d5a081
10 10
11 import de.intevation.artifacts.CallMeta; 11 import de.intevation.artifacts.CallMeta;
12 12
13 import de.intevation.artifacts.common.ArtifactNamespaceContext; 13 import de.intevation.artifacts.common.ArtifactNamespaceContext;
14 import de.intevation.artifacts.common.utils.XMLUtils; 14 import de.intevation.artifacts.common.utils.XMLUtils;
15 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
16 15
17 import de.intevation.artifactdatabase.DefaultService; 16 import de.intevation.artifactdatabase.DefaultService;
18 17
19 import de.intevation.flys.backend.SessionHolder; 18 import de.intevation.flys.backend.SessionHolder;
20 import de.intevation.flys.model.Annotation; 19 import de.intevation.flys.model.Annotation;
97 96
98 protected Document getUncached(String river) { 97 protected Document getUncached(String river) {
99 98
100 Document result = XMLUtils.newDocument(); 99 Document result = XMLUtils.newDocument();
101 100
102 ElementCreator ec = new ElementCreator(
103 result,
104 ArtifactNamespaceContext.NAMESPACE_URI,
105 ArtifactNamespaceContext.NAMESPACE_PREFIX);
106
107 Session session = SessionHolder.acquire(); 101 Session session = SessionHolder.acquire();
108 102
109 try { 103 try {
110 Iterator<Annotation> iter = 104 Iterator<Annotation> iter =
111 AnnotationsFactory.getAnnotationsIterator(river); 105 AnnotationsFactory.getAnnotationsIterator(river);
112 106
113 Element all = ec.create("distances"); 107 Element all = result.createElement("distances");
114 108
115 while (iter.hasNext()) { 109 while (iter.hasNext()) {
116 Annotation a = iter.next(); 110 Annotation a = iter.next();
117 Element distance = buildDistanceNode(ec, a); 111 Element distance = buildDistanceNode(result, a);
118 all.appendChild(distance); 112 all.appendChild(distance);
119 } 113 }
120 114
121 result.appendChild(all); 115 result.appendChild(all);
122 } 116 }
135 * @param ec The ElementCreator. 129 * @param ec The ElementCreator.
136 * @param anno The Annotation that provides information about the distance. 130 * @param anno The Annotation that provides information about the distance.
137 * 131 *
138 * @return an Element that contains information about a distance. 132 * @return an Element that contains information about a distance.
139 */ 133 */
140 protected static Element buildDistanceNode(ElementCreator ec, Annotation anno) { 134 protected static Element buildDistanceNode(
141 Position pos = anno.getPosition(); 135 Document document,
142 Range range = anno.getRange(); 136 Annotation anno
143 Attribute attr = anno.getAttribute(); 137 ) {
144 Edge edge = anno.getEdge(); 138 Position pos = anno.getPosition();
139 Range range = anno.getRange();
140 Attribute attr = anno.getAttribute();
141 Edge edge = anno.getEdge();
142 BigDecimal a = range.getA();
143 BigDecimal b = range.getB();
145 144
146 BigDecimal a = range.getA(); 145 Element distance = document.createElement("distance");
147 BigDecimal b = range.getB();
148 146
149 Element distance = ec.create("distance"); 147 distance.setAttribute("description", pos.getValue());
150 ec.addAttr(distance, "description", pos.getValue(), true); 148
151 ec.addAttr(distance, "riverside", attr.getValue(), true); 149 String riverSide = attr.getValue();
150
151 if (riverSide != null && riverSide.length() > 0) {
152 distance.setAttribute("riverside", riverSide);
153 }
152 154
153 if (a != null) { 155 if (a != null) {
154 ec.addAttr(distance, "from", a.toString(), true); 156 distance.setAttribute("from", a.toString());
155 } 157 }
156 if (b != null) { 158 if (b != null) {
157 ec.addAttr(distance, "to", b.toString(), true); 159 distance.setAttribute("to", b.toString());
158 } 160 }
159 if (edge != null) { 161 if (edge != null) {
160 BigDecimal bottom = edge.getBottom(); 162 BigDecimal bottom = edge.getBottom();
161 BigDecimal top = edge.getTop(); 163 BigDecimal top = edge.getTop();
162 if (bottom != null) { 164 if (bottom != null) {
163 ec.addAttr(distance, "bottom", bottom.toString(), true); 165 distance.setAttribute("bottom", bottom.toString());
164 } 166 }
165 if (top != null) { 167 if (top != null) {
166 ec.addAttr(distance, "top", top.toString(), true); 168 distance.setAttribute("top", top.toString());
167 } 169 }
168 } 170 }
169 171
170 return distance; 172 return distance;
171 } 173 }

http://dive4elements.wald.intevation.org