xlawrence    2005/06/13 15:02:35 CEST

  Modified files:
    core/src/java/org/jahia/engines/shared BigText_Field.java 
  Log:
  Added common method for getting a page State
  
  Revision  Changes    Path
  1.7       +74 -124   
jahia/core/src/java/org/jahia/engines/shared/BigText_Field.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/engines/shared/BigText_Field.java.diff?r1=1.6&r2=1.7&f=h
  
  
  
  Index: BigText_Field.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/engines/shared/BigText_Field.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BigText_Field.java        6 Jun 2005 15:03:05 -0000       1.6
  +++ BigText_Field.java        13 Jun 2005 13:02:35 -0000      1.7
  @@ -19,10 +19,10 @@
   
   package org.jahia.engines.shared;
   
  +import java.util.Map;
   import java.util.HashMap;
   import java.util.Collection;
   import java.util.Vector;
  -import java.util.StringTokenizer;
   import org.jahia.data.containers.JahiaContainer;
   import org.jahia.data.fields.*;
   import org.jahia.engines.EngineMessages;
  @@ -36,12 +36,10 @@
   import org.jahia.services.sites.JahiaSite;
   import org.jahia.utils.JahiaString;
   import org.jahia.utils.JahiaTools;
  -import org.jahia.services.htmlparser.ActiveXServerURLCleanupDOMVisitor;
   import org.jahia.services.htmlparser.ExtractLinksDOMVisitor;
   import java.util.ArrayList;
   import java.util.Iterator;
   import org.jahia.urls.ContentServletURL;
  -import javax.servlet.http.HttpServletRequest;
   import java.net.MalformedURLException;
   import org.jahia.services.pages.ContentPage;
   import org.jahia.content.ContentFieldKey;
  @@ -54,22 +52,20 @@
   
   import org.jahia.services.acl.JahiaACLEntry;
   
  -import javax.servlet.ServletConfig;
  -
   import org.jahia.content.ContentObject;
   import org.jahia.content.ObjectKey;
   import org.jahia.content.JahiaObject;
  -import org.apache.commons.lang.StringUtils;
   
  -import org.jahia.services.usermanager.JahiaGroup;
  -import org.jahia.services.usermanager.JahiaUserManagerService;
  +import org.jahia.services.version.EntryLoadRequest;
  +
  +import org.jahia.services.workflow.WorkflowService;
   
   public class BigText_Field {
       
       private static org.apache.log4j.Logger logger =
               org.apache.log4j.Logger.getLogger(BigText_Field.class);
       
  -    private static          BigText_Field   theObject   = null;
  +    private static final    BigText_Field   theObject   = new 
BigText_Field();
       private static final    String          JSP_FILE    =
               "/jsp/jahia/engines/shared/bigtext_field.jsp";
       
  @@ -81,15 +77,10 @@
        * AK    19.12.2000
        *
        */
  -    public static synchronized BigText_Field getInstance() {
  -        if (theObject == null) {
  -            theObject = new BigText_Field();
  -        }
  +    public static BigText_Field getInstance() {
           return theObject;
       } // end getInstance
       
  -    
  -    
       /**
        * handles the field actions
        *
  @@ -101,12 +92,19 @@
        */
       public boolean handleField( ParamBean jParams, Integer modeInt, HashMap 
engineMap )
       throws JahiaException {
  -        int mode = modeInt.intValue();
  +        final int mode = modeInt.intValue();
           String fieldsEditCallingEngineName = (String) engineMap.get(
                   "fieldsEditCallingEngineName" );
           JahiaField  theField = (JahiaField) engineMap.get(
  -                fieldsEditCallingEngineName + ".theField" );
  -        initHtmlEditorsHelpers(engineMap,jParams);
  +                new StringBuffer().append(fieldsEditCallingEngineName).
  +                append(".theField").toString() );
  +        initHtmlEditorsHelpers(engineMap, jParams);
  +        
  +        String value = theField.getValue();
  +        if (value.indexOf(JahiaBigTextField.URL_MARKER) > 0) {
  +            value = JahiaBigTextField.rewriteURLs(value, jParams);
  +            theField.setValue(value);
  +        }
           
           logger.debug("handling mode : " + mode + " for field " +
                   theField.getID() + " value=" + theField.getValue());
  @@ -144,12 +142,12 @@
                                                 : theField.getConnectType();
            */
           
  -        String fieldValue = (String)jParams.getRequest().getParameter( "_" +
  -                new Integer(theField.getID()).toString() );
  +        String fieldValue = (String)jParams.getRequest().getParameter(
  +                new 
StringBuffer().append("_").append(theField.getID()).toString());
           
           if (fieldValue != null) {
               
  -            fieldValue = JahiaTools.replacePattern(fieldValue,"|","|");
  +            fieldValue = JahiaTools.replacePattern(fieldValue, "|", 
"|");
               if ("ISO-8859-1".equalsIgnoreCase(jParams.settings().
                       getDefaultResponseBodyEncoding())) {
                   // This code is used to transform submissions that might 
contain
  @@ -167,12 +165,11 @@
               JahiaSite site = 
ServicesRegistry.getInstance().getJahiaSitesService()
               .getSite(theField.getJahiaID());
               
  -            if ( site.getHtmlCleanup()==1 ){
  +            if ( site.getHtmlCleanup() == 1 ){
                   Vector DOMVisitors = ServicesRegistry.getInstance()
                   .getHtmlParserService()
                   .getHtmlDOMVisitors(theField.getJahiaID());
                   
  -                
                   ExtractLinksDOMVisitor linkExtractionVisitor = null;
                   if (site.getHtmlMarkupFiltering() == 1) {
                       linkExtractionVisitor = new ExtractLinksDOMVisitor();
  @@ -180,17 +177,18 @@
                       DOMVisitors.add(linkExtractionVisitor);
                   }
                   
  -                String serverURL = 
jParams.getRequest().getParameter("serverURL");
  -                
  -                if ( serverURL != null ){
  -                    ActiveXServerURLCleanupDOMVisitor rsnfURLVisitor =
  -                            new ActiveXServerURLCleanupDOMVisitor(serverURL);
  -                    DOMVisitors.add(rsnfURLVisitor);
  -                }
  +                /* Not needed anymore since the ActivX editor is no longer 
supported  */
  +                //                final String serverURL = 
jParams.getRequest().getParameter("serverURL");
  +                //
  +                //                if ( serverURL != null ) {
  +                //                    ActiveXServerURLCleanupDOMVisitor 
rsnfURLVisitor =
  +                //                            new 
ActiveXServerURLCleanupDOMVisitor(serverURL);
  +                //                    DOMVisitors.add(rsnfURLVisitor);
  +                //                }
                   
                   fieldValue = 
JahiaTextContentTidy.tidyPreProcessing(fieldValue);
                   fieldValue = 
ServicesRegistry.getInstance().getHtmlParserService()
  -                .parse(fieldValue,DOMVisitors,theField.getSiteID());
  +                .parse(fieldValue, DOMVisitors, theField.getSiteID());
                   fieldValue = 
JahiaTextContentTidy.tidyPostProcessing(fieldValue);
                   
                   if (linkExtractionVisitor != null) {
  @@ -200,8 +198,9 @@
               
               EngineMessages resultMessages = ServicesRegistry.getInstance().
                       
getHtmlParserService().checkTextParsingErrors(fieldValue);
  -            if ( !resultMessages.isEmpty() ){
  -                resultMessages.saveMessages(String.valueOf(theField.getID()) 
+ ".",
  +            if ( !resultMessages.isEmpty() ) {
  +                resultMessages.saveMessages(
  +                        new 
StringBuffer().append(theField.getID()).append(".").toString(),
                           jParams.getRequest());
                   fieldValue = oriFieldValue;
                   out = false;
  @@ -211,7 +210,8 @@
               fieldValue = theField.getValue();
           }
           fieldValue = JahiaString.getProperStr(fieldValue, 
jParams.getLocale());
  -        theField.setValue( fieldValue );
  +        
  +        theField.setValue(fieldValue);
           theField.setObject(null);
           
           return out;
  @@ -292,7 +292,7 @@
                                   }
                               } catch (JahiaException ex) {
                                   logger.debug("Page " + pageID +
  -                                        "not found, ignoring in references");
  +                                        " not found, ignoring in 
references");
                               }
                           }
                       } catch (JahiaException je) {
  @@ -355,7 +355,6 @@
                           new HashMap(), new HashMap());
               }
           }
  -        
           return theField.save(jParams);
           
       } // end saveData
  @@ -373,12 +372,14 @@
       throws JahiaException {
           
           String fieldsEditCallingEngineName = (String) engineMap.get( 
"fieldsEditCallingEngineName" );
  -        FieldsEditHelper feh = 
(FieldsEditHelper)engineMap.get(fieldsEditCallingEngineName + "."
  -                + FieldsEditHelperAbstract.FIELDS_EDIT_HELPER_CONTEXTID);
  +        FieldsEditHelper feh = (FieldsEditHelper)engineMap.get(
  +                new 
StringBuffer().append(fieldsEditCallingEngineName).append(".").
  +                
append(FieldsEditHelperAbstract.FIELDS_EDIT_HELPER_CONTEXTID));
           
           boolean editable = false;
           JahiaContainer theContainer = (JahiaContainer)engineMap.get(
  -                fieldsEditCallingEngineName + ".theContainer");
  +                new StringBuffer().append(fieldsEditCallingEngineName).
  +                append(".theContainer"));
           if ( theContainer == null ){
               // in case of a field , not a field in a container
               editable = true;
  @@ -437,7 +438,8 @@
               output = ServicesRegistry.getInstance().getJahiaFetcherService().
                       fetchServlet( jParams, JahiaEngine.NOT_EDITABLE_FIELD );
           }
  -        engineMap.put( fieldsEditCallingEngineName + ".fieldForm", output );
  +        engineMap.put( new 
StringBuffer().append(fieldsEditCallingEngineName).
  +                append(".fieldForm").toString(), output );
           
           return true;
       } // end composeEngineMap
  @@ -516,7 +518,7 @@
               JahiaField field, ParamBean jParams, HashMap engineMap) throws 
