knguyen 2004/10/25 18:22:52 CEST
Modified files: (Branch: JAHIA-4-0-BRANCH)
src/java/org/jahia/services/pages ContentPage.java
src/java/org/jahia/services/search
JahiaSearchResultHandlerImpl.java
src/java/org/jahia/utils/fileparsers PDFExtractor.java
Log:
fixe for JAHIA-179, avoid extracting again the content of a pdf file, if it has not
changed. Extracted content is serialized in tmp file and deserialized if needed.
Revision Changes Path
1.72.2.13 +14 -1 jahia/src/java/org/jahia/services/pages/ContentPage.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/services/pages/ContentPage.java.diff?r1=1.72.2.12&r2=1.72.2.13&f=h
1.2.2.4 +7 -5
jahia/src/java/org/jahia/services/search/JahiaSearchResultHandlerImpl.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/services/search/JahiaSearchResultHandlerImpl.java.diff?r1=1.2.2.3&r2=1.2.2.4&f=h
1.3.2.4 +54 -1 jahia/src/java/org/jahia/utils/fileparsers/PDFExtractor.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/utils/fileparsers/PDFExtractor.java.diff?r1=1.3.2.3&r2=1.3.2.4&f=h
Index: ContentPage.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/services/pages/Attic/ContentPage.java,v
retrieving revision 1.72.2.12
retrieving revision 1.72.2.13
diff -u -r1.72.2.12 -r1.72.2.13
--- ContentPage.java 22 Oct 2004 14:43:12 -0000 1.72.2.12
+++ ContentPage.java 25 Oct 2004 16:22:51 -0000 1.72.2.13
@@ -4811,7 +4811,20 @@
ContentObject versionedParentContainer = versionedParentField.
getParent(user, versionedLoadRequest, operationMode);
- if (versionedParentContainer != null) {
+
+ if (
versionedParentContainer.isDeletedOrDoesNotExist(entryState.getVersionID())
+ &&
!versionedParentField.isDeletedOrDoesNotExist(entryState.getVersionID()) ) {
+
+ // there are so much situation where a sub page is activated at
v=t1, but not the parent container !!!!
+ // It's the case, when a user has admin right for the page
(subpage),
+ // but not admin right on the parent container ( that is
localted on the parent page ).
+ // If we restore at v=t1, the subpage exist while the parent
container will be deleted ( as it doesn't exist at v=t1 )!
+ // This situation will create orphan pages ( pages that appear
in sitemap but not in any container list )!!!!
+ // That is why we should not restore the parent container
+
+ // do not restore the parent container
+
+ } else {
// It is more usefull to have the start object the page
opResult.merge(versionedParentContainer.restoreVersion(user,
operationMode, entryState, removeMoreRecentActive,
Index: JahiaSearchResultHandlerImpl.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/services/search/Attic/JahiaSearchResultHandlerImpl.java,v
retrieving revision 1.2.2.3
retrieving revision 1.2.2.4
diff -u -r1.2.2.3 -r1.2.2.4
--- JahiaSearchResultHandlerImpl.java 22 Oct 2004 14:43:13 -0000 1.2.2.3
+++ JahiaSearchResultHandlerImpl.java 25 Oct 2004 16:22:52 -0000 1.2.2.4
@@ -28,6 +28,7 @@
import org.jahia.services.pages.*;
import org.jahia.services.version.*;
import org.jahia.exceptions.JahiaException;
+import org.jahia.content.ContentObject;
/**
* Default implementation to build JahiaSearchResult from a collection of
ParsedObject
@@ -265,11 +266,12 @@
processField = true;
} else if ( jParams.getEntryLoadRequest().isStaging()
&& !contentField.isMarkedForDelete() ){
- if (workflowState > EntryLoadRequest.ACTIVE_WORKFLOW_STATE
- && contentField.hasStagingEntryIgnoreLanguageCase (languageCodeVal)
) {
- // accept staging only if really has staged in the given languageCode
- processField = true;
- } else if
(!contentField.hasStagingEntryIgnoreLanguageCase(languageCodeVal)) {
+ if (workflowState > EntryLoadRequest.ACTIVE_WORKFLOW_STATE &&
+ (contentField.hasStagingEntryIgnoreLanguageCase (languageCodeVal) ))
{
+ // accept staging only if really has staged in the given
languageCode
+ processField = true;
+ } else if (workflowState == EntryLoadRequest.ACTIVE_WORKFLOW_STATE &&
+
!contentField.hasStagingEntryIgnoreLanguageCase(languageCodeVal)) {
// accept active only if field doesn't exist in staging
processField = true;
}
Index: PDFExtractor.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/utils/fileparsers/Attic/PDFExtractor.java,v
retrieving revision 1.3.2.3
retrieving revision 1.3.2.4
diff -u -r1.3.2.3 -r1.3.2.4
--- PDFExtractor.java 20 Oct 2004 09:46:09 -0000 1.3.2.3
+++ PDFExtractor.java 25 Oct 2004 16:22:52 -0000 1.3.2.4
@@ -24,6 +24,11 @@
private static org.apache.log4j.Logger logger =
org.apache.log4j.Logger.getLogger (PDFExtractor.class);
+ /**
+ * Temp file directory.
+ */
+ private File tempDirectory = new File( System.getProperty( "java.io.tmpdir" ) );
+
public PDFExtractor(){
}
@@ -54,7 +59,30 @@
InputStream fileStream,
String charSet) throws Exception {
String strVal = null;
- if (fileStream != null) {
+
+ // try to load previously extracted data if the file has not changed
+
+ String formattedPath = JahiaTools.replacePattern(path,"/","\\");
+ formattedPath = JahiaTools.replacePattern(formattedPath,"\\","_");
+
+ String tmpFilePath = tempDirectory.getAbsolutePath()
+ + File.separator + "jahia_pdf_tmpfile_" + lastModified + "_" +
formattedPath;
+
+ try {
+ // Deserialize from a file
+ File file = new File(tmpFilePath);
+ ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
+ // Deserialize the object
+ strVal = (String) in.readObject();
+ in.close();
+ logger.info("Use previous extracted pdf tmp file " + tmpFilePath);
+ } catch (ClassNotFoundException e) {
+ logger.debug(e);
+ } catch (IOException e) {
+ //logger.debug(e); file could not exist and it's not an error
+ }
+
+ if (strVal == null && fileStream != null) {
Reader pdfReader = null;
try {
long startTime = System.currentTimeMillis();
@@ -69,6 +97,31 @@
elapsedTime = System.currentTimeMillis() - startTime;
logger.info("Finished reading pdf Reader to String in " +
elapsedTime + "ms.");
+ if ( strVal != null ){
+ try {
+ // before creating a new tmp file, deleted old version if
any
+ File[] files = tempDirectory.listFiles();
+ int size = files.length;
+ File f = null;
+ for (int i = 0; i < size; i++) {
+ f = (File) files[i];
+ if (f.getName().endsWith(formattedPath)) {
+ f.delete();
+ }
+ }
+ }catch (Throwable t ){
+ }
+
+ try {
+ // Serialize to a file
+ ObjectOutput out = new ObjectOutputStream(new
+ FileOutputStream(tmpFilePath));
+ out.writeObject(strVal);
+ out.close();
+ }
+ catch (IOException e) {
+ }
+ }
}
catch (Throwable t) {
logger.debug(t);