Index: addon/editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/resource/ResourceUploadPlugin.java =================================================================== --- addon/editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/resource/ResourceUploadPlugin.java (revision 25504) +++ addon/editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/resource/ResourceUploadPlugin.java (revision ) @@ -15,18 +15,17 @@ */ package org.hippoecm.frontend.editor.plugins.resource; -import java.io.IOException; +import java.io.*; import java.util.Calendar; import javax.jcr.Node; import javax.jcr.RepositoryException; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.jackrabbit.extractor.PdfTextExtractor; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.upload.FileUpload; -import org.apache.wicket.markup.html.form.upload.FileUploadField; import org.apache.wicket.model.StringResourceModel; import org.apache.wicket.util.value.IValueMap; import org.apache.wicket.util.value.ValueMap; @@ -40,9 +39,15 @@ import org.hippoecm.frontend.plugins.yui.upload.FileUploadWidget; import org.hippoecm.frontend.plugins.yui.upload.FileUploadWidgetSettings; import org.hippoecm.frontend.service.render.RenderPlugin; +import org.hippoecm.repository.api.HippoNodeType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Plugin for uploading resources into the JCR repository. + * The plugin supports multi-file upload with instant or delayed upload. + * This plugin can be configured with specific types, so not all file types are allowed to be uploaded. + */ public class ResourceUploadPlugin extends RenderPlugin { @SuppressWarnings("unused") private final static String SVN_ID = "$Id: ResourceUploadPlugin.java 25504 2010-11-30 13:43:42Z abogaart $"; @@ -122,10 +127,16 @@ } else { JcrNodeModel nodeModel = (JcrNodeModel) ResourceUploadPlugin.this.getDefaultModel(); Node node = nodeModel.getNode(); + ByteArrayOutputStream output = new ByteArrayOutputStream(); try { - node.setProperty("jcr:mimeType", mimeType); - node.setProperty("jcr:data", upload.getInputStream()); - node.setProperty("jcr:lastModified", Calendar.getInstance()); + IOUtils.copy(upload.getInputStream(), output); + + setDefaultResourceProperties(node, mimeType, new ByteArrayInputStream(output.toByteArray())); + + if(extension.toLowerCase().equals("pdf")){ + handlePdfAndSetHippoTextProperty(node, new ByteArrayInputStream(output.toByteArray())); + } + ResourceHelper.validateResource(node, fileName); } catch (RepositoryException ex) { error(ex); @@ -136,7 +147,55 @@ } catch (GalleryException ex) { error(ex); log.error(ex.getMessage()); + } finally { + IOUtils.closeQuietly(output); } } } + + /** + * Set the default 'hippo:resource' properties: + *