Search in sources :

Example 11 with Resource

use of com.willshex.blogwt.shared.api.datatype.Resource in project blogwt by billy1380.

the class ResourceUploadAction method executeAction.

/* (non-Javadoc)
	 * 
	 * @see
	 * gwtupload.server.gae.CloudStorageUploadAction#executeAction(javax.servlet
	 * .http.HttpServletRequest, java.util.List) */
@Override
public String executeAction(HttpServletRequest request, List<FileItem> sessionFiles) throws UploadActionException {
    StringBuffer resourcesJson = new StringBuffer();
    Resource resource;
    final Date now = new Date();
    for (FileItem i : sessionFiles) {
        if (!i.isFormField()) {
            resource = new Resource();
            resource.created = now;
            resource.data = "gs://" + ((CloudStorageFileItem) i).getKey().getKeyString();
            resource.description = "New uploaded file " + i.getName();
            resource.name = i.getName();
            JsonObject object = new JsonObject();
            object.addProperty("contentType", i.getContentType());
            // add it to the description
            try {
                object.addProperty("staticUrl", ImagesServiceFactory.getImagesService().getServingUrl(ServingUrlOptions.Builder.withBlobKey(((CloudStorageFileItem) i).getKey())).replaceFirst("https:\\/\\/", "//").replaceFirst("http:\\/\\/", "//"));
            } catch (Throwable e) {
            }
            resource.properties = object.toString();
            resource = ResourceServiceProvider.provide().addResource(resource);
            if (resourcesJson.length() != 0) {
                resourcesJson.append(" ");
            }
            resourcesJson.append(resource.id.toString());
        }
    }
    return resourcesJson.toString();
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) CloudStorageFileItem(gwtupload.server.gae.CloudStorageFileItemFactory.CloudStorageFileItem) Resource(com.willshex.blogwt.shared.api.datatype.Resource) JsonObject(com.google.gson.JsonObject) Date(java.util.Date)

Example 12 with Resource

use of com.willshex.blogwt.shared.api.datatype.Resource in project blogwt by billy1380.

the class GetResourceRequest method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("resource")) {
        JsonElement jsonResource = jsonObject.get("resource");
        if (jsonResource != null) {
            resource = new Resource();
            resource.fromJson(jsonResource.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Resource(com.willshex.blogwt.shared.api.datatype.Resource)

Example 13 with Resource

use of com.willshex.blogwt.shared.api.datatype.Resource in project blogwt by billy1380.

the class GetResourcesResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("resources")) {
        JsonElement jsonResources = jsonObject.get("resources");
        if (jsonResources != null) {
            resources = new ArrayList<Resource>();
            Resource item = null;
            for (int i = 0; i < jsonResources.getAsJsonArray().size(); i++) {
                if (jsonResources.getAsJsonArray().get(i) != null) {
                    (item = new Resource()).fromJson(jsonResources.getAsJsonArray().get(i).getAsJsonObject());
                    resources.add(item);
                }
            }
        }
    }
    if (jsonObject.has("pager")) {
        JsonElement jsonPager = jsonObject.get("pager");
        if (jsonPager != null) {
            pager = new Pager();
            pager.fromJson(jsonPager.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Pager(com.willshex.blogwt.shared.api.Pager) Resource(com.willshex.blogwt.shared.api.datatype.Resource)

Example 14 with Resource

use of com.willshex.blogwt.shared.api.datatype.Resource in project blogwt by billy1380.

the class UpdateResourceRequest method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("resource")) {
        JsonElement jsonResource = jsonObject.get("resource");
        if (jsonResource != null) {
            resource = new Resource();
            resource.fromJson(jsonResource.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Resource(com.willshex.blogwt.shared.api.datatype.Resource)

Aggregations

Resource (com.willshex.blogwt.shared.api.datatype.Resource)14 JsonElement (com.google.gson.JsonElement)6 PreloadedImage (gwtupload.client.PreloadedImage)3 JsonObject (com.google.gson.JsonObject)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 JsonParser (com.google.gson.JsonParser)1 GWT (com.google.gwt.core.client.GWT)1 Element (com.google.gwt.dom.client.Element)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 UiBinder (com.google.gwt.uibinder.client.UiBinder)1 UiField (com.google.gwt.uibinder.client.UiField)1 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 Button (com.google.gwt.user.client.ui.Button)1 FormPanel (com.google.gwt.user.client.ui.FormPanel)1 HTMLPanel (com.google.gwt.user.client.ui.HTMLPanel)1 Image (com.google.gwt.user.client.ui.Image)1 TextArea (com.google.gwt.user.client.ui.TextArea)1 TextBox (com.google.gwt.user.client.ui.TextBox)1 Widget (com.google.gwt.user.client.ui.Widget)1 DefaultEventBus (com.willshex.blogwt.client.DefaultEventBus)1