cmailleux    2005/03/02 15:31:24 CET

  Modified files:        (Branch: JAHIA-4-1-BRANCH)
    etc/struts           validator-jahia-rules.xml 
    src/java/org/jahia/data/containers ContainerValidatorBase.java 
    src/java/org/jahia/engines/validation 
                                          EngineValidationHelper.java 
                                          JahiaFieldChecks.java 
                                          JahiaMltHelper.java 
                                          ValidationError.java 
                                          ValidationErrorSorter.java 
  Log:
  Added some documentation

  Bug fixes and Some name have changed
  
  Revision  Changes    Path
  1.1.2.2   +35 -18    jahia/etc/struts/validator-jahia-rules.xml
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/etc/struts/validator-jahia-rules.xml.diff?r1=1.1.2.1&r2=1.1.2.2&f=h
  1.1.2.3   +321 -244  
jahia/src/java/org/jahia/data/containers/ContainerValidatorBase.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/data/containers/ContainerValidatorBase.java.diff?r1=1.1.2.2&r2=1.1.2.3&f=h
  1.1.2.2   +4 -7      
jahia/src/java/org/jahia/engines/validation/EngineValidationHelper.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/validation/EngineValidationHelper.java.diff?r1=1.1.2.1&r2=1.1.2.2&f=h
  1.1.2.2   +103 -23   
jahia/src/java/org/jahia/engines/validation/JahiaFieldChecks.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/validation/JahiaFieldChecks.java.diff?r1=1.1.2.1&r2=1.1.2.2&f=h
  1.1.2.2   +51 -15    
jahia/src/java/org/jahia/engines/validation/JahiaMltHelper.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/validation/JahiaMltHelper.java.diff?r1=1.1.2.1&r2=1.1.2.2&f=h
  1.1.2.2   +6 -10     
jahia/src/java/org/jahia/engines/validation/ValidationError.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/validation/ValidationError.java.diff?r1=1.1.2.1&r2=1.1.2.2&f=h
  1.1.2.2   +12 -7     
jahia/src/java/org/jahia/engines/validation/ValidationErrorSorter.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/validation/ValidationErrorSorter.java.diff?r1=1.1.2.1&r2=1.1.2.2&f=h
  
  
  
  Index: validator-jahia-rules.xml
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/etc/struts/Attic/validator-jahia-rules.xml,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- validator-jahia-rules.xml 23 Feb 2005 10:02:39 -0000      1.1.2.1
  +++ validator-jahia-rules.xml 2 Mar 2005 14:31:23 -0000       1.1.2.2
  @@ -3,23 +3,40 @@
        "-//Apache Software Foundation//DTD Commons Validator Rules 
Configuration 1.1.3//EN"
        "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd";>
   <form-validation>
  -  <global>
  -   <!-- epf mandatory MLText -->
  -    <validator name="mandatoryLanguageText" 
classname="org.jahia.engines.validation.JahiaFieldChecks" 
  -                     method="validateMandatoryMLText" 
methodParams="java.lang.Object,
  -                       org.apache.commons.validator.ValidatorAction,
  -                       org.apache.commons.validator.Field,
  -                       org.apache.struts.action.ActionMessages,
  -                       javax.servlet.http.HttpServletRequest" 
  -                       msg="errors.mandlang"/>
  +    <global>
  +        <!-- validator to check whether all mandatory languages are set -->
  +        <validator name="requiredMandatoryLang" 
  +              classname="org.jahia.engines.validation.JahiaFieldChecks" 
  +                  method="validateMandatoryMLText" 
  +           methodParams="java.lang.Object,
  +                         org.apache.commons.validator.ValidatorAction,
  +                         org.apache.commons.validator.Field,
  +                         org.apache.struts.action.ActionMessages,
  +                         javax.servlet.http.HttpServletRequest" 
  +                     msg="errors.mandlang"/>
                          
  -   <!-- epf maxlength MLText -->
  -    <validator name="maxlengthLanguageText" 
classname="org.jahia.engines.validation.JahiaFieldChecks" 
  -                     method="validateMaxLengthMLText" 
methodParams="java.lang.Object,
  -                       org.apache.commons.validator.ValidatorAction,
  -                       org.apache.commons.validator.Field,
  -                       org.apache.struts.action.ActionMessages,
  -                       javax.servlet.http.HttpServletRequest" 
  -                       msg="errors.maxlength"/>
  -  </global>
  +        <!-- validator to check that the input for each language does not 
exceed a specified maximum length -->
  +        <validator name="maxlengthAllLang" 
  +              classname="org.jahia.engines.validation.JahiaFieldChecks" 
  +                      method="validateMaxLengthMLText" 
  +           methodParams="java.lang.Object,
  +                        org.apache.commons.validator.ValidatorAction,
  +                        org.apache.commons.validator.Field,
  +                        org.apache.struts.action.ActionMessages,
  +                        javax.servlet.http.HttpServletRequest" 
  +                 depends=""
  +                    msg="errors.maxlength"/>
  +
  +        <!-- validator to check that the input for each language isn't less 
