Author: xlawrence
Date: Tue May 22 16:58:40 2007
New Revision: 670

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D670&repname=
=3Dcorporate_portal_templates_v2
Log:
finalize first version of Generali's enhanced form generator

Added:
    branches/JAHIA-5-0-SP-BRANCH/src/java/jahiatemplates/org/jahia/corporat=
eportalv2/search/
    branches/JAHIA-5-0-SP-BRANCH/src/java/jahiatemplates/org/jahia/corporat=
eportalv2/search/FormGeneratorContainerSearcher.java
Modified:
    branches/JAHIA-5-0-SP-BRANCH/src/jsp/common/declarations.inc
    branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/definitions.inc
    branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/display_form.inc
    branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/form_generator.jsp

Added: branches/JAHIA-5-0-SP-BRANCH/src/java/jahiatemplates/org/jahia/corpo=
rateportalv2/search/FormGeneratorContainerSearcher.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-5-0-SP-BRANCH/src/java/jahiatemplates/org/jahia/corporateportalv2/search/F=
ormGeneratorContainerSearcher.java&rev=3D670&repname=3Dcorporate_portal_tem=
plates_v2
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/src/java/jahiatemplates/org/jahia/corporat=
eportalv2/search/FormGeneratorContainerSearcher.java (added)
+++ branches/JAHIA-5-0-SP-BRANCH/src/java/jahiatemplates/org/jahia/corporat=
eportalv2/search/FormGeneratorContainerSearcher.java Tue May 22 16:58:40 20=
07
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2002-2006 Jahia Ltd
+ *
+ * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL),
+ * Version 1.0 (the "License"), or (at your option) any later version; you=
 may
+ * not use this file except in compliance with the License. You should have
+ * received a copy of the License along with this program; if not, you may=
 obtain
