raimund@1285: package de.intevation.flys.client.server; raimund@1285: raimund@1285: import org.w3c.dom.Document; raimund@1285: import org.w3c.dom.Element; raimund@1285: import org.w3c.dom.NodeList; raimund@1285: raimund@1285: import com.google.gwt.user.server.rpc.RemoteServiceServlet; raimund@1285: raimund@1285: import de.intevation.artifacts.httpclient.exceptions.ConnectionException; raimund@1285: import de.intevation.artifacts.httpclient.http.HttpClient; raimund@1285: import de.intevation.artifacts.httpclient.http.HttpClientImpl; raimund@1285: import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; raimund@1285: raimund@1285: import de.intevation.artifacts.common.ArtifactNamespaceContext; raimund@1285: import de.intevation.artifacts.common.utils.XMLUtils; raimund@1285: raimund@1285: import de.intevation.flys.client.shared.exceptions.ServerException; raimund@1285: import de.intevation.flys.client.client.services.CollectionItemAttributeService; raimund@1285: raimund@1285: import de.intevation.flys.client.shared.model.Collection; raimund@1285: import de.intevation.flys.client.shared.model.Artifact; raimund@1285: import de.intevation.flys.client.shared.model.CollectionItemAttribute; raimund@1285: import de.intevation.flys.client.shared.model.Style; raimund@1285: import de.intevation.flys.client.shared.model.StyleSetting; raimund@1285: raimund@1285: raimund@1285: /** raimund@1285: * raimund@1285: * @author Raimund Renkert raimund@1285: */ raimund@1285: public class CollectionItemAttributeServiceImpl raimund@1285: extends RemoteServiceServlet raimund@1285: implements CollectionItemAttributeService raimund@1285: { raimund@1285: public static final String XPATH_RESULT = "/art:result/text()"; raimund@1285: raimund@1285: public static final String OPERATION_FAILURE = "FAILED"; raimund@1285: raimund@1285: raimund@1285: public CollectionItemAttribute getCollectionItemAttribute( raimund@1285: Collection collection, raimund@1285: String artifact, raimund@1285: String url, raimund@1285: String locale) raimund@1285: throws ServerException raimund@1285: { raimund@1285: System.out.println( raimund@1285: "GetCollectionItemAttributeServiceImpl.getCollectionItemAttribute"); raimund@1285: raimund@1285: Document requestDoc = XMLUtils.newDocument(); raimund@1285: raimund@1285: XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( raimund@1285: requestDoc, raimund@1285: ArtifactNamespaceContext.NAMESPACE_URI, raimund@1285: ArtifactNamespaceContext.NAMESPACE_PREFIX); raimund@1285: raimund@1285: Element action = ec.create("action"); raimund@1285: raimund@1285: Element type = ec.create("type"); raimund@1285: ec.addAttr(type, "name", "getitemattribute", false); raimund@1285: raimund@1285: Element art = ec.create("artifact"); raimund@1285: ec.addAttr(art, "uuid", artifact, false); raimund@1285: raimund@1285: type.appendChild(art); raimund@1285: action.appendChild(type); raimund@1285: requestDoc.appendChild (action); raimund@1285: raimund@1285: try { raimund@1285: HttpClient client = new HttpClientImpl(url, locale); raimund@1285: Document res = (Document) client.doCollectionAction( raimund@1285: requestDoc, raimund@1285: collection.identifier(), raimund@1285: new DocumentResponseHandler()); raimund@1285: raimund@1285: return readXML (res); raimund@1285: } raimund@1285: catch (ConnectionException ce) { raimund@1285: System.err.println(ce.getLocalizedMessage()); raimund@1285: } raimund@1285: throw new ServerException(""); raimund@1285: } raimund@1285: raimund@1285: protected CollectionItemAttribute readXML (Document doc) { raimund@1285: CollectionItemAttribute cia = new CollectionItemAttribute(); raimund@1285: raimund@1285: Element root = doc.getDocumentElement(); raimund@1285: NodeList themes = root.getElementsByTagName("art:themes"); raimund@1285: raimund@1285: if (themes.getLength() != 1) { raimund@1285: return null; raimund@1285: } raimund@1285: raimund@1285: Element e = (Element) themes.item(0); raimund@1285: NodeList items = e.getElementsByTagName("theme"); raimund@1285: raimund@1285: for (int i = 0; i < items.getLength(); i++) { raimund@1285: cia.appendStyle(getStyle ((Element) items.item(i))); raimund@1285: } raimund@1285: raimund@1285: return cia; raimund@1285: } raimund@1285: raimund@1285: raimund@1285: protected Style getStyle (Element element) { raimund@1285: raimund@1285: if (!element.getTagName().equals("theme")) { raimund@1285: return null; raimund@1285: } raimund@1285: raimund@1285: NodeList list = element.getElementsByTagName("field"); raimund@1285: Style style = new Style(); raimund@1285: style.setName (element.getAttribute("name")); raimund@1285: for(int i = 0; i < list.getLength(); i++) { raimund@1285: Element e = (Element) list.item(i); raimund@1285: StyleSetting set = new StyleSetting ( raimund@1285: e.getAttribute("name"), raimund@1285: e.getAttribute("default"), raimund@1285: e.getAttribute("display"), raimund@1285: e.getAttribute("hints"), raimund@1285: e.getAttribute("type")); raimund@1285: style.appendStyleSetting(set); raimund@1285: } raimund@1285: return style; raimund@1285: } raimund@1285: } raimund@1285: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :