Index: gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingGalleryProcessor.java
===================================================================
--- gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingGalleryProcessor.java (revision 24897)
+++ gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingGalleryProcessor.java (revision )
@@ -22,7 +22,9 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
+import org.apache.jackrabbit.value.ValueFactoryImpl;
import org.hippoecm.frontend.plugins.gallery.imageutil.ScaleImageOperation;
import org.hippoecm.frontend.plugins.gallery.model.GalleryException;
import org.hippoecm.repository.gallery.HippoGalleryNodeType;
@@ -109,9 +111,11 @@
log.debug("Unknown image MIME type: {}, using raw data", mimeType);
}
- node.setProperty("jcr:data", stored);
+ node.setProperty("jcr:data", ValueFactoryImpl.getInstance().createBinary(stored));
node.setProperty(HippoGalleryNodeType.IMAGE_WIDTH, width);
node.setProperty(HippoGalleryNodeType.IMAGE_HEIGHT, height);
}
+
+
}
Index: gallery/frontend/pom.xml
===================================================================
--- gallery/frontend/pom.xml (revision 25588)
+++ gallery/frontend/pom.xml (revision )
@@ -65,6 +65,12 @@
${project.version}
+ org.apache.jackrabbit
+ jackrabbit-jcr-commons
+ ${jackrabbit.version}
+ provided
+
+
org.onehippo.cms7
hippo-cms-workflowmenu
${project.version}
Index: gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/model/DefaultGalleryProcessor.java
===================================================================
--- gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/model/DefaultGalleryProcessor.java (revision 24897)
+++ gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/model/DefaultGalleryProcessor.java (revision )
@@ -37,6 +37,8 @@
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeDefinition;
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.value.ValueFactoryImpl;
import org.hippoecm.frontend.editor.plugins.resource.ResourceException;
import org.hippoecm.frontend.editor.plugins.resource.ResourceHelper;
import org.slf4j.Logger;
@@ -268,20 +270,23 @@
}
primaryChild = (Node) item;
if (primaryChild.isNodeType("hippo:resource")) {
- primaryChild.setProperty("jcr:mimeType", mimeType);
- primaryChild.setProperty("jcr:data", istream);
+ ResourceHelper.setDefaultResourceProperties(primaryChild, mimeType, istream);
+ if (mimeType.equals(ResourceHelper.MIME_TYPE_PDF)) {
+ InputStream dataInputStream = primaryChild.getProperty(JcrConstants.JCR_DATA).getBinary().getStream();
+ ResourceHelper.handlePdfAndSetHippoTextProperty(primaryChild,dataInputStream);
- }
+ }
+ }
validateResource(primaryChild, fileName);
for (NodeDefinition childDef : node.getPrimaryNodeType().getChildNodeDefinitions()) {
if (childDef.getDefaultPrimaryType() != null
&& childDef.getDefaultPrimaryType().isNodeType("hippo:resource")) {
- makeRegularImage(node, childDef.getName(), primaryChild.getProperty("jcr:data").getStream(),
- primaryChild.getProperty("jcr:mimeType").getString(), primaryChild.getProperty(
- "jcr:lastModified").getDate());
+ makeRegularImage(node, childDef.getName(), primaryChild.getProperty(JcrConstants.JCR_DATA).getStream(),
+ primaryChild.getProperty(JcrConstants.JCR_MIMETYPE).getString(), primaryChild.getProperty(
+ JcrConstants.JCR_LASTMODIFIED).getDate());
}
}
- makeThumbnailImage(primaryChild, primaryChild.getProperty("jcr:data").getStream(), primaryChild
- .getProperty("jcr:mimeType").getString());
+ makeThumbnailImage(primaryChild, primaryChild.getProperty(JcrConstants.JCR_DATA).getStream(), primaryChild
+ .getProperty(JcrConstants.JCR_MIMETYPE).getString());
} catch (ItemNotFoundException ex) {
// deliberate ignore
}
@@ -291,9 +296,9 @@
throws RepositoryException {
if (!node.hasNode(name)) {
Node child = node.addNode(name);
- child.setProperty("jcr:data", istream);
- child.setProperty("jcr:mimeType", mimeType);
- child.setProperty("jcr:lastModified", lastModified);
+ child.setProperty(JcrConstants.JCR_DATA, ValueFactoryImpl.getInstance().createBinary(istream));
+ child.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
+ child.setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified);
}
}
@@ -301,11 +306,11 @@
GalleryException {
if (mimeType.startsWith("image")) {
InputStream thumbNail = createThumbnail(resourceData, thumbnailSize, mimeType);
- node.setProperty("jcr:data", thumbNail);
+ node.setProperty(JcrConstants.JCR_DATA, ValueFactoryImpl.getInstance().createBinary(thumbNail));
} else {
- node.setProperty("jcr:data", resourceData);
+ node.setProperty(JcrConstants.JCR_DATA, ValueFactoryImpl.getInstance().createBinary(resourceData));
}
- node.setProperty("jcr:mimeType", mimeType);
+ node.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
}
public void validateResource(Node node, String fileName) throws GalleryException, RepositoryException {
@@ -318,8 +323,8 @@
public void initGalleryResource(Node node, InputStream data, String mimeType, String fileName, Calendar lastModified)
throws GalleryException, RepositoryException {
- node.setProperty("jcr:mimeType", mimeType);
- node.setProperty("jcr:data", data);
- node.setProperty("jcr:lastModified", lastModified);
+ node.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
+ node.setProperty(JcrConstants.JCR_DATA, ValueFactoryImpl.getInstance().createBinary(data));
+ node.setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified);
}
}
Index: editor/frontend/pom.xml
===================================================================
--- editor/frontend/pom.xml (revision 25588)
+++ editor/frontend/pom.xml (revision )
@@ -80,6 +80,28 @@
jdo2-api
provided
+
+
+ org.apache.commons
+ commons-io
+ [1.3.2,1.4)
+ provided
+
+
+
+ org.apache.jackrabbit
+ jackrabbit-jcr-commons
+ ${jackrabbit.version}
+ provided
+
+
+
+ org.apache.tika
+ tika-parsers
+ 0.6
+ provided
+
+
@@ -105,6 +127,25 @@
+
+
+ false
+ ${basedir}/src/test/java
+
+ **
+
+
+ **/*.java
+
+
+
+ false
+ ${basedir}/src/test/resources
+
+ **
+
+
+
org.apache.maven.plugins
Index: editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/resource/ResourceHelper.java
===================================================================
--- editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/resource/ResourceHelper.java (revision 24835)
+++ editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/resource/ResourceHelper.java (revision )
@@ -15,26 +15,42 @@
*/
package org.hippoecm.frontend.editor.plugins.resource;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.value.ValueFactoryImpl;
+import org.apache.tika.config.TikaConfig;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.utils.ParseUtils;
+import org.hippoecm.repository.api.HippoNodeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.*;
+import java.util.Calendar;
+
import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
+/**
+ * Resource helper for creating and validating nodes of type hippo:resource
+ */
public class ResourceHelper {
@SuppressWarnings("unused")
private final static String SVN_ID = "$Id: ResourceHelper.java 24835 2010-11-04 12:39:17Z bvanhalderen $";
public static final String MIME_IMAGE_PJPEG = "image/pjpeg";
public static final String MIME_IMAGE_JPEG = "image/jpeg";
+ public static final String MIME_TYPE_PDF = "application/pdf";
+ static final Logger log = LoggerFactory.getLogger(ResourceHelper.class);
+
private ResourceHelper() {
}
public static void validateResource(Node resource, String filename) throws ResourceException, RepositoryException {
try {
- String mimeType = (resource.hasProperty("jcr:mimeType") ? resource.getProperty("jcr:mimeType").getString()
+ String mimeType = (resource.hasProperty(JcrConstants.JCR_MIMETYPE) ? resource.getProperty(JcrConstants.JCR_MIMETYPE).getString()
: "");
mimeType = mimeType.toLowerCase();
if (mimeType.equals(MIME_IMAGE_PJPEG)) {
@@ -42,7 +58,7 @@
}
if (mimeType.startsWith("image/")) {
ImageInfo imageInfo = new ImageInfo();
- imageInfo.setInput(resource.getProperty("jcr:data").getStream());
+ imageInfo.setInput(resource.getProperty(JcrConstants.JCR_DATA).getStream());
if (imageInfo.check()) {
String imageInfoMimeType = imageInfo.getMimeType();
if (imageInfoMimeType == null) {
@@ -58,16 +74,16 @@
} else {
throw new ResourceException("impermissable image type content");
}
- } else if (mimeType.equals("application/pdf")) {
+ } else if (mimeType.equals(MIME_TYPE_PDF)) {
String line;
- line = new BufferedReader(new InputStreamReader(resource.getProperty("jcr:data").getStream()))
+ line = new BufferedReader(new InputStreamReader(resource.getProperty(JcrConstants.JCR_DATA).getStream()))
.readLine().toUpperCase();
if (!line.startsWith("%PDF-")) {
throw new ResourceException("impermissable pdf type content");
}
} else if (mimeType.equals("application/postscript")) {
String line;
- line = new BufferedReader(new InputStreamReader(resource.getProperty("jcr:data").getStream()))
+ line = new BufferedReader(new InputStreamReader(resource.getProperty(JcrConstants.JCR_DATA).getStream()))
.readLine().toUpperCase();
if (!line.startsWith("%!")) {
throw new ResourceException("impermissable postscript type content");
@@ -82,4 +98,66 @@
}
}
+ /**
+ * Set the default 'hippo:resource' properties:
+ *
+ * - jcr:mimeType
+ * - jcr:data
+ * - jcr:lastModified
+ *
+ *
+ * @param node the {@link Node} on which to set the properties
+ * @param mimeType the mime-type of the binary data (e.g. application/pdf, image/jpeg)
+ * @param inputStream the data stream. Once the properties have been set the input stream will be closed.
+ *
+ * @throws RepositoryException exception thrown when one of the properties or values could not be set
+ */
+ public static void setDefaultResourceProperties(Node node, String mimeType, InputStream inputStream) throws RepositoryException {
+ ValueFactory factory = ValueFactoryImpl.getInstance();
+ try{
+ node.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
+ node.setProperty(JcrConstants.JCR_DATA, factory.createBinary(inputStream));
+ node.setProperty(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
+ } finally {
+ IOUtils.closeQuietly(inputStream);
-}
+ }
+ }
+
+ /**
+ * Handles the {@link InputStream} and extract text content from the PDF and sets it as a binary type property on the
+ * resource node. Once the property has been set the input stream will be closed.
+ *
+ * @param node the {@link Node} on which to set the '{@value org.hippoecm.repository.api.HippoNodeType#HIPPO_TEXT}' property
+ * @param inputStream data stream
+ */
+ public static void handlePdfAndSetHippoTextProperty(Node node, InputStream inputStream) {
+ ValueFactory factory = ValueFactoryImpl.getInstance();
+ ByteArrayInputStream byteInputStream = null;
+ try {
+ String content = ParseUtils.getStringContent(inputStream, getTikaConfig(), MIME_TYPE_PDF);
+ byteInputStream = new ByteArrayInputStream(content.getBytes());
+ node.setProperty(HippoNodeType.HIPPO_TEXT, factory.createBinary(byteInputStream));
+ } catch (IOException e) {
+ log.warn("An exception has occurred while trying to create inputstream based on " +
+ "extracted text: {} ",e);
+ } catch (RepositoryException e) {
+ log.warn("An exception occurred while trying to set property with extracted text: {}: ",e);
+ } catch (TikaException e) {
+ log.warn("An exception occurred while trying to set Tika configuration: {}: ",e);
+ } finally {
+ IOUtils.closeQuietly(byteInputStream);
+ IOUtils.closeQuietly(inputStream);
+ }
+ }
+
+ /**
+ * Gets the default Tika Configuration
+ *
+ * @return the {@link org.apache.tika.config.TikaConfig}
+ */
+ private static TikaConfig getTikaConfig(){
+ return TikaConfig.getDefaultConfig();
+ }
+
+
+}
Index: editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/resource/ResourceUploadPlugin.java
===================================================================
--- editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/resource/ResourceUploadPlugin.java (revision 24835)
+++ editor/frontend/src/main/java/org/hippoecm/frontend/editor/plugins/resource/ResourceUploadPlugin.java (revision )
@@ -15,13 +15,8 @@
*/
package org.hippoecm.frontend.editor.plugins.resource;
-import java.io.IOException;
-import java.util.Calendar;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-
import org.apache.commons.lang.StringUtils;
+import org.apache.jackrabbit.JcrConstants;
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;
@@ -39,6 +34,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * 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 24835 2010-11-04 12:39:17Z bvanhalderen $";
@@ -51,7 +56,7 @@
private FileUploadForm form;
public ResourceUploadPlugin(IPluginContext context, IPluginConfig config) {
- super(context, config);
+ super(context, config);
// if the types config is not set, all extensions are allowed
String typesConfig = config.getString("types");
@@ -100,6 +105,12 @@
}
}
+
+ /**
+ * Handles the file upload from the form.
+ *
+ * @param upload the {@link FileUpload} containing the upload information
+ */
private void handleUpload(FileUpload upload) {
String fileName = upload.getClientFileName();
String mimeType = upload.getContentType();
@@ -122,9 +133,14 @@
JcrNodeModel nodeModel = (JcrNodeModel) ResourceUploadPlugin.this.getDefaultModel();
Node node = nodeModel.getNode();
try {
- node.setProperty("jcr:mimeType", mimeType);
- node.setProperty("jcr:data", upload.getInputStream());
- node.setProperty("jcr:lastModified", Calendar.getInstance());
+
+ ResourceHelper.setDefaultResourceProperties(node, mimeType, upload.getInputStream());
+
+ if(extension.toLowerCase().equals("pdf")){
+ InputStream inputStream = node.getProperty(JcrConstants.JCR_DATA).getBinary().getStream();
+ ResourceHelper.handlePdfAndSetHippoTextProperty(node, inputStream);
+ }
+
ResourceHelper.validateResource(node, fileName);
} catch (RepositoryException ex) {
error(ex);
@@ -138,4 +154,5 @@
}
}
}
+
}