+ * a copy of the License at
+ *
+ *  http://www.jahia.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package jahiatemplates.org.jahia.corporateportalv2.search;
+
+import org.jahia.data.search.JahiaSearchHit;
+import org.jahia.data.search.JahiaSearchResult;
+import org.jahia.exceptions.JahiaException;
+import org.jahia.params.ProcessingContext;
+import org.jahia.registries.ServicesRegistry;
+import org.jahia.services.containers.ContentContainer;
+import org.jahia.services.search.*;
+import org.jahia.services.version.EntryLoadRequest;
+
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Specific Container searcher for the form generator template.
+ * We get the search string from the user input, then get the "id" fields =
of the container
+ * results
+ *
+ * @author Xavier Lawrence
+ */
+public class FormGeneratorContainerSearcher extends JahiaSearcher {
+
+    private static final org.apache.log4j.Logger logger =3D
+            org.apache.log4j.Logger.getLogger(FormGeneratorContainerSearch=
er.class);
+
+    private String fieldName;
+    private EntryLoadRequest loadRequest =3D EntryLoadRequest.CURRENT;
+    private int ctnListID =3D 0;
+    private int siteId =3D -1;
+    private int containerLevel =3D 0;
+    private String containerListName;
+
+    public FormGeneratorContainerSearcher(final int ctnListID,
+                                          final String query,
+                                          final EntryLoadRequest loadReque=
st,
+                                          final String fieldName) {
+        this.setCtnListID(ctnListID);
+        if (loadRequest !=3D null) {
+            this.setLoadRequest(loadRequest);
+        }
+        this.setQuery(query);
+        this.fieldName =3D fieldName;
+    }
+
+    public FormGeneratorContainerSearcher(final String containerListName,
+                                          final ProcessingContext params,
+                                          final String query,
+                                          final EntryLoadRequest loadReque=
st,
+                                          final String fieldName)
+            throws JahiaException {
+        if (containerListName !=3D null) {
+            int clistID =3D ServicesRegistry.getInstance().getJahiaContain=
ersService().
+                    getContainerListID(containerListName, params.getPage()=
.getID());
+            if (clistID !=3D -1) {
+                this.setCtnListID(clistID);
+            }
+        }
+        this.setQuery(query);
+        if (loadRequest !=3D null) {
+            this.setLoadRequest(loadRequest);
+        }
+        this.containerListName =3D containerListName;
+        this.fieldName =3D fieldName;
+    }
+
+    public String searchContainerIds(final String query,
+                                     final ProcessingContext jParams) thro=
ws JahiaException {
+        final ContainerSearcher searcher =3D new ContainerSearcher(jParams=
.getSiteID(), containerListName, query, loadRequest);
+        final JahiaSearchResult res =3D searcher.search(query, jParams);
+        final Iterator ite =3D res.results().iterator();
+        final StringBuffer ids =3D new StringBuffer();
+        try {
+            while (ite.hasNext()) {
+                final JahiaSearchHit hit =3D (JahiaSearchHit) ite.next();
+                final ContentContainer theObject =3D (ContentContainer) Co=
ntentContainer.getInstance(hit.getSearchHitObjectKey());
+                final String value =3D theObject.getJahiaContainer(jParams=
, jParams.getEntryLoadRequest()).
+                        getFieldValue(fieldName);
+                ids.append(value);
+                ids.append(" ");
+            }
+        } catch (final ClassNotFoundException cnfe) {
+            logger.error("Error in searchContainerIds", cnfe);
+        }
+        return ids.toString();
+    }
+
+    public JahiaSearchResult search(final String query,
+                                    final ProcessingContext jParams) throw=
s JahiaException {
+
+        final ContainerSearcher searcher =3D new ContainerSearcher(ctnList=
ID, query, loadRequest);
+        final JahiaSearchResult res =3D searcher.search(query, jParams);
+        final Iterator ite =3D res.results().iterator();
+        final StringBuffer finalQuery =3D new StringBuffer();
+        try {
+            while (ite.hasNext()) {
+                final JahiaSearchHit hit =3D (JahiaSearchHit) ite.next();
+                final ContentContainer theObject =3D (ContentContainer) Co=
ntentContainer.getInstance(hit.getSearchHitObjectKey());
+                final String value =3D theObject.getJahiaContainer(jParams=
, jParams.getEntryLoadRequest()).
+                        getFieldValue(fieldName);
+                finalQuery.append(value);
+                finalQuery.append(" ");
+            }
+        } catch (final ClassNotFoundException cnfe) {
+            logger.error("Error in search", cnfe);
+        }
+
+        return searcher.search(finalQuery.toString(), jParams);
+    }
+
+    public ArrayList getLanguageCodes() {
+        List locales =3D loadRequest.getLocales();
+        ArrayList result =3D new ArrayList();
+        for (int i =3D 0; i < locales.size(); i++) {
+            Locale locale =3D (Locale) locales.get(i);
+            result.add(locale.toString());
+        }
+        return result;
+    }
+
+    /**
+     * Lucene implementation
+     *
+     * @param query
+     * @param searchHandlers
+     * @param jParams
+     * @return
+     * @throws JahiaException
+     */
+    protected SearchResult doSearch(String query, String[] searchHandlers,=
 ProcessingContext jParams)
+            throws JahiaException {
+        final SearchResult result =3D new SearchResultImpl();
+        final ServicesRegistry sReg =3D ServicesRegistry.getInstance();
+        for (int i =3D 0; i < searchHandlers.length; i++) {
+            final SearchHandler searchHandler =3D sReg.getJahiaSearchServi=
ce().getSearchManager().
+                    getSearchHandler(searchHandlers[i]);
+            searchHandler.search(query, result);
+        }
+        return result;
+    }
+
+
+    public String getFieldName() {
+        return fieldName;
+    }
+
+    public void setFieldName(String fieldName) {
+        this.fieldName =3D fieldName;
+    }
+
+    public EntryLoadRequest getLoadRequest() {
+        return loadRequest;
+    }
+
+    public void setLoadRequest(EntryLoadRequest loadRequest) {
+        this.loadRequest =3D loadRequest;
+    }
+
+    public int getCtnListID() {
+        return ctnListID;
+    }
+
+    public void setCtnListID(int ctnListID) {
+        this.ctnListID =3D ctnListID;
+    }
+
+    public int getSiteId() {
+        return siteId;
+    }
+
+    public void setSiteId(int siteId) {
+        this.siteId =3D siteId;
+    }
+
+    public int getContainerLevel() {
+        return containerLevel;
+    }
+
+    public void setContainerLevel(int containerLevel) {
+        this.containerLevel =3D containerLevel;
+    }
+}

Modified: branches/JAHIA-5-0-SP-BRANCH/src/jsp/common/declarations.inc
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/src/jsp/common/declarations.inc&rev=3D670&repname=3Dcorporate_porta=
l_templates_v2
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/src/jsp/common/declarations.inc (original)
+++ branches/JAHIA-5-0-SP-BRANCH/src/jsp/common/declarations.inc Tue May 22=
 16:58:40 2007
@@ -61,6 +61,7 @@
     org.apache.slide.webdav.util.URLUtil,
     org.apache.lucene.queryParser.QueryParser,
     org.jahia.taglibs.esi.JesiConst,
+    jahiatemplates.org.jahia.corporateportalv2.search.*,
     org.jahia.ajax.usersession.userSettings"
 %><%@ taglib uri=3D"/WEB-INF/etc/struts/struts-bean" prefix=3D"bean" %><%@
 taglib uri=3D"/WEB-INF/etc/struts/struts-html" prefix=3D"html" %><%@

Modified: branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/definitions.i=
nc
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/src/jsp/form_generator/definitions.inc&rev=3D670&repname=3Dcorporat=
e_portal_templates_v2
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/definitions.inc (or=
iginal)
+++ branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/definitions.inc Tue=
 May 22 16:58:40 2007
@@ -53,9 +53,9 @@
             value=3D"<%=3DgetMultivalues(resBundleID,formTypes)%>"/>
         <content:declareField name=3D"defaultValue" title=3D"Default value=
(s) separated by semi-column ':'" type=3D"SmallText"
             titleKey=3D"form.defaultValue" bundleKey=3D"<%=3DresBundleID%>=
"/>
-        <content:declareContainerList name=3D"values" title=3D"Values">
+        <content:declareContainerList name=3D"values" title=3D"Values" con=
tainerListType=3D"<%=3DJahiaContainerDefinition.SINGLE_TYPE%>">
         <content:declareContainer>
-        <content:declareField name=3D"id" title=3D"Id" type=3D"SmallText"
+        <content:declareField name=3D"id" title=3D"Id" type=3D"SmallText" =
readOnly=3D"true"
             titleKey=3D"form.id" bundleKey=3D"<%=3DresBundleID%>"/>
         <content:declareField name=3D"value" title=3D"Value" type=3D"BigTe=
xt"
             titleKey=3D"form.value" bundleKey=3D"<%=3DresBundleID%>"/>

Modified: branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/display_form.=
inc
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/src/jsp/form_generator/display_form.inc&rev=3D670&repname=3Dcorpora=
te_portal_templates_v2
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/display_form.inc (o=
riginal)
+++ branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/display_form.inc Tu=
e May 22 16:58:40 2007
@@ -27,6 +27,16 @@
         formsEnum =3D forms.getContainers();
         boolean isFormOK =3D false;
         int t =3D 0;
+        final String searchString =3D (String)request.getParameter("search=
String");
+                               if (searchString !=3D null && 
searchString.length() > 0) {      =

+                               final FormGeneratorContainerSearcher 
containerSearcher =3D new For=
mGeneratorContainerSearcher("values",
+                                                       jParams, searchString, 
jParams.getEntryLoadRequest(), "id");=
                                                        =

+                       final String ids =3D 
containerSearcher.searchContainerIds(search=
String, jParams);               =

+                       ContainerSearcher theSearcher =3D new 
ContainerSearcher("values",
+                                                       jParams, ids, 
jParams.getEntryLoadRequest());                                           =

+                               request.setAttribute("values_search_handler", 
theSearcher);
+                               }
+
         while (formsEnum.hasMoreElements()) {
             t++;
             JahiaContainer form =3D (JahiaContainer) formsEnum.nextElement=
();
@@ -352,14 +362,7 @@
                                        if (rowValues =3D=3D null) {
                                                        rowValues =3D new 
ArrayList(fields.size());     =

                                        }
-                                       =

-                                       final String value =3D 
c.getFieldValue("value"=
);
-                                       if (value =3D=3D null) {
-                                                       rowValues.add("");
-                                       } else {
-                                                       rowValues.add(value);
-                                       }
-                                       =

+                                       rowValues.add(c);
                                        valuesByRow.put(key, rowValues);
                           } =

                        }
@@ -372,16 +375,22 @@
                        <br/>&nbsp;<br/>                =

                        <div class=3D"formResultListing">               =

                        <display:table name=3D"formResultList" class=3D"formR=
