comparison flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java @ 1292:bdc270ea6195

Edited item attributes are saved and send to the server on accept. flys-client/trunk@2898 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 05 Oct 2011 16:29:14 +0000
parents 0f3b19df1880
children d9cb362b8b34
comparison
equal deleted inserted replaced
1291:1d04f35b2cc0 1292:bdc270ea6195
43 String url, 43 String url,
44 String locale) 44 String locale)
45 throws ServerException 45 throws ServerException
46 { 46 {
47 System.out.println( 47 System.out.println(
48 "GetCollectionItemAttributeServiceImpl.getCollectionItemAttribute"); 48 "CollectionItemAttributeServiceImpl.getCollectionItemAttribute");
49 49
50 Document requestDoc = XMLUtils.newDocument(); 50 Document requestDoc = XMLUtils.newDocument();
51 51
52 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( 52 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
53 requestDoc, 53 requestDoc,
70 HttpClient client = new HttpClientImpl(url, locale); 70 HttpClient client = new HttpClientImpl(url, locale);
71 Document res = (Document) client.doCollectionAction( 71 Document res = (Document) client.doCollectionAction(
72 requestDoc, 72 requestDoc,
73 collection.identifier(), 73 collection.identifier(),
74 new DocumentResponseHandler()); 74 new DocumentResponseHandler());
75 75 return readXML (res, artifact);
76 return readXML (res);
77 } 76 }
78 catch (ConnectionException ce) { 77 catch (ConnectionException ce) {
79 System.err.println(ce.getLocalizedMessage()); 78 System.err.println(ce.getLocalizedMessage());
80 } 79 }
81 throw new ServerException(""); 80 throw new ServerException("");
82 } 81 }
83 82
84 protected CollectionItemAttribute readXML (Document doc) { 83
84 public void setCollectionItemAttribute(
85 Collection collection,
86 String artifact,
87 String url,
88 String locale,
89 CollectionItemAttribute attributes)
90 throws ServerException
91 {
92 System.out.println(
93 "CollectionItemAttributeServiceImpl.setCollectionItemAttribute");
94
95 Document doc = writeXML(attributes, artifact);
96
97 try {
98 HttpClient client = new HttpClientImpl(url, locale);
99 Document res = (Document) client.doCollectionAction(
100 doc,
101 collection.identifier(),
102 new DocumentResponseHandler());
103
104 return;
105 }
106 catch (ConnectionException ce) {
107 System.err.println(ce.getLocalizedMessage());
108 }
109 throw new ServerException("");
110 }
111
112 protected CollectionItemAttribute readXML (Document doc, String artifact) {
85 CollectionItemAttribute cia = new CollectionItemAttribute(); 113 CollectionItemAttribute cia = new CollectionItemAttribute();
114 cia.setArtifact(artifact);
86 115
87 Element root = doc.getDocumentElement(); 116 Element root = doc.getDocumentElement();
88 NodeList themes = root.getElementsByTagName("art:themes"); 117 NodeList themes = root.getElementsByTagName("art:themes");
89 118
90 if (themes.getLength() != 1) { 119 if (themes.getLength() != 1) {
100 129
101 return cia; 130 return cia;
102 } 131 }
103 132
104 133
134 protected Document writeXML (
135 CollectionItemAttribute attributes,
136 String artifact)
137 {
138 Document styles = XMLUtils.newDocument();
139
140 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
141 styles,
142 ArtifactNamespaceContext.NAMESPACE_URI,
143 ArtifactNamespaceContext.NAMESPACE_PREFIX);
144 Element action = ec.create("action");
145 Element type = ec.create("type");
146 type.setAttribute("name", "setitemattribute");
147 Element art = ec.create("artifact");
148 art.setAttribute("uuid", artifact);
149 Element attr = ec.create("attribute");
150 Element themes = ec.create("themes");
151 action.appendChild(type);
152 type.appendChild(art);
153 art.appendChild(attr);
154 attr.appendChild(themes);
155
156 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
157 styles,
158 "",
159 "");
160
161 for (int i = 0; i < attributes.getNumStyles(); i++) {
162 Style s = attributes.getStyle(i);
163 Element theme = creator.create("theme");
164 theme.setAttribute("name", s.getName());
165 theme.setAttribute("facet", s.getFacet());
166 theme.setAttribute("index", String.valueOf(i));
167 for (int j = 0; j < s.getNumSettings(); j++) {
168 StyleSetting set = s.getSetting(j);
169 Element field = creator.create("field");
170 field.setAttribute("name", set.getName());
171 field.setAttribute("display", set.getDisplayName());
172 field.setAttribute("default", set.getDefaultValue());
173 field.setAttribute("hints", set.getHints());
174 field.setAttribute("type", set.getType());
175 theme.appendChild(field);
176 }
177 themes.appendChild(theme);
178 }
179 styles.appendChild(action);
180 return styles;
181 }
182
183
105 protected Style getStyle (Element element) { 184 protected Style getStyle (Element element) {
106 185
107 if (!element.getTagName().equals("theme")) { 186 if (!element.getTagName().equals("theme")) {
108 return null; 187 return null;
109 } 188 }
110 189
111 NodeList list = element.getElementsByTagName("field"); 190 NodeList list = element.getElementsByTagName("field");
112 Style style = new Style(); 191 Style style = new Style();
192
113 style.setName (element.getAttribute("name")); 193 style.setName (element.getAttribute("name"));
194 style.setFacet (element.getAttribute("facet"));
114 for(int i = 0; i < list.getLength(); i++) { 195 for(int i = 0; i < list.getLength(); i++) {
115 Element e = (Element) list.item(i); 196 Element e = (Element) list.item(i);
116 StyleSetting set = new StyleSetting ( 197 StyleSetting set = new StyleSetting (
117 e.getAttribute("name"), 198 e.getAttribute("name"),
118 e.getAttribute("default"), 199 e.getAttribute("default"),

http://dive4elements.wald.intevation.org