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@215: import de.intevation.flys.client.shared.exceptions.ServerException; 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@587: /** XPath to figure out the ttl of the created collection.*/ ingo@587: public static final String XPATH_COLLECTION_TTL = ingo@587: "/art:result/art:artifact-collection/@art:ttl"; ingo@587: ingo@215: /** Error message key that is thrown if an error occured while creating ingo@215: * a new collection.*/ ingo@215: public static final String ERROR_CREATE_COLLECTION = ingo@215: "error_create_collection"; ingo@26: ingo@215: ingo@229: public Collection create(String serverUrl, String locale, String ownerId) ingo@215: throws ServerException ingo@215: { ingo@71: System.out.println("Start creating a new collection."); ingo@26: ingo@71: Document create = ingo@71: ClientProtocolUtils.newCreateCollectionDocument(null); ingo@229: HttpClient client = new HttpClientImpl(serverUrl, locale); 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@587: String ttlStr = XMLUtils.xpathString( ingo@587: doc, XPATH_COLLECTION_TTL, ArtifactNamespaceContext.INSTANCE); ingo@587: ingo@587: if (uuid.trim().length() == 0 || ttlStr.length() == 0) { ingo@215: throw new ServerException(ERROR_CREATE_COLLECTION); ingo@215: } ingo@215: ingo@587: return new DefaultCollection(uuid, Long.valueOf(ttlStr)); ingo@26: } ingo@26: catch (ConnectionException ce) { ingo@26: System.err.println(ce.getLocalizedMessage()); ingo@26: } ingo@26: ingo@215: throw new ServerException(ERROR_CREATE_COLLECTION); ingo@26: } ingo@26: } ingo@26: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :