Author: areshetnyak
Date: 2010-02-16 10:59:42 -0500 (Tue, 16 Feb 2010)
New Revision: 1839
Added:
core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/PDFDocumentReadException.java
Modified:
core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/PDFDocumentReader.java
Log:
EXOJCR-422 : The adding throw PDFDocumentReadException when IOException
Added:
core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/PDFDocumentReadException.java
===================================================================
---
core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/PDFDocumentReadException.java
(rev 0)
+++
core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/PDFDocumentReadException.java 2010-02-16
15:59:42 UTC (rev 1839)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.document;
+
+import java.io.IOException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id: PDFDocumentReaderException.java 111 2010-11-11 11:11:11Z rainf0x $
+ */
+public class PDFDocumentReadException
+ extends DocumentReadException
+{
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * String, the message of exception
+ * @param cause
+ * the cause of exception.
+ */
+ public PDFDocumentReadException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
\ No newline at end of file
Modified:
core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/PDFDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/PDFDocumentReader.java 2010-02-16
15:45:59 UTC (rev 1838)
+++
core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/PDFDocumentReader.java 2010-02-16
15:59:42 UTC (rev 1839)
@@ -24,6 +24,7 @@
import org.exoplatform.commons.utils.ISO8601;
import org.exoplatform.services.document.DCMetaData;
import org.exoplatform.services.document.DocumentReadException;
+import org.exoplatform.services.document.PDFDocumentReadException;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.pdfbox.pdmodel.PDDocument;
@@ -84,13 +85,16 @@
StringWriter sw = new StringWriter();
try
{
+ if (is.available() == 0)
+ return "";
+
try
{
pdDocument = PDDocument.load(is);
}
catch (IOException e)
{
- return "";
+ throw new PDFDocumentReadException("Can not load PDF documet.",
e);
}
PDFTextStripper stripper = new PDFTextStripper();