1 31 32 package org.opencms.workplace.editors; 33 34 import org.opencms.main.CmsLog; 35 import org.opencms.widgets.I_CmsWidget; 36 import org.opencms.widgets.Messages; 37 import org.opencms.xml.CmsXmlException; 38 import org.opencms.xml.content.I_CmsXmlContentValueVisitor; 39 import org.opencms.xml.types.I_CmsXmlContentValue; 40 41 import java.util.ArrayList ; 42 import java.util.HashMap ; 43 import java.util.List ; 44 import java.util.Locale ; 45 import java.util.Map ; 46 47 import org.apache.commons.logging.Log; 48 49 61 public class CmsXmlContentWidgetVisitor implements I_CmsXmlContentValueVisitor { 62 63 64 private static final Log LOG = CmsLog.getLog(CmsXmlContentWidgetVisitor.class); 65 66 67 private Locale m_locale; 68 69 70 private List m_uniqueWidgets; 71 72 73 private Map m_values; 74 75 76 private Map m_widgets; 77 78 81 public CmsXmlContentWidgetVisitor() { 82 83 initialize(null); 84 } 85 86 91 public CmsXmlContentWidgetVisitor(Locale locale) { 92 93 initialize(locale); 94 } 95 96 101 public Locale getLocale() { 102 103 return m_locale; 104 } 105 106 111 public List getUniqueWidgets() { 112 113 return m_uniqueWidgets; 114 } 115 116 123 public Map getValues() { 124 125 return m_values; 126 } 127 128 135 public Map getWidgets() { 136 137 return m_widgets; 138 } 139 140 143 public void visit(I_CmsXmlContentValue value) { 144 145 if (LOG.isDebugEnabled()) { 146 LOG.debug(org.opencms.workplace.editors.Messages.get().getBundle().key( 147 org.opencms.workplace.editors.Messages.LOG_VISITING_1, 148 value.getPath())); 149 } 150 151 if (value.isSimpleType()) { 152 boolean useLocale = m_locale != null; 154 if ((useLocale && value.getLocale() == getLocale()) || (!useLocale)) { 155 try { 156 I_CmsWidget widget = value.getContentDefinition().getContentHandler().getWidget(value); 158 if (!m_uniqueWidgets.contains(widget)) { 159 m_uniqueWidgets.add(widget); 160 } 161 m_widgets.put(value.getPath(), widget); 162 m_values.put(value.getPath(), value); 163 if (LOG.isDebugEnabled()) { 164 LOG.debug(Messages.get().getBundle().key( 165 Messages.LOG_DEBUG_WIDGETCOLLECTOR_ADD_1, 166 value.getPath())); 167 } 168 } catch (CmsXmlException e) { 169 if (LOG.isErrorEnabled()) { 171 LOG.error(Messages.get().getBundle().key(Messages.ERR_WIDGETCOLLECTOR_ADD_1, value), e); 172 } 173 } 174 } 175 } 176 } 177 178 183 private void initialize(Locale locale) { 184 185 m_widgets = new HashMap (25); 187 m_uniqueWidgets = new ArrayList (12); 188 m_values = new HashMap (25); 189 m_locale = locale; 191 } 192 } | Popular Tags |