From bd91e42a893d50ecfaa50d9051131a1a593d4487 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Fri, 5 Apr 2013 22:03:34 +0200
Subject: [PATCH] add asRawText() in mixin.text_convertable that does no
 substitution.

it should be used to get SearchableText that should be static.
---
 product/ERP5/Document/TextDocument.py  |  4 ++--
 product/ERP5/mixin/text_convertable.py | 10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/product/ERP5/Document/TextDocument.py b/product/ERP5/Document/TextDocument.py
index 69f0d10db6..338878f6fc 100644
--- a/product/ERP5/Document/TextDocument.py
+++ b/product/ERP5/Document/TextDocument.py
@@ -128,7 +128,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin,
                                          **substitution_method_parameter_dict)
 
     def _convert(self, format, substitution_method_parameter_dict=None,
-                safe_substitute=True, charset=None, text_content=None, **kw):
+                safe_substitute=True, charset=None, text_content=None, substitute=True, **kw):
       """
         Convert text using portal_transforms or oood
       """
@@ -184,7 +184,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin,
           self.setConversion(result, original_mime_type, **kw)
         else:
           mime_type, result = self.getConversion(**kw)
-        if format in VALID_TEXT_FORMAT_LIST:
+        if substitute and format in VALID_TEXT_FORMAT_LIST:
           # only textual content can be sustituted 
           if substitution_method_parameter_dict is None:
             substitution_method_parameter_dict = {}
diff --git a/product/ERP5/mixin/text_convertable.py b/product/ERP5/mixin/text_convertable.py
index 5ed12c25c3..d017a1a544 100644
--- a/product/ERP5/mixin/text_convertable.py
+++ b/product/ERP5/mixin/text_convertable.py
@@ -49,6 +49,16 @@ class TextConvertableMixin:
     mime, data = self.convert(format='txt', **kw)
     return str(data)
 
+  security.declareProtected(Permissions.AccessContentsInformation,
+                            'asRawText')
+  def asRawText(self, **kw):
+    """
+    Converts the current document to plain text without substitution
+    """
+    kw.pop('format', None)
+    mime, data = self.convert(format='txt', substitute=False, **kw)
+    return str(data)
+
   security.declareProtected(Permissions.AccessContentsInformation,
                             'asTextContent')
   def asTextContent(self, **kw):
-- 
2.30.9