ingo@26: package de.intevation.flys.client.server; ingo@26: ingo@26: import org.w3c.dom.Document; ingo@26: ingo@26: import com.google.gwt.user.server.rpc.RemoteServiceServlet; ingo@26: ingo@26: import de.intevation.artifacts.common.ArtifactNamespaceContext; ingo@26: import de.intevation.artifacts.common.utils.ClientProtocolUtils; ingo@26: import de.intevation.artifacts.common.utils.XMLUtils; ingo@26: ingo@26: import de.intevation.artifacts.httpclient.exceptions.ConnectionException; ingo@26: import de.intevation.artifacts.httpclient.http.HttpClient; ingo@26: import de.intevation.artifacts.httpclient.http.HttpClientImpl; ingo@26: import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; ingo@26: ingo@71: import de.intevation.flys.client.shared.model.Collection; ingo@71: import de.intevation.flys.client.shared.model.DefaultCollection; ingo@26: import de.intevation.flys.client.client.services.CreateCollectionService; ingo@26: ingo@26: ingo@26: /** ingo@26: * This interface provides the createCollection service to create new ingo@26: * collections in the artifact server. ingo@26: * ingo@26: * @author Ingo Weinzierl ingo@26: */ ingo@26: public class CreateCollectionServiceImpl ingo@26: extends RemoteServiceServlet ingo@26: implements CreateCollectionService ingo@26: { ingo@26: /** XPath to figure out the uuid of the created collection.*/ ingo@26: public static final String XPATH_COLLECTION_UUID = ingo@26: "/art:result/art:artifact-collection/@art:uuid"; ingo@26: ingo@26: ingo@71: public Collection create(String serverUrl, String ownerId) { ingo@71: System.out.println("Start creating a new collection."); ingo@26: ingo@71: Document create = ingo@71: ClientProtocolUtils.newCreateCollectionDocument(null); ingo@26: HttpClient client = new HttpClientImpl(serverUrl); ingo@26: ingo@26: try { ingo@26: Document doc = (Document) client.createCollection( ingo@26: create, ownerId, new DocumentResponseHandler()); ingo@26: ingo@71: String uuid = XMLUtils.xpathString( ingo@26: doc, XPATH_COLLECTION_UUID, ArtifactNamespaceContext.INSTANCE); ingo@71: ingo@71: return new DefaultCollection(uuid); ingo@26: } ingo@26: catch (ConnectionException ce) { ingo@26: System.err.println(ce.getLocalizedMessage()); ingo@26: } ingo@26: ingo@26: return null; ingo@26: } ingo@26: } ingo@26: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :