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.inputdata; 017 018import org.apache.cocoon.ProcessingException; 019import org.xml.sax.ContentHandler; 020import org.xml.sax.SAXException; 021 022import org.ametys.web.cache.pageelement.PageElementCache; 023import org.ametys.web.repository.page.Page; 024import org.ametys.web.repository.site.Site; 025 026/** 027 * Abstraction for providing data at view-time by SAXing events. 028 */ 029public interface InputData 030{ 031 /** 032 * Returns true if this {@link InputData} is cacheable for the current site and if possible page. 033 * @param site the current {@link Site}. 034 * @param page the current {@link Page}. Can be null. 035 * @return true if this {@link InputData} is cacheable for the current site or page. 036 */ 037 public boolean isCacheable(Site site, Page page); 038 039 /** 040 * Returns true if the resulting SAX events should be actually stored in the central {@link PageElementCache}.<br> 041 * It may be useful to return false for some InputData managing their own cache and don't wanting to waste space in the central cache.<br> 042 * This method is only called if {@link #isCacheable(Site, Page)} returns true. 043 * @param site the current {@link Site}. 044 * @param page the current {@link Page}. Can be null. 045 * @return true if the content is cacheable and should be stored in the {@link PageElementCache}. 046 */ 047 public default boolean shouldBeCached(Site site, Page page) 048 { 049 return true; 050 } 051 052 /** 053 * Generates SAX events for providing data. 054 * @param handler the content handler to SAX into. 055 * @throws SAXException if an error occurs while SAXing. 056 * @throws ProcessingException if an error occurs during processing. 057 */ 058 public void toSAX(ContentHandler handler) throws SAXException, ProcessingException; 059}