than a specified minimum length -->
  +        <validator name="minlengthAllLang" 
  +              classname="org.jahia.engines.validation.JahiaFieldChecks" 
  +                              method="validateMinLengthMLText" 
  +           methodParams="java.lang.Object,
  +                        org.apache.commons.validator.ValidatorAction,
  +                        org.apache.commons.validator.Field,
  +                        org.apache.struts.action.ActionMessages,
  +                        javax.servlet.http.HttpServletRequest" 
  +                depends=""
  +                    msg="errors.minlength"/>
  +    </global>
   </form-validation>
  
  
  
  Index: ContainerValidatorBase.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/data/containers/Attic/ContainerValidatorBase.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- ContainerValidatorBase.java       23 Feb 2005 10:02:39 -0000      1.1.2.2
  +++ ContainerValidatorBase.java       2 Mar 2005 14:31:23 -0000       1.1.2.3
  @@ -1,46 +1,27 @@
   /*
  - *                                   ____.
  - *                       __/\ ______|    |__/\.     _______
  - *            __   .____|    |       \   |    +----+       \
  - *    _______|  /--|    |    |    -   \  _    |    :    -   \_________
  - *   \\______: :---|    :    :           |    :    |         \________>
  - *           |__\---\_____________:______:    :____|____:_____\
  - *                                      /_____|
  - *
  - *              . . . i n   j a h i a   w e   t r u s t . . .
  - *
  - *
  - *
  - * ----- BEGIN LICENSE BLOCK -----
  - * Version: JCSL 1.0
  - *
  - * The contents of this file are subject to the Jahia Community Source 
License
  - * 1.0 or later (the "License"); you may not use this file except in
  - * compliance with the License. You may obtain a copy of the License at
  - * http://www.jahia.org/license
  - *
  - * Software distributed under the License is distributed on an "AS IS" basis,
  - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  - * for the rights, obligations and limitations governing use of the contents
  - * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
  - * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. 
JAHIA
  - * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
  - *
  - * The Shared Modifications are Jahia View Helper.
  - *
  - * The Developer of the Shared Modifications is Jahia Solution S�rl.
  - * Portions created by the Initial Developer are Copyright (C) 2002 by the
  - * Initial Developer. All Rights Reserved.
  - *
  - * Contributor(s):
  - * 13-Aug-2003, Commaro, Benjamin Papez
  - *
  - * ----- END LICENSE BLOCK -----
  + * ____. __/\ ______| |__/\. _______ __ .____| | \ | +----+ \ _______| /--| 
| | - \ _ | : -
  + * \_________ \\______: :---| : : | : | \________> 
|__\---\_____________:______:
  + * :____|____:_____\ /_____| . . . i n j a h i a w e t r u s t . . . ----- 
BEGIN
  + * LICENSE BLOCK ----- Version: JCSL 1.0 The contents of this file are 
subject
  + * to the Jahia Community Source License 1.0 or later (the "License"); you 
may
  + * not use this file except in compliance with the License. You may obtain a
  + * copy of the License at http://www.jahia.org/license Software distributed
  + * under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 
ANY
  + * KIND, either express or implied. See the License for the rights, 
obligations
  + * and limitations governing use of the contents of the file. The Original 
and
  + * Upgraded Code is the Jahia CMS and Portal Server. The developer of the
  + * Original and Upgraded Code is JAHIA Ltd. JAHIA Ltd. owns the copyrights in
  + * the portions it created. All Rights Reserved. The Shared Modifications are
  + * Jahia View Helper. The Developer of the Shared Modifications is Jahia
  + * Solution S�rl. Portions created by the Initial Developer are Copyright 
(C)
  + * 2002 by the Initial Developer. All Rights Reserved. Contributor(s):
  + * 28-Feb-2005, Commaro, Benjamin Papez ----- END LICENSE BLOCK -----
    */
   package org.jahia.data.containers;
   
   import java.util.*;
   
  +import org.jahia.data.FormDataManager;
   import org.jahia.data.fields.*;
   import org.jahia.engines.JahiaEngine;
   import org.jahia.engines.shared.JahiaPageEngineTempBean;
  @@ -51,225 +32,321 @@
   import org.jahia.utils.LanguageCodeConverters;
   
   /**
  - * Used as the base class for all container validator beans.  
  + * Used as the base class for all container validator beans.
    * 
    * @author Benjamin Papez
    */
  -public abstract class ContainerValidatorBase {
  +public abstract class ContainerValidatorBase
  +{
   
  -    private static final org.apache.log4j.Logger logger =
  -        org.apache.log4j.Logger.getLogger(ContainerValidatorBase.class);
  +  private static final org.apache.log4j.Logger logger = 
org.apache.log4j.Logger
  +    .getLogger(ContainerValidatorBase.class);
   
  -    protected ContainerFacadeInterface cf = null;
  +  protected ContainerFacadeInterface cf = null;
   
  -    protected ParamBean jParams = null;
  -
  -    /**
  -     * The constructor obtains the container facade and the ParamBean 
  -     * object used in the Jahia engines. 
  -     * 
  -     * @param ContainerFacadeInterface newCf
  -     * @param ParamBean newParams
  -     */
  -    public ContainerValidatorBase(
  -        ContainerFacadeInterface newCf,
  -        ParamBean newParams) {
  -        super();
  -        cf = newCf;
  -        jParams = newParams;
  +  protected ParamBean jParams = null;
  +
  +  /**
  +   * The constructor obtains the container facade and the ParamBean object 
used
  +   * in the Jahia engines.
  +   * 
  +   * @param newCf
  +   * @param newParams
  +   */
  +  public ContainerValidatorBase(ContainerFacadeInterface newCf,
  +    ParamBean newParams)
  +  {
  +    super();
  +    cf = newCf;
  +    jParams = newParams;
  +  }
  +
  +  /**
  +   * Gets the Jahia field out of the container field facade. The field is
  +   * returned in the currently processed language. The version is either the
  +   * staged or the active version. Keywords for uninitialized values are
  +   * deleted. For a PAGE, the title is returned.
  +   * 
  +   * @param fieldName
  +   * @return value
  +   */
  +  protected String getJahiaField(String fieldName)
  +  {
  +    String field = null;
  +
  +    try
  +    {
  +      Map engineMap = (HashMap)jParams.getSession().getAttribute(
  +        "jahia_session_engineMap");
  +
  +      ArrayList locales = new ArrayList();
  +      String languageCode = (String)engineMap
  +        .get(JahiaEngine.PROCESSING_LANGUAGECODE);
  +      locales.add(LanguageCodeConverters.languageCodeToLocale(languageCode));
  +
  +      EntryLoadRequest entryLoadRequest = new EntryLoadRequest(
  +        EntryLoadRequest.STAGING_WORKFLOW_STATE
  +          | EntryLoadRequest.ACTIVE_WORKFLOW_STATE, 0, locales);
  +
  +      Enumeration fields = cf.getFields();
  +
  +      while (fields.hasMoreElements() && field == null)
  +      {
  +        JahiaContentFieldFacade cff = (JahiaContentFieldFacade)fields
  +          .nextElement();
  +
  +        JahiaField newJf = cff.getField(entryLoadRequest, false);
  +        if (fieldName.equals(newJf.getDefinition().getName()))
  +        {
  +          switch (newJf.getType())
  +          {
  +            case FieldTypes.PAGE:
  +              HashMap pageBeans = (HashMap)jParams.getSession().getAttribute(
  +                "Page_Field.PageBeans");
  +              if (pageBeans == null)
  +              {
  +                pageBeans = new HashMap();
  +              }
  +
  +              JahiaPageEngineTempBean pageBean = 
(JahiaPageEngineTempBean)pageBeans
  +                .get(newJf.getDefinition().getName());
  +
  +              field = pageBean.getTitle(languageCode);
  +              break;
  +
  +            case FieldTypes.BIGTEXT:
  +              field = removeDefaultHtmlTags(
  +                newJf.getValue());
  +              break;
  +
  +            case FieldTypes.DATE:
  +              if (newJf.getValue() != null
  +                && newJf.getValue().toUpperCase().indexOf("JAHIA_CALENDAR") 
!= -1)
  +                field = "";
  +              else
  +                field = newJf.getValue();
  +              break;
  +
  +            case FieldTypes.FILE:
  +              if (newJf.getValue() != null
  +                && newJf.getValue().toUpperCase().indexOf("<EMPTY>") != -1)
  +                field = "";
  +              else
  +                field = newJf.getValue();
  +              break;
  +
  +            case FieldTypes.APPLICATION:
  +              field = newJf.getObject().toString();
  +              break;
  +
  +            default:
  +              field = newJf.getValue();
  +              break;
  +          }
  +        }
  +      }
  +    }
  +    catch (JahiaException e)
  +    {
  +      logger.error("Error in retrieving Jahia field :", e);
       }
   
  -    /**
  -     * Gets the Jahia field out of the container field facade. The 
  -     * field is returned in the currently processed language. The 
  -     * version is either the staged or the active version.
  -     * Keywords for uninitialized values are deleted.
  -     * For a PAGE, the title is returned.
  -     * 
  -     * @param String fieldName
  -     * @return value
  -     */
  -    protected String getJahiaField(String fieldName) {
  -        String field = null;
  -
  -        try {
  -            Map engineMap =
  -                (HashMap)jParams.getSession().getAttribute(
  -                    "jahia_session_engineMap");
  -
  -            ArrayList locales = new ArrayList();
  -            String languageCode =
  -                (String)engineMap.get(JahiaEngine.PROCESSING_LANGUAGECODE);
  -            locales.add(
  -                LanguageCodeConverters.languageCodeToLocale(languageCode));
  -
  -            EntryLoadRequest entryLoadRequest =
  -                new EntryLoadRequest(
  -                    EntryLoadRequest.STAGING_WORKFLOW_STATE
  -                        | EntryLoadRequest.ACTIVE_WORKFLOW_STATE,
  -                    0,
  -                    locales);
  -
  -            Enumeration fields = cf.getFields();
  -
  -            while (fields.hasMoreElements() && field == null) {
  -                JahiaContentFieldFacade cff =
  -                    (JahiaContentFieldFacade)fields.nextElement();
  -
  -                JahiaField newJf = cff.getField(entryLoadRequest, false);
  -                if (fieldName.equals(newJf.getDefinition().getName())) {
  -                    switch (newJf.getType()) {
  -                        case FieldTypes.PAGE :
  -                            HashMap pageBeans =
  -                                (HashMap)jParams.getSession().getAttribute(
  -                                    "Page_Field.PageBeans");
  -                            if (pageBeans == null) {
  -                                pageBeans = new HashMap();
  -                            }
  -
  -                            JahiaPageEngineTempBean pageBean =
  -                                (JahiaPageEngineTempBean)pageBeans.get(
  -                                    newJf.getDefinition().getName());
  -
  -                            field = pageBean.getTitle(languageCode);
  -                            break;
  -
  -                        case FieldTypes.DATE :
  -                            if (newJf.getValue() != null
  -                                && newJf.getValue().toUpperCase().indexOf(
  -                                    "JAHIA_CALENDAR")
  -                                    != -1)
  -                                field = "";
  -                            else
  -                                field = newJf.getValue();
  -                            break;
  -
  -                        case FieldTypes.FILE :
  -                            if (newJf.getValue() != null
  -                                && newJf.getValue().toUpperCase().indexOf(
  -                                    "<EMPTY>")
  -                                    != -1)
  -                                field = "";
  -                            else
  -                                field = newJf.getValue();
  -                            break;
  -
  -                        case FieldTypes.APPLICATION :
  -                            field = (String)newJf.getObject().toString();
  -                            break;
  -
  -                        default :
  -                            field = newJf.getValue();
  -                            break;
  -                    }
  +    return field;
  +  }
  +
  +  /**
  +   * Gets the Jahia multivalue field out of the container field facade. The
  +   * field is returned in the currently processed language. The version is
  +   * either the staged or the active version. The field values are converted 
to
  +   * a String array.
  +   * 
  +   * @param fieldName
  +   * @return fieldValues
  +   */
  +  protected JahiaMltHelper getJahiaMultiLanguageField(String fieldName)
  +  {
  +    JahiaMltHelper field = null;
  +
  +    try
  +    {
  +      Enumeration fields = cf.getFields();
  +
  +      while (fields.hasMoreElements() && field == null)
  +      {
  +        JahiaContentFieldFacade cff = (JahiaContentFieldFacade)fields
  +          .nextElement();
  +
  +        Enumeration fieldsPerLanguage = cff.getFields();
  +
  +        while (fieldsPerLanguage.hasMoreElements())
  +        {
  +
  +          JahiaField newJf = (JahiaField)fieldsPerLanguage.nextElement();
  +
  +          if (fieldName.equals(newJf.getDefinition().getName()))
  +          {
  +            if (field == null)
  +              field = new JahiaMltHelper(jParams.getSite()
  +                .getLanguageSettings());
  +
  +            switch (newJf.getType())
  +            {
  +              case FieldTypes.PAGE:
  +                HashMap pageBeans = 
(HashMap)jParams.getSession().getAttribute(
  +                  "Page_Field.PageBeans");
  +                if (pageBeans == null)
  +                {
  +                  pageBeans = new HashMap();
                   }
  -            }
  -        } catch (JahiaException e) {
  -            logger.error("Error in retrieving Jahia field :", e);
  -        }
   
  -        return field;
  -    }
  +                JahiaPageEngineTempBean pageBean = 
(JahiaPageEngineTempBean)pageBeans
  +                  .get(newJf.getDefinition().getName());
   
  -    /**
  -       * Gets the Jahia multivalue field out of the container field facade. 
The 
  -       * field is returned in the currently processed language. The 
  -       * version is either the staged or the active version.
  -       * The field values are converted to a String array.
  -       *  
  -       * @param String fieldName
  -       * @return fieldValues
  -       */
  -    protected JahiaMltHelper getJahiaMultiLanguageField(String fieldName) {
  -        JahiaMltHelper field = null;
  -
  -        try {
  -            Enumeration fields = cf.getFields();
  -
  -            while (fields.hasMoreElements() && field == null) {
  -                JahiaContentFieldFacade cff =
  -                    (JahiaContentFieldFacade)fields.nextElement();
  -
  -                Enumeration fieldsPerLanguage = cff.getFields();
  -
  -                while (fieldsPerLanguage.hasMoreElements()) {
  -
  -                    JahiaField newJf =
  -                        (JahiaField)fieldsPerLanguage.nextElement();
  -
  -                    if (fieldName.equals(newJf.getDefinition().getName())) {
  -                        if (field == null)
  -                            field =
  -                                new JahiaMltHelper(
  -                                    jParams.getSite().getLanguageSettings());
  -
  -                        switch (newJf.getType()) {
  -                            case FieldTypes.PAGE :
  -                                HashMap pageBeans =
  -                                    (HashMap)jParams
  -                                        .getSession()
  -                                        .getAttribute(
  -                                        "Page_Field.PageBeans");
  -                                if (pageBeans == null) {
  -                                    pageBeans = new HashMap();
  -                                }
  -
  -                                JahiaPageEngineTempBean pageBean =
  -                                    (JahiaPageEngineTempBean)pageBeans.get(
  -                                        newJf.getDefinition().getName());
  -
  -                                field.addMltItem(
  -                                    newJf.getLanguageCode(),
  -                                    pageBean.getTitle(
  -                                        newJf.getLanguageCode()));
  -                                break;
  -
  -                            case FieldTypes.DATE :
  -                                if (newJf.getValue() != null
  -                                    && 
newJf.getValue().toUpperCase().indexOf(
  -                                        "JAHIA_CALENDAR")
  -                                        != -1)
  -                                    field.addMltItem(
  -                                        newJf.getLanguageCode(),
  -                                        "");
  -                                else
  -                                    field.addMltItem(
  -                                        newJf.getLanguageCode(),
  -                                        newJf.getValue());
  -                                break;
  -
  -                            case FieldTypes.FILE :
  -                                if (newJf.getValue() != null
  -                                    && 
newJf.getValue().toUpperCase().indexOf(
  -                                        "<EMPTY>")
  -                                        != -1)
  -                                    field.addMltItem(
  -                                        newJf.getLanguageCode(),
  -                                        "");
  -                                else
  -                                    field.addMltItem(
  -                                        newJf.getLanguageCode(),
  -                                        newJf.getValue());
  -                                break;
  -
  -                            case FieldTypes.APPLICATION :
  -                                field.addMltItem(
  -                                    newJf.getLanguageCode(),
  -                                    (String)newJf.getObject().toString());
  -                                break;
  -
  -                            default :
  -                                field.addMltItem(
  -                                    newJf.getLanguageCode(),
  -                                    newJf.getValue());
  -                                break;
  -                        }
  -                    }
  -                }
  +                field.addMltItem(newJf.getLanguageCode(), pageBean
  +                  .getTitle(newJf.getLanguageCode()));
  +                break;
  +
  +              case FieldTypes.BIGTEXT:
  +                field.addMltItem(newJf.getLanguageCode(), 
  +                  removeDefaultHtmlTags(newJf.getValue()));
  +                break;
  +
  +              case FieldTypes.DATE:
  +                if (newJf.getValue() != null
  +                  && 
newJf.getValue().toUpperCase().indexOf("JAHIA_CALENDAR") != -1)
  +                  field.addMltItem(newJf.getLanguageCode(), "");
  +                else
  +                  field.addMltItem(newJf.getLanguageCode(), 
newJf.getValue());
  +                break;
  +
  +              case FieldTypes.FILE:
  +                if (newJf.getValue() != null
  +                  && newJf.getValue().toUpperCase().indexOf("<EMPTY>") != -1)
  +                  field.addMltItem(newJf.getLanguageCode(), "");
  +                else
  +                  field.addMltItem(newJf.getLanguageCode(), FormDataManager
  +                    .getInstance().removeSpecialTags(newJf.getValue()));
  +                break;
  +
  +              case FieldTypes.APPLICATION:
  +                field.addMltItem(newJf.getLanguageCode(), newJf.getObject()
  +                  .toString());
  +                break;
  +
  +              default:
  +                field.addMltItem(newJf.getLanguageCode(), newJf.getValue());
  +                break;
               }
  -        } catch (JahiaException e) {
  -            logger.error("Error in retrieving Jahia field :", e);
  +          }
           }
  -        return field;
  +      }
       }
  +    catch (JahiaException e)
  +    {
  +      logger.error("Error in retrieving Jahia field :", e);
  +    }
  +    return field;
  +  }
  +  
  +  /**
  +   * Remove tags <html>, <br>
  +   *
  +   * @param str
  +   * @return the string with removed tags
  +   */
  +  public String removeDefaultHtmlTags (String str) {
  +      if (str == null) {
  +          return null;
  +      }
  +
  +      str = removeTags(str, "html");
  +      str = removeTag(str, "br");
  +
  +      return str;
  +  }
  +
  +  /*
  +   * Remove a start & end tag in a string
  +   * For example removeTags(str,"title") will remove <title> and </title>
  +   * @author POL
  +   * @version 1.0   POL 23/01/2002
  +   * @param  str    Input String
  +   * @param  tag    Tag to remove
  +   * @return str
  +   **/
  +  private String removeTags (String str, String tag) {
  +      str = removeTag(str, tag);
  +      str = removeTag(str, "/" + tag);
  +      str = removeSpacesAndBreaks(str);
  +      return str;
  +  }
  +
  +  /*
  +   * Remove a tag from a string
  +   * Exemple: removeTag(str,"body") will remove <body bgcolor="#ffffff">
  +   * @author POL
  +   * @version 1.0   POL 23/01/2002
  +   * @param  str    Input String
  +   * @param  tag    Tag to remove
  +   * @return str
  +   **/
  +  private String removeTag (String str, String tag) {
  +      if (str == null) {
  +          return null;
  +      }
  +      StringBuffer result = new StringBuffer(str.length());
  +      String strLower = str.toLowerCase();
  +      tag = tag.toLowerCase();
  +      int startOfIndex = 0;
  +      int i = strLower.indexOf("<" + tag);
  +      while (i != -1) {
  +          result.append(str.substring(startOfIndex, i));
  +          i = strLower.indexOf(">", i);
  +          if (i != -1) {
  +              startOfIndex = i + 1;
  +          }
  +          i = strLower.indexOf("<" + tag, startOfIndex);
  +      }
  +      str = result.append(str.substring(startOfIndex, 
str.length())).toString();
  +      return str;
  +  }
  +
  +  /*
  +   * Remove a tag from a string
  +   * Exemple: removeTag(str,"body") will remove <body bgcolor="#ffffff">
  +   * @author POL
  +   * @version 1.0   POL 23/01/2002
  +   * @param  str    Input String
  +   * @param  tag    Tag to remove
  +   * @return str
  +   **/
  +  private String removeSpacesAndBreaks (String str) {
  +      if (str == null) {
  +          return null;
  +      }
  +      StringBuffer result = new StringBuffer(str.length());
  +      int startOfIndex = 0;
  +      int i = str.indexOf("/r");
  +      while (i != -1) {
  +          result.append(str.substring(startOfIndex, i));
  +          startOfIndex = i + 2;
  +          i = str.indexOf("/r", startOfIndex);
  +      }
  +      
  +      str = result.append(str.substring(startOfIndex, 
str.length())).toString();
  +      result = new StringBuffer(str.length());      
  +      startOfIndex = 0;      
  +      i = str.indexOf("/r");
  +      while (i != -1) {
  +          result.append(str.substring(startOfIndex, i));
  +          startOfIndex = i + 2;
  +          i = str.indexOf("/r", startOfIndex);
  +      }
  +      
  +      str = result.append(str.substring(startOfIndex, 
str.length())).toString();
  +      
  +      return str.trim();
  +  }  
  +  
   }
  +
  
  
  
  Index: EngineValidationHelper.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/validation/Attic/EngineValidationHelper.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- EngineValidationHelper.java       23 Feb 2005 10:02:40 -0000      1.1.2.1
  +++ EngineValidationHelper.java       2 Mar 2005 14:31:23 -0000       1.1.2.2
  @@ -33,7 +33,7 @@
    * Initial Developer. All Rights Reserved.
    *
    * Contributor(s):
  - * 13-Aug-2003, Jahia Solutions Sarl: Khue Nguyen
  + * 28-Feb-2005, Commaro, Benjamin Papez
    *
    * ----- END LICENSE BLOCK -----
    */
  @@ -46,8 +46,9 @@
   
   /**
    *
  - * <p>Title: </p>
  - * <p>Description: </p>
  + * <p>Title: EngineValidationHelper</p>
  + * <p>Description: This class is used to ease the validation process and 
groups the 
  + *                 validation errors per screen. </p>
    * <p>Copyright: Copyright (c) 2004</p>
    * <p>Company: Jahia Ltd</p>
    * @author not attributable
  @@ -55,10 +56,6 @@
    */
   public class EngineValidationHelper {
   
  -    /** logging */
  -    private static final org.apache.log4j.Logger logger =
  -            org.apache.log4j.Logger.getLogger (EngineValidationHelper.class);
  -
       private String previousScreen;
       private String nextScreen;
       private ArrayList validationErrors = new ArrayList();
  
  
  
  Index: JahiaFieldChecks.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/validation/Attic/JahiaFieldChecks.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- JahiaFieldChecks.java     23 Feb 2005 10:02:40 -0000      1.1.2.1
  +++ JahiaFieldChecks.java     2 Mar 2005 14:31:23 -0000       1.1.2.2
  @@ -1,8 +1,41 @@
   /*
  - * Created on Feb 21, 2005
  + *                                   ____.
  + *                       __/\ ______|    |__/\.     _______
  + *            __   .____|    |       \   |    +----+       \
  + *    _______|  /--|    |    |    -   \  _    |    :    -   \_________
  + *   \\______: :---|    :    :           |    :    |         \________>
  + *           |__\---\_____________:______:    :____|____:_____\
  + *                                      /_____|
    *
  - * To change the template for this generated file go to
  - * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  + *              . . . i n   j a h i a   w e   t r u s t . . .
  + *
  + *
  + *
  + * ----- BEGIN LICENSE BLOCK -----
  + * Version: JCSL 1.0
  + *
  + * The contents of this file are subject to the Jahia Community Source 
License
  + * 1.0 or later (the "License"); you may not use this file except in
  + * compliance with the License. You may obtain a copy of the License at
  + * http://www.jahia.org/license
  + *
  + * Software distributed under the License is distributed on an "AS IS" basis,
  + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  + * for the rights, obligations and limitations governing use of the contents
  + * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
  + * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. 
JAHIA
  + * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
  + *
  + * The Shared Modifications are Jahia View Helper.
  + *
  + * The Developer of the Shared Modifications is Jahia Solution S�rl.
  + * Portions created by the Initial Developer are Copyright (C) 2002 by the
  + * Initial Developer. All Rights Reserved.
  + *
  + * Contributor(s):
  + * 28-Feb-2005, Commaro, Benjamin Papez
  + *
  + * ----- END LICENSE BLOCK -----
    */
   package org.jahia.engines.validation;
   
  @@ -19,11 +52,14 @@
   import org.jahia.services.sites.SiteLanguageSettings;
   
   /**
  - * @author pap
  - *
  - * To change the template for this generated type comment go to
  - * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  - */
  +*
  +* <p>Title: JahiaFieldChecks</p>
  +* <p>Description: This class implements the Jahia specific user input 
validation methods.</p>
  +* <p>Copyright: Copyright (c) 2004</p>
  +* <p>Company: Jahia Ltd</p>
  +* @author not attributable
  +* @version 1.0
  +*/
   public class JahiaFieldChecks extends FieldChecks {
       private static final org.apache.log4j.Logger logger =
           org.apache.log4j.Logger.getLogger(JahiaFieldChecks.class);
  @@ -37,6 +73,7 @@
   
       /**
        * Checks if texts for all languages are provided.
  +     * 
        * @param bean
        * @param va
        * @param field
  @@ -61,11 +98,6 @@
               return false;
           } else {
               JahiaMltHelper mltHelper = (JahiaMltHelper)value;
  -
  -                     logger.debug(
  -                    "validate MLT field: "
  -                        + field.getProperty());
  -
               if (!isAllMandatoryLanguagesSet(mltHelper)) {
                   errors.add(
                       field.getKey(),
  @@ -76,6 +108,16 @@
           }
       }
   
  +    /**
  +     * Checks if texts for all languages do not exceed a specified maximum 
length.
  +     * 
  +     * @param bean
  +     * @param va
  +     * @param field
  +     * @param errors
  +     * @param request
  +     * @return true if text in all languages are less than maxlength, false 
if not
  +     */
       public static boolean validateMaxLengthMLText(
           Object bean,
           ValidatorAction va,
  @@ -95,9 +137,9 @@
               JahiaMltHelper mltHelper = (JahiaMltHelper)value;
   
               int maxLength = Integer.parseInt(field.getVarValue("maxlength"));
  -            String[] textes = mltHelper.getText();
  -            for (int i = 0; i < textes.length; i++) {
  -                if (textes[i] != null && textes[i].length() > maxLength) {
  +            String[] texts = mltHelper.getText();
  +            for (int i = 0; i < texts.length; i++) {
  +                if (texts[i] != null && texts[i].length() > maxLength) {
                       errors.add(
                           field.getKey(),
                           Resources.getActionMessage(request, va, field));
  @@ -109,9 +151,52 @@
       }
   
       /**
  -     * check if all mandatory languages are set within the passed 
EpfMltHelper Object
  +     * Checks if texts for all languages isn't less than a specified minimum 
length.
  +     * 
  +     * @param bean
  +     * @param va
  +     * @param field
  +     * @param errors
  +     * @param request
  +     * @return true if text in all languages are not less than minlength, 
false if they are
  +     */
  +    public static boolean validateMinLengthMLText(
  +        Object bean,
  +        ValidatorAction va,
  +        Field field,
  +        ActionMessages errors,
  +        HttpServletRequest request) {
  +        Object value = getPropertyValue(bean, field.getProperty());
  +
  +        if (!(value instanceof JahiaMltHelper)) {
  +            if (value != null) {
  +                logger.error(
  +                    "property value must be an JahiaMltHelper "
  +                        + field.getProperty());
  +            }
  +            return false;
  +        } else {
  +            JahiaMltHelper mltHelper = (JahiaMltHelper)value;
  +
  +            int minLength = Integer.parseInt(field.getVarValue("minlength"));
  +            String[] texts = mltHelper.getText();
  +            for (int i = 0; i < texts.length; i++) {
  +                if (texts[i] != null && texts[i].length() < minLength) {
  +                    errors.add(
  +                        field.getKey(),
  +                        Resources.getActionMessage(request, va, field));
  +                    return false;
  +                }
  +            }
  +            return true;
  +        }
  +    }    
  +    
  +    /**
  +     * Check if all mandatory languages are set within the passed 
JahiaMltHelper Object
  +     * 
        * @param mltHelper
  -     * @return
  +     * @return true if text in all languages is given, false if not
        */
       public static boolean isAllMandatoryLanguagesSet(JahiaMltHelper 
mltHelper) {
           String[] texts = mltHelper.getText();
  @@ -125,10 +210,6 @@
                   SiteLanguageSettings siteLanguageSettings =
                       (SiteLanguageSettings)languageIterator.next();
   
  -                             logger.debug(
  -                    "siteLanguageSettings.getCode(): "
  -                        + siteLanguageSettings.getCode() + " lang[i]: " + 
lang[i]);
  -
                   if (lang[i].equals("shared") || 
                        lang[i].equals(siteLanguageSettings.getCode())) {
                       found = true;
  @@ -147,7 +228,6 @@
        * If PropertyUtils.getProperty() throws an exception, the exception is 
logged and null is returned.
        * @param bean
        * @param property
  -     * @param appCtx
        * @return the bean property or null
        */
       private static Object getPropertyValue(Object bean, String property) {
  
  
  
  Index: JahiaMltHelper.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/validation/Attic/JahiaMltHelper.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- JahiaMltHelper.java       23 Feb 2005 10:02:41 -0000      1.1.2.1
  +++ JahiaMltHelper.java       2 Mar 2005 14:31:23 -0000       1.1.2.2
  @@ -1,21 +1,56 @@
   /*
  - * Created on Mar 22, 2004
  + *                                   ____.
  + *                       __/\ ______|    |__/\.     _______
  + *            __   .____|    |       \   |    +----+       \
  + *    _______|  /--|    |    |    -   \  _    |    :    -   \_________
  + *   \\______: :---|    :    :           |    :    |         \________>
  + *           |__\---\_____________:______:    :____|____:_____\
  + *                                      /_____|
    *
  - * To change the template for this generated file go to
  - * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  + *              . . . i n   j a h i a   w e   t r u s t . . .
  + *
  + *
  + *
  + * ----- BEGIN LICENSE BLOCK -----
  + * Version: JCSL 1.0
  + *
  + * The contents of this file are subject to the Jahia Community Source 
License
  + * 1.0 or later (the "License"); you may not use this file except in
  + * compliance with the License. You may obtain a copy of the License at
  + * http://www.jahia.org/license
  + *
  + * Software distributed under the License is distributed on an "AS IS" basis,
  + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  + * for the rights, obligations and limitations governing use of the contents
  + * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
  + * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. 
JAHIA
  + * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
  + *
  + * The Shared Modifications are Jahia View Helper.
  + *
  + * The Developer of the Shared Modifications is Jahia Solution S�rl.
  + * Portions created by the Initial Developer are Copyright (C) 2002 by the
  + * Initial Developer. All Rights Reserved.
  + *
  + * Contributor(s):
  + * 28-Feb-2005, Commaro, Benjamin Papez
  + *
  + * ----- END LICENSE BLOCK -----
    */
   package org.jahia.engines.validation;
   
   import java.util.*;
  -import java.util.Iterator;
  -import java.util.Vector;
   
   /**
  - * @author pap
  - *
  - * To change the template for this generated type comment go to
  - * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  - */
  +*
  +* <p>Title: JahiaMltHelper</p>
  +* <p>Description: This class converts all languages of a field to an array. 
This is then
  +*                 used in the user input validation methods.</p>
  +* <p>Copyright: Copyright (c) 2004</p>
  +* <p>Company: Jahia Ltd</p>
  +* @author not attributable
  +* @version 1.0
  +*/
   public class JahiaMltHelper {
       private String[] text = null;
       private String[] language = null;
  @@ -30,9 +65,10 @@
       }
   
       /**
  -     * get the text for a given language key, returns empty string if not 
found
  +     * Get the text for a given language key, returns empty string if not 
found
  +     * 
        * @param lang a language key
  -     * @return
  +     * @return text
        */
       public String getText(String lang) {
           for (int i = 0; i < language.length; i++) {
  @@ -44,14 +80,14 @@
       }
   
       /**
  -     * @return
  +     * @return language
        */
       public String[] getLanguage() {
           return language;
       }
   
       /**
  -     * @return
  +     * @return text
        */
       public String[] getText() {
           return text;
  @@ -97,7 +133,7 @@
       }
   
       /**
  -     * @return
  +     * @return languageSettings
        */
       public List getLanguageSettings() {
           return languageSettings;
  
  
  
  Index: ValidationError.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/validation/Attic/ValidationError.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- ValidationError.java      23 Feb 2005 10:02:41 -0000      1.1.2.1
  +++ ValidationError.java      2 Mar 2005 14:31:23 -0000       1.1.2.2
  @@ -33,7 +33,7 @@
    * Initial Developer. All Rights Reserved.
    *
    * Contributor(s):
  - * 13-Aug-2003, Jahia Solutions Sarl: Khue Nguyen
  + * 28-Feb-2005, Commaro, Benjamin Papez
    *
    * ----- END LICENSE BLOCK -----
    */
  @@ -43,8 +43,8 @@
   
   /**
    *
  - * <p>Title: </p>
  - * <p>Description: </p>
  + * <p>Title: ValidationError</p>
  + * <p>Description: The object of this class holds a validation error for a 
Jahia field.</p>
    * <p>Copyright: Copyright (c) 2004</p>
    * <p>Company: Jahia Ltd</p>
    * @author not attributable
  @@ -52,16 +52,12 @@
    */
   public class ValidationError {
   
  -  /** logging */
  -  private static final org.apache.log4j.Logger logger =
  -    org.apache.log4j.Logger.getLogger(ValidationError.class);
  -
     private Object source;
     private String msgError;
   
  -  public ValidationError(Object source, String msgError) {
  -    this.source = source;
  -    this.msgError = msgError;
  +  public ValidationError(Object newSource, String newMsgError) {
  +    this.source = newSource;
  +    this.msgError = newMsgError;
     }
   
     public Object getSource() {
  
  
  
  Index: ValidationErrorSorter.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/validation/Attic/ValidationErrorSorter.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- ValidationErrorSorter.java        23 Feb 2005 10:02:41 -0000      1.1.2.1
  +++ ValidationErrorSorter.java        2 Mar 2005 14:31:23 -0000       1.1.2.2
  @@ -33,7 +33,7 @@
    * Initial Developer. All Rights Reserved.
    *
    * Contributor(s):
  - * 13-Aug-2003, Commaro, Benjamin Papez
  + * 28-Feb-2005, Commaro, Benjamin Papez
    *
    * ----- END LICENSE BLOCK -----
    */
  @@ -47,12 +47,17 @@
   import org.jahia.exceptions.JahiaException;
   
   /**
  - * This class sorts the validation messages. The messages, which are on the 
currently
  - * processed page are the first items. Then the messages are sorted 
according to the
  - * appearance on the screen (first tab, first field to last tab, last field).
  - * 
  - * @author pap
  - */
  +*
  +* <p>Title: ValidationErrorSorter</p>
  +* <p>Description: This class sorts the validation messages. The messages, 
which are on the currently
  +*                 processed page are the first items. Then the messages are 
sorted according to the
  +*                 appearance on the screen (first tab, first field to last 
tab, last field).</p>
  +* <p>Copyright: Copyright (c) 2004</p>
  +* <p>Company: Jahia Ltd</p>
  +* @author not attributable
  +* @version 1.0
  +*/
  +
   public class ValidationErrorSorter implements Comparator {
     ContainerEditViewFieldGroup fieldGroup = null;
     public ValidationErrorSorter(ContainerEditViewFieldGroup 
currentFieldGroup) {
  

Reply via email to