001/*
002 *  Copyright 2010 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.web.content.consistency;
017
018import org.apache.cocoon.environment.ObjectModelHelper;
019import org.apache.cocoon.environment.Request;
020import org.apache.cocoon.xml.AttributesImpl;
021
022import org.ametys.cms.repository.Content;
023import org.ametys.cms.repository.ContentQueryHelper;
024import org.ametys.plugins.repository.AmetysObjectIterable;
025import org.ametys.plugins.repository.query.expression.AndExpression;
026import org.ametys.plugins.repository.query.expression.Expression;
027import org.ametys.plugins.repository.query.expression.Expression.Operator;
028import org.ametys.plugins.repository.query.expression.StringExpression;
029import org.ametys.web.repository.content.WebContent;
030
031/**
032 * Generate content with consistency information.<br>
033 * Parameters:
034 * <ul>
035 *  <li>short-test: set to true to make a short test, false to make a full one (default false).</li>
036 *  <li>omit-consistent: set to true to omit consistent contents and generate only contents with unknown or failed consistency information (default false).</li>
037 * </ul>
038 */
039public class GlobalContentConsistencyGenerator extends org.ametys.cms.content.consistency.GlobalContentConsistencyGenerator
040{
041    @Override
042    protected AmetysObjectIterable<Content> _getContents()
043    {
044        Request request = ObjectModelHelper.getRequest(objectModel);
045        String siteName = parameters.getParameter("siteName", request.getParameter("siteName"));
046        
047        Expression consistencyExpr = new ConsistencyExpression();
048        Expression siteExpr = new StringExpression("site", Operator.EQ, siteName);
049        Expression expression = new AndExpression(consistencyExpr, siteExpr);
050        
051        String query = ContentQueryHelper.getContentXPathQuery(expression);
052        
053        return _resolver.query(query);
054    }
055    
056    @Override
057    protected void _saxAdditionalContentAttributes(Content content, AttributesImpl atts)
058    {
059        if (content instanceof WebContent)
060        {
061            WebContent webContent = (WebContent) content;
062            atts.addCDATAAttribute("siteName", webContent.getSiteName());
063//            webContent.getReferencingPages();
064        }
065    }
066}