001/* 002 * Copyright 2018 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.runtime.model; 017 018import java.util.Map; 019 020import org.apache.cocoon.ProcessingException; 021import org.xml.sax.ContentHandler; 022import org.xml.sax.SAXException; 023 024import org.ametys.runtime.util.ModifiableLabelable; 025 026/** 027 * Interface for view items 028 */ 029public interface ViewItem extends ModifiableLabelable 030{ 031 /** 032 * Converts the view item in a JSON map 033 * @param context the context of the definitions referenced in this view item and/or its children 034 * @return The view item as a JSON map 035 * @throws ProcessingException If an error occurs when converting the view item 036 */ 037 public Map<String, Object> toJSON(DefinitionContext context) throws ProcessingException; 038 039 /** 040 * Generates SAX events for the view item 041 * @param contentHandler the {@link ContentHandler} that will receive the SAX events 042 * @param context the context of the definitions included in the view item 043 * @throws SAXException if an error occurs during the SAX events generation 044 */ 045 public void toSAX(ContentHandler contentHandler, DefinitionContext context) throws SAXException; 046 047 /** 048 * Create an instance of {@link ViewItem} 049 * @return the created instance 050 */ 051 public ViewItem createInstance(); 052 053 /** 054 * Copy the current view item in the given one. 055 * If the view item is an accessor, its view items are copied only if they are not already present in the reference view 056 * @param item the copy 057 * @param referenceView the reference view 058 * @param itemPath the path of the view item in the reference view 059 */ 060 public default void copyTo(ViewItem item, View referenceView, String itemPath) 061 { 062 copyTo(item); 063 } 064 065 /** 066 * Copy the current view item in the given one. 067 * If the view item is an accessor, its view items are not copied 068 * @param item the copy 069 */ 070 public void copyTo(ViewItem item); 071 072 /** 073 * Indicates whether some other object is "equal to" this one. 074 * @param obj the reference object with which to compare. 075 * @param checkDetails <code>true</code> to check the view item's details during comparison (label, description, ...) 076 * @return <code>true</code> if this object is the same as the given obj, <code>false</code> otherwise. 077 */ 078 public boolean equals(Object obj, boolean checkDetails); 079}