JahiaException {
           logger.debug("Comparing ACLs of field "+field.getID()+ " and page "+
                   pageID);
  -        final ContentPage page = ContentPage.getPage(pageID);   
  +        final ContentPage page = ContentPage.getPage(pageID);
           final ContentObject aclObject = getFieldACLObject(field, jParams, 
engineMap);
           
           // Define an ACLEntry for "Read" Rights
  @@ -532,7 +534,7 @@
           // Get all the groups which can see the target page
           final Vector pageACLGroups = 
page.getACL().getGroupnameListNoAdmin(aclEntry);
           logger.debug("pageACLGroups: "+pageACLGroups);
  -              
  +        
           Vector result = new Vector(fieldACLGroups.size());
           
           Iterator ite = fieldACLGroups.iterator();
  @@ -592,17 +594,17 @@
                   final int ctnListID = container.getListID();
                   logger.debug("Trying to use parent ContainerList ACL 
instead: ID = " +
                           ctnListID);
  -
  +                
                   if (ctnListID <= 0) { // this means the containerList is 
empty
  -                    // fetch the page ACL entry instead          
  +                    // fetch the page ACL entry instead
                       ContentPage fieldPage = 
ContentPage.getPage(field.getPageID());
                       logger.debug("Trying to use parent ContentPage ACL 
instead: ID = " +
                               field.getPageID());
                       
                       if (fieldPage == null) {
                           logger.error("Field ContentPage is null !!!");
  -                        throw new JahiaException("Field ContentPage is null 
!!!", 
  -                                "Field ContentPage is null !!!", 
  +                        throw new JahiaException("Field ContentPage is null 
!!!",
  +                                "Field ContentPage is null !!!",
                                   JahiaException.APPLICATION_ERROR,
                                   JahiaException.ERROR_SEVERITY);
                       }
  @@ -625,91 +627,39 @@
       }
       
       /**
  -     * @return The Content of the BigText Field with cleaned URLs
  +     * Returns a String representing the state of a page. The String 
returned is
  +     * the name of a CSS class which will be used by the editor to format 
the page
  +     * title according to the CSS class. Thus, you should not modify the 
return
  +     * values of this method, without changing the CSS class names of the 
JahiaLinker
  +     * plugin (jahia-linker.css).
  +     *
  +     * @param pageId The pageId to get the state of
  +     *
  +     * @return A String representing the state of the page and a CSS class 
name
  +     * @throws JahiaException If Something goes wrong
        */
  -    public String cleanUpHardCodedLinks( JahiaField field, 
HttpServletRequest req ) {
  -        String content = field.getValue();
  -        if (content.toLowerCase().indexOf("href") < 0) {
  -            // BigText does not contain any link
  -            return content;
  -        }
  +    public String getPageState(int pageId, String currentLanguageCode)
  +    throws JahiaException {
  +        ContentPage page = ContentPage.getPage(pageId);
  +        if (page == null) { return "staging"; }
           
  -        if (content.indexOf("jahia") < 0) {
  -            // No jahia hardcoded links
  -            return content;
  -        }
  +        Map languagesStates = 
WorkflowService.getInstance().getLanguagesStates(page);
  +        final Integer state = 
((Integer)languagesStates.get(currentLanguageCode));
           
  -        StringBuffer result = new StringBuffer();
  -        final String delimiter = " ";
  -        StringTokenizer tokenizer = new StringTokenizer(content, delimiter);
  +        if (state == null) { return "staging"; }
           
  -        while (tokenizer.hasMoreTokens()) {
  -            String token = tokenizer.nextToken();
  -            
  -            if (token.toLowerCase().startsWith("href") && 
token.indexOf("pid") > -1) {
  -                logger.debug("Found a Jahia HardCoded link: "+token);
  -                
  -                // To know if we have to close the '<a' tag...
  -                final boolean close = (token.indexOf('>') > -1) ? true : 
false;
  -                
  -                String link;
  -                if (close) {
  -                    link = token.substring(6, token.indexOf('>')-1);
  -                } else {
  -                    link = token.substring(6, token.length()-1);
  -                }
  -                
  -                logger.debug("Link is: "+link);
  -                
  -                boolean removeHost = false;
  -                if (link.indexOf(req.getServerName()) > -1 ||
  -                        link.indexOf("localhost") > -1) {
  -                    
  -                    // Get rid of the hostName and protocole
  -                    // We drop everything before the third '/'
  -                    link = link.substring(8);
  -                    link = link.substring(link.indexOf('/'));
  -                    
  -                    logger.debug("Link is (no host): "+link);
  -                    removeHost = true;
  -                }
  -                
  -                // Get rid of the '/op/.../'
  -                if (link.indexOf("/op/") > -1) {
  -                    if (link.indexOf("/op/edit") > -1) {
  -                        link = StringUtils.replace(link, "/op/edit", "");
  -                        
  -                    } else if (link.indexOf("/op/compare") > -1) {
  -                        link = StringUtils.replace(link, "/op/compare", "");
  -                        
  -                    } else {
  -                        link = StringUtils.replace(link, "/op/preview", "");
  -                        
  -                    }
  -                }
  -                
  -                // Get rid of all what is after the /pid/
  -                // (matrix, jSessionId, etc.)
  -                if (link.indexOf('?') > -1) {
  -                    link = link.substring(0, link.indexOf('?'));
  -                }
  -                
  -                // Get rid of the context, ie only keep the pid value
  -                if (removeHost) link = link.substring(link.indexOf("pid/") + 
4);
  +        if (page.isMarkedForDelete()) { return "markForDeleted"; }
  +        
  +        switch (state.intValue()) {
  +            case EntryLoadRequest.ACTIVE_WORKFLOW_STATE:
  +                return "active";
                   
  -                result.append("href=\"");
  -                result.append(link);
  -                result.append("\"");
  -                if (close) result.append(">");
  +            case EntryLoadRequest.WAITING_WORKFLOW_STATE:
  +                return "waiting";
                   
  -            } else {
  -                result.append(token);
  -            }
  -            
  -            result.append(delimiter);
  +            default:
  +                return "staging";
           }
  -        
  -        return result.toString();
       }
       
   } // end BigText_Field
  

Reply via email to