001/* 002 * Copyright 2019 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.core.model.type; 017 018import org.apache.cocoon.xml.AttributesImpl; 019 020import org.ametys.runtime.model.ModelHelper; 021import org.ametys.runtime.model.type.DataContext; 022import org.ametys.runtime.model.type.ModelItemType; 023import org.ametys.runtime.plugin.component.AbstractLogEnabled; 024 025/** 026 * Abstract class for model group item types 027 */ 028public abstract class AbstractModelItemType extends AbstractLogEnabled implements ModelItemType 029{ 030 private String _id; 031 032 public void setPluginInfo(String pluginName, String featureName, String id) 033 { 034 _id = id; 035 } 036 037 public String getId() 038 { 039 return _id; 040 } 041 042 /** 043 * Retrieves the attributes of the context value to SAX 044 * @param context The context of the data to SAX 045 * @param saxModel <code>true</code> to sax the context model attributes 046 * @return the attributes 047 */ 048 protected AttributesImpl _getContextAttributes(DataContext context, boolean saxModel) 049 { 050 AttributesImpl attributes = new AttributesImpl(); 051 052 // Get the data path including the parent context 053 String dataPath = context.getDataPath(); 054 attributes.addCDATAAttribute("dataPath", dataPath); 055 String fullDataPath = context.getFullDataPath(); 056 attributes.addCDATAAttribute("fullDataPath", fullDataPath); 057 058 // Transform the data path to model path 059 if (saxModel) 060 { 061 attributes.addCDATAAttribute("modelPath", ModelHelper.getDefinitionPathFromDataPath(dataPath)); 062 attributes.addCDATAAttribute("fullModelPath", ModelHelper.getDefinitionPathFromDataPath(fullDataPath)); 063 } 064 065 return attributes; 066 } 067}