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();
}
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());
}
}
}
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());
}
}
}
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());
}
}
}
Aggregations