esultListing" pagesize=3D"15" id=3D"formResultListID"
-                               requestURI=3D'<%=3DbypassUrl%>' 
defaultsort=3D"1">
+                               requestURI=3D'<%=3DbypassUrl%>' 
defaultsort=3D"1"=
 defaultorder=3D"descending" >
                         <% =

                                final List rowValues =3D (List) 
pageContext.getAt=
tribute("formResultListID");
                                final Iterator columns =3D 
theContainers.iterator=
();
                                int i=3D0;
                                while (columns.hasNext()) {
                                                                                
                                        final JahiaContainer currentField =3D 
(JahiaContainer) colu=
mns.next(); =

+                                                                               
                                        JahiaContainer currentValue =3D null;
                                                                                
                                        String theValue =3D "";
                                                                                
                                        try { =

-                                                                               
                                                 theValue =3D (String) 
rowValues.get(i);        =

+                                                                               
                                                        currentValue =3D 
(JahiaContainer) rowValues.get(i); =

+                                                                               
                                                        theValue =3D 
currentValue.getFieldValue("value");
+                                                       if (theValue =3D=3D 
null) {
+                                                                       
theValue =3D "";
+                                                       }
+                                                                               
                                                        =

                                                                                
                                                        if 
(theValue.startsWith(contextPath)) {
                                                                                
                                                                        final 
StringBuffer buff =3D new StringBuffer(); =

                                                                                
                                                                        
buff.append("<a href=3D\"");
@@ -394,12 +403,29 @@
                                                                                
                                        } catch (Exception e) {
                                                                                
                                        } =

                         %>
+                               <% if (i =3D=3D 0) { %>
+                               <display:column 
title=3D"<%=3DcreationDateTitle%>=
" sortable=3D"true" comparator=3D"<%=3D comparator %>" >
+                                               
<%=3DcurrentValue.getContentContainer().getMeta=
dataDateValue("creationDate", jParams, "-", sdf) %>
+                               </display:column>       =

+                               <% } %>
+                               =

                                <display:column 
title=3D"<%=3DcurrentField.getFie=
ldValue("fieldTitle","")%>" sortable=3D"true" comparator=3D"<%=3D comparato=
r %>" >
                                <%=3DtheValue%>
+                               <% final ContainerBean currentFieldBean =3D new 
C=
ontainerBean(currentValue, jParams);    =

+                                        
jData.gui().html().drawBeginActionMenu(currentF=
ieldBean ,
+                                    null, null, false, "", "jahiatemplates=
.Corporate_portal_templates_v2",
+                                    null, out);
+                                 %>    =

                                </display:column>
                                <% i++; %>
                                <% } %> =

                       </display:table>         =

+                       <form method=3D"post" action=3D"<%=3DbypassUrl%>" nam=
e=3D"search" >
+                                       <content:resourceBundle 
resourceBundle=3D"jahiatemp=
lates.Corporate_portal_templates_v2"
+                                                               
resourceName=3D"search"/>: <input type=3D"text" =
name=3D"searchString"/>
+                                                                               
                        <input type=3D"submit" name=3D"submitbutton" 
value=3D"<conten=
t:resourceBundle resourceBundle=3D"jahiatemplates.Corporate_portal_template=
s_v2"
+                                                               
resourceName=3D"poll.submit"/>"/>
+                       </form>
                       </div>   =

                         <%
                     }

Modified: branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/form_generato=
r.jsp
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/src/jsp/form_generator/form_generator.jsp&rev=3D670&repname=3Dcorpo=
rate_portal_templates_v2
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/form_generator.jsp =
(original)
+++ branches/JAHIA-5-0-SP-BRANCH/src/jsp/form_generator/form_generator.jsp =
Tue May 22 16:58:40 2007
@@ -21,6 +21,8 @@
 logger.debug("Entering form_generator.jsp");
 Vector emptyMandatoryFields =3D new Vector();
 boolean storePostedValues =3D false;
+final String creationDateTitle =3D JahiaResourceBundle.getString(ResourceB=
undle.getBundle("jahiatemplates.Corporate_portal_templates_v2", jParams.get=
Locale()), "doc.creationDate", jParams.getLocale());    =

+final SimpleDateFormat sdf =3D new SimpleDateFormat("dd.MM.yyyy");
 %>
 <%@ include file=3D"definitions.inc"%>
 <%@ include file=3D"process_post.inc"%>

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to