Skip to content

Commit 3911996

Browse files
committed
Merge branch 'master' of https://github.com/logicaldoc/community
2 parents a8f8aa6 + f774e3a commit 3911996

File tree

1 file changed

+26
-1
lines changed
  • logicaldoc-core/src/main/java/com/logicaldoc/core/automation

1 file changed

+26
-1
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/automation/DocTool.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import com.logicaldoc.core.metadata.Template;
3232
import com.logicaldoc.core.metadata.TemplateDAO;
3333
import com.logicaldoc.core.parser.ParsingException;
34+
import com.logicaldoc.core.searchengine.Hit;
35+
import com.logicaldoc.core.searchengine.SearchEngine;
3436
import com.logicaldoc.core.security.Tenant;
3537
import com.logicaldoc.core.security.TenantDAO;
3638
import com.logicaldoc.core.security.authorization.PermissionException;
@@ -588,7 +590,7 @@ public Document copyResource(Document doc, String fileVersion, String suffix, St
588590
}
589591

590592
/**
591-
* Gets the content of a resource and stores it as a string
593+
* Gets the content of a resource and reads it as a string
592594
*
593595
* @param docId The document's identifier
594596
* @param fileVersion The file version
@@ -986,4 +988,27 @@ public String parse(Document document, String fileVersion) {
986988
return null;
987989
}
988990
}
991+
992+
/**
993+
* Same as {@link #DocTool.parse()} but first it tries to get the text from
994+
* the already built fulltext index
995+
*
996+
* @param document The document to elaborate
997+
*
998+
* @return the extracted texts
999+
*/
1000+
public String getText(Document document) {
1001+
String text = null;
1002+
1003+
if (document.getIndexed() == AbstractDocument.INDEX_INDEXED) {
1004+
SearchEngine indexer = Context.get(SearchEngine.class);
1005+
Hit hit = indexer.getHit(document.getId());
1006+
if (hit != null)
1007+
text = hit.getContent();
1008+
}
1009+
1010+
if (StringUtils.isEmpty(text))
1011+
text = parse(document, null);
1012+
return text;
1013+
}
9891014
}

0 commit comments

Comments
 (0)