pvollenweider    2005/05/24 14:24:10 CEST

  Modified files:        (Branch: JAHIA-4-1-BRANCH)
    src/view/jsp/include declarations.inc page_categories_list.inc 
    src/view/jsp         searchresult.jsp web_css.jsp 
  Log:
  Highlight search results + display extract from file extraction.
  
  Revision   Changes    Path
  1.6.4.6    +58 -3     
corporate_portal_templates/src/view/jsp/include/declarations.inc
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/include/declarations.inc.diff?r1=1.6.4.5&r2=1.6.4.6&f=h
  1.2.4.1    +2 -2      
corporate_portal_templates/src/view/jsp/include/page_categories_list.inc
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/include/page_categories_list.inc.diff?r1=1.2&r2=1.2.4.1&f=h
  1.19.4.2   +95 -11    corporate_portal_templates/src/view/jsp/searchresult.jsp
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/searchresult.jsp.diff?r1=1.19.4.1&r2=1.19.4.2&f=h
  1.28.4.14  +11 -0     corporate_portal_templates/src/view/jsp/web_css.jsp
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/web_css.jsp.diff?r1=1.28.4.13&r2=1.28.4.14&f=h
  
  
  
  Index: declarations.inc
  ===================================================================
  RCS file: 
/home/cvs/repository/corporate_portal_templates/src/view/jsp/include/declarations.inc,v
  retrieving revision 1.6.4.5
  retrieving revision 1.6.4.6
  diff -u -r1.6.4.5 -r1.6.4.6
  --- declarations.inc  26 Apr 2005 13:51:35 -0000      1.6.4.5
  +++ declarations.inc  24 May 2005 12:24:09 -0000      1.6.4.6
  @@ -1,11 +1,13 @@
   <%@ page import="jahiatemplates.*" %>
  +<%@ page import="java.io.IOException"%>
  +<%@ page import="java.io.InputStream"%>
   <%@ page import="java.lang.*"%>
   <%@ page import="java.net.*"%>
  -<%@ page import="java.text.SimpleDateFormat" %>
   <%@ page import="java.text.DateFormat" %>
  +<%@ page import="java.text.SimpleDateFormat" %>
  +<%@ page import="java.text.SimpleDateFormat"%>
   <%@ page import="java.util.*" %>
   <%@ page import="javax.servlet.*"%>
  -<%@ page import="java.io.IOException"%>
   <%@ page import="org.jahia.data.*" %>
   <%@ page import="org.jahia.data.beans.*" %>
   <%@ page import="org.jahia.data.containers.*" %>
  @@ -20,11 +22,14 @@
   <%@ page import="org.jahia.services.categories.*" %>
   <%@ page import="org.jahia.services.containers.*" %>
   <%@ page import="org.jahia.services.fields.*" %>
  +<%@ page import="org.jahia.services.fileextraction.*"%>
   <%@ page import="org.jahia.services.pages.*" %>
   <%@ page import="org.jahia.services.search.*" %>
   <%@ page import="org.jahia.services.sites.*" %>
   <%@ page import="org.jahia.services.usermanager.*" %>
  +<%@ page import="org.jahia.services.webdav.*"%>
   <%@ page import="org.jahia.utils.*" %>
  +<%@ page import="org.jahia.utils.fileparsers.CharsetDetection"%>
   <%@ taglib uri="/WEB-INF/etc/struts/struts-bean" prefix="bean" %>
   <%@ taglib uri="/WEB-INF/etc/struts/struts-html" prefix="html" %>
   <%@ taglib uri="/WEB-INF/etc/struts/struts-logic" prefix="logic" %>
  @@ -384,7 +389,57 @@
       str = result.append(str.substring(startIndex,str.length())).toString();
       return str;
   }
  -
  +public String hl(String str, String strToHighlight) {
  +    if (str==null ){
  +        return str;
  +    }
  +    int TRUNK_SIZE = 255;
  +    int CHARS_BEFORE = 50;
  +    String STRING_BEFORE_SEARCH = "<span class='hl'>";
  +    String STRING_AFTER_SEARCH = "</span>";
  +
  +    StringBuffer result = new StringBuffer(str.length() + 100);
  +
  +    String[] searchStrings = JahiaTools.getTokens(strToHighlight," ");
  +    if (searchStrings.length > 0) {
  +        String searchString = 
JahiaTools.replacePattern(searchStrings[0],"*","");
  +
  +        String lcStr = str.toLowerCase();
  +        String lcsearchString = searchString.toLowerCase();
  +
  +        int i = lcStr.indexOf(lcsearchString);
  +
  +        // truncate to 255 chars
  +        int startOfIndex = Math.max(i,CHARS_BEFORE) - CHARS_BEFORE;
  +        int maxLength = Math.min(TRUNK_SIZE,str.length()-startOfIndex);
  +        str = str.substring(startOfIndex, maxLength + startOfIndex);
  +        lcStr = str.toLowerCase();
  +
  +        for (int  k = 0; k < searchStrings.length; k++){
  +            result = new StringBuffer(str.length() + 100);
  +            searchString  = 
JahiaTools.replacePattern(searchStrings[k],"*","");
  +            lcStr = str.toLowerCase();
  +            lcsearchString = searchString.toLowerCase();
  +            startOfIndex = 0;
  +            i = lcStr.indexOf(lcsearchString,startOfIndex);
  +            int searchStringLength = searchString.length();
  +            while (i != -1) {
  +                result.append(str.substring(startOfIndex, i));
  +                result.append(STRING_BEFORE_SEARCH);
  +                result.append(str.substring(i, i + searchStringLength) );
  +                result.append(STRING_AFTER_SEARCH);
  +                startOfIndex = i + searchStringLength;
  +                i = lcStr.indexOf(lcsearchString,startOfIndex);
  +            }
  +            result.append(str.substring(startOfIndex,str.length()));
  +            str = result.toString();
  +        }
  +        if (maxLength == TRUNK_SIZE) {
  +            result.append("[...]");
  +        }
  +    }
  +    return result.toString();
  +}
   %>
   <logic:present parameter="addComment">
   <script language="javascript"type="text/javascript"><!--//--><![CDATA[//><!--
  
  
  
  Index: page_categories_list.inc
  ===================================================================
  RCS file: 
/home/cvs/repository/corporate_portal_templates/src/view/jsp/include/page_categories_list.inc,v
  retrieving revision 1.2
  retrieving revision 1.2.4.1
  diff -u -r1.2 -r1.2.4.1
  --- page_categories_list.inc  18 Mar 2004 11:47:06 -0000      1.2
  +++ page_categories_list.inc  24 May 2005 12:24:09 -0000      1.2.4.1
  @@ -21,8 +21,8 @@
                    String curCategoriesProperty = (String) 
curCategoriesPropertiesEnum.nextElement();
                    if (curCategoriesProperty.startsWith("homepage")){
                        int pageID = new 
Integer(curCategory.getProperty(curCategoriesProperty)).intValue();
  -                     ContentPage cp = 
jData.page().getContentPage().getPage(pageID);
  -                     JahiaPage jp = 
cp.getPage(jData.params().getEntryLoadRequest(), 
jData.params().getOperationMode(), jData.params().getUser());
  +                     ContentPage cp2 = 
jData.page().getContentPage().getPage(pageID);
  +                     JahiaPage jp = 
cp2.getPage(jData.params().getEntryLoadRequest(), 
jData.params().getOperationMode(), jData.params().getUser());
                        categoryName = "<a href=\"" + jp.getURL(jData.params()) 
+ "\">" + curCategory.getTitle(jData.params().getLocale()) + "</a>";
                        categoryPath = getPath(jp, jData, true);
                       %>
  
  
  
  Index: searchresult.jsp
  ===================================================================
  RCS file: 
/home/cvs/repository/corporate_portal_templates/src/view/jsp/searchresult.jsp,v
  retrieving revision 1.19.4.1
  retrieving revision 1.19.4.2
  diff -u -r1.19.4.1 -r1.19.4.2
  --- searchresult.jsp  2 Mar 2005 10:00:46 -0000       1.19.4.1
  +++ searchresult.jsp  24 May 2005 12:24:10 -0000      1.19.4.2
  @@ -58,6 +58,84 @@
                                <pg:item>
                                <%
                                JahiaSearchHit thisHit = 
(JahiaSearchHit)searchResults.results().get(i);
  +                String teaser = thisHit.getTeaser();
  +                ParsedObject po = thisHit.getParsedObject();
  +                if (po != null) {
  +                    String fieldIDStr = 
po.getValue(JahiaSearchConstant.FIELD_FIELDID);
  +                    try {
  +                        int fieldID = Integer.parseInt(fieldIDStr);
  +                        ContentField cf = ContentField.getField(fieldID);
  +                        if (cf != null) {
  +                            int type = cf.getType();
  +                            if ((type == FieldTypes.BIGTEXT) || (type == 
FieldTypes.SMALLTEXT) ||
  +                                (type == FieldTypes.SMALLTEXT_SHARED_LANG )) 
{
  +                                String thisTeaser = cf.getValue(jParams);
  +                                if (thisTeaser != null) {
  +                                    teaser = removeTags(thisTeaser);
  +                                }
  +                            } else if (type == FieldTypes.FILE) {
  +                                logger.debug("Try to get infos from file for 
field ["+fieldID+"]");
  +                                JahiaField jf = 
ServicesRegistry.getInstance().getJahiaFieldService().loadField(cf.getID(),jParams);
  +                                // 
.getJahiaField(jParams.getEntryLoadRequest());
  +                                JahiaFileField fField = (JahiaFileField) 
jf.getObject();
  +                                JahiaSite site = 
ServicesRegistry.getInstance()
  +                                        
.getJahiaSitesService().getSite(jParams.getSiteID());
  +
  +                                logger.debug("RealName " + 
fField.getRealName ());
  +
  +                                DAVFileAccess file = 
JahiaWebdavBaseService.getInstance()
  +                                        .getDAVFileAccess (site, 
fField.getRealName ());
  +                                file.beginTransaction();
  +                                if (file.isValid () && file.hasRevisions () 
&& !file.isCollection ()) {
  +                                    String contentType = fField.getType (); 
// (String) file.getProperty("DAV:","getcontenttype");
  +                                    if (contentType != null) {
  +                                        if (!file.getPath().equals("#")) {
  +                                            try {
  +                                                InputStream ins = 
file.downloadFile();
  +                                                String charSet = null;
  +                                                CharsetDetection charsetDet 
= new CharsetDetection();
  +                                                
charsetDet.charsetDetection(ins);
  +                                                charSet = 
charsetDet.getCharset();
  +                                                ins.close();
  +                                                long lastModifiedDate = 
System.currentTimeMillis();
  +                                                try {
  +                                                    lastModifiedDate = 
file.getJahiaFileField()
  +                                                        .getLastModifDate();
  +                                                } catch ( Throwable t ){
  +                                                    logger.debug(t);
  +                                                }
  +                                                ins = file.downloadFile();
  +                                                
org.jahia.services.fileextraction.ExtractedDocument extDoc =
  +                                                    
ServicesRegistry.getInstance().getFileExtractionService()
  +                                                        
.getExtractedDocument(contentType,file.getPath(),lastModifiedDate,
  +                                                            
true,ins,charSet);
  +                                                if ( extDoc != null ){
  +                                                    teaser = 
extDoc.getContentAsString();
  +                                                    //logger.debug("Teaser 
is " + teaser);
  +                                                } else {
  +                                                    logger.debug("extDoc is 
NULL");
  +                                                }
  +                                                ins.close();
  +                                            } catch ( Throwable t ){
  +                                                logger.debug(t);
  +                                            }
  +                                        }
  +                                    } else {
  +                                        logger.debug("contentType is NULL");
  +                                    }
  +                                    teaser += " " + file.getName();
  +                                } else {
  +                                    logger.debug("if (file.isValid () && 
file.hasRevisions () && !file.isCollection ()) NOT PASSED");
  +                                }
  +                                file.commitTransaction();
  +                            }
  +                        }
  +                    } catch (NumberFormatException nfe) {
  +                        //logger.debug("Could not get refreshPageId: " + 
nfe);
  +                    }
  +                }
  +
  +                teaser = hl(teaser,searchString);
                                if (thisHit.page != null){
                                %>
                                <tr>
  @@ -69,17 +147,23 @@
                                        <td valign="top" width="7"><img 
src="<%=theURL%>/images/triangle.gif" alt="-"/></td>
                                        <td valign="top" width="10"><img 
src="<%=theURL%>/images/pix.gif" width="10" height="1" alt=""/></td>
                                        <td valign="top" width="100%">
  -                                     <a class="leftlinkon" 
href="<%=thisHit.page.getUrl(jData.params())%>"><b><%=thisHit.page.getTitle()%></b></a>
 - score : <%=thisHit.getScore()%> <% if (!oneHitPerPage){%>%<%}%><br/>
  -                                 <%
  -                                     if ( thisHit.type != FieldTypes.FILE ){
  -                                     %><span 
class="grey"><%=thisHit.getTeaser()%>...</span><%
  -                                     } else {
  -                                             String thisPicto = 
getPicto(thisHit.teaser);
  -                                     %>
  -                                     <span class="leftlink"><a 
href="<%=thisHit.fileDownloadUrl%>"><img
  -                                     
src="<%=theURL%>/images/icons/standard/<%=thisPicto%>.gif" 
alt="[<%=thisPicto%>]"
  -                                     width="16" height="16" 
border="0"/>&nbsp;<%=thisHit.getTeaser()%>...</a></span>
  -                                     <% } %>
  +                                         <a class="leftlinkon" 
href="<%=thisHit.page.getUrl(jData.params())%>"><b><%=thisHit.page.getTitle()%></b></a>
 - score : <%=thisHit.getScore()%> <% if (!oneHitPerPage){%>%<%}%><br/>
  +                        <%
  +                        if ( thisHit.type == FieldTypes.FILE ){
  +                            %><span class="grey"><%=teaser%></span><%
  +                            String thisPicto = getPicto(thisHit.teaser);
  +                            %>
  +                        <br/><span class="leftlink"><a 
href="<%=thisHit.fileDownloadUrl%>" target="_blank"><img
  +                            
src="<%=theURL%>/images/icons/standard/<%=thisPicto%>.gif" 
alt="[<%=thisPicto%>]"
  +                            width="16" height="16" 
border="0"/>&nbsp;<%=thisHit.teaser%>...</a></span>
  +                            <%
  +                        } else if ((thisHit.type == FieldTypes.BIGTEXT) || 
(thisHit.type == FieldTypes.SMALLTEXT) ||
  +                            (thisHit.type == 
FieldTypes.SMALLTEXT_SHARED_LANG )) {
  +                            %><span class="grey"><%=teaser%></span><%
  +                        } else {
  +                            %><span class="grey"><%=teaser%></span><%
  +                        }
  +                        %>
                                        </td>
                                </tr>
                                <% } %>
  
  
  
  Index: web_css.jsp
  ===================================================================
  RCS file: 
/home/cvs/repository/corporate_portal_templates/src/view/jsp/web_css.jsp,v
  retrieving revision 1.28.4.13
  retrieving revision 1.28.4.14
  diff -u -r1.28.4.13 -r1.28.4.14
  --- web_css.jsp       27 Apr 2005 10:43:45 -0000      1.28.4.13
  +++ web_css.jsp       24 May 2005 12:24:10 -0000      1.28.4.14
  @@ -942,4 +942,15 @@
        clear: both;
        font-size: 1px;
        line-height: 0px;
  +}
  +a.maincat {
  +    font-size:11px;
  +    font-weight: bold;
  +    color: <%=darkcolor1%>;
  +}
  +a.subcat {
  +    color: <%=darkcolor1%>;
  +}
  +span.hl {
  +    background: #FFFF66;
   }
  \ No newline at end of file
  

Reply via email to