Revision: 55673 Author: jhoffman Date: 2015-09-25 16:20:59 +0200 (Fri, 25 Sep 2015) Log Message: ----------- HIPPLUG-1166: removed AbstractTagsPlugin#getFieldDescriptor and thereby also AbstractTagsPlugin#getDocumentTypeDescriptor because the field concept does not apply to Tags/TagsSuggest plugins. Also introduced 'captionKey' (same as in taxonomy) with a fixed default per plugin.
Modified Paths: -------------- hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/AbstractTagsPlugin.java hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/TagSuggestPlugin.java hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/TagsPlugin.java Modified: hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/AbstractTagsPlugin.java =================================================================== --- hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/AbstractTagsPlugin.java 2015-09-25 10:47:19 UTC (rev 55672) +++ hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/AbstractTagsPlugin.java 2015-09-25 14:20:59 UTC (rev 55673) @@ -1,5 +1,5 @@ /* - * Copyright 2008-2015 Hippo B.V. (http://www.onehippo.com) + * Copyright 2015 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,88 +15,42 @@ */ package org.onehippo.forge.ecmtagging.editor; +import javax.jcr.Node; + import org.apache.wicket.model.IModel; -import org.apache.wicket.model.Model; import org.apache.wicket.model.StringResourceModel; -import org.hippoecm.frontend.editor.ITemplateEngine; -import org.hippoecm.frontend.editor.TemplateEngineException; import org.hippoecm.frontend.editor.plugins.field.AbstractFieldPlugin; import org.hippoecm.frontend.plugin.IPluginContext; import org.hippoecm.frontend.plugin.config.IPluginConfig; import org.hippoecm.frontend.service.render.RenderPlugin; -import org.hippoecm.frontend.types.IFieldDescriptor; -import org.hippoecm.frontend.types.ITypeDescriptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.jcr.Node; - /** + * Base class for tags plugin and tagsuggest plugin */ public abstract class AbstractTagsPlugin extends RenderPlugin<Node> { - private final Logger log = LoggerFactory.getLogger(getClass()); + private final Logger log = LoggerFactory.getLogger(AbstractTagsPlugin.class); - protected abstract String getDefaultFieldName(); - public AbstractTagsPlugin(IPluginContext context, IPluginConfig config) { super(context, config); } /** - * Get the document type descriptor object that this field is part of - */ - protected ITypeDescriptor getDocumentTypeDescriptor() { - - final ITemplateEngine templateEngine = getPluginContext().getService(getPluginConfig().getString(ITemplateEngine.ENGINE), ITemplateEngine.class); - if (templateEngine != null) { - try { - return templateEngine.getType(getModel()); - } catch (TemplateEngineException e) { - log.error("Cannot determine type for the field", e); - } - } else { - log.error("Cannot find template engine, plugin config is {}", getPluginConfig()); - } - return null; - } - - /** - * Get the field descriptor object for this field - */ - protected IFieldDescriptor getFieldDescriptor() { - - final ITypeDescriptor docType = getDocumentTypeDescriptor(); - if (docType != null) { - final String fieldName = getPluginConfig().getString(AbstractFieldPlugin.FIELD, getDefaultFieldName()); - - final IFieldDescriptor field = docType.getField(fieldName); - if (field != null) { - return field; - } - - log.warn("Cannot find field '{}' for type {}", fieldName, docType.getName()); - } - - return null; - } - - /** * Get the model for the caption, a.k.a. title. * * Inspired on org.hippoecm.frontend.editor.plugins.field.AbstractFieldPlugin#getCaptionModel(), - * unfortunately this class does not extend from AbstractFieldPlugin. + * unfortunately this class does not extend from AbstractFieldPlugin. Also, it's become quite different, since the + * concept of a field does not apply to tags/tagsuggest. */ - protected IModel<String> getCaptionModel(final IModel<String> defaultModel) { + protected IModel<String> getCaptionModel(final String defaultCaptionKey, final String defaultCaption) { - final IFieldDescriptor field = getFieldDescriptor(); - String caption = getPluginConfig().getString("caption"); - String captionKey = field != null ? field.getName() : caption; + final String captionKey = getPluginConfig().getString("captionKey", defaultCaptionKey); + final String caption = getPluginConfig().getString("caption", defaultCaption); - if(captionKey != null && caption != null) { // implicitly from translator service (this class implements IStringResourceProvider) log.debug("Getting field caption from translator by captionKey '{}' and default caption '{}'", captionKey, caption); return new StringResourceModel(captionKey, this, null, caption); - } else return defaultModel; } } Modified: hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/TagSuggestPlugin.java =================================================================== --- hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/TagSuggestPlugin.java 2015-09-25 10:47:19 UTC (rev 55672) +++ hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/TagSuggestPlugin.java 2015-09-25 14:20:59 UTC (rev 55673) @@ -19,7 +19,6 @@ import java.util.Iterator; import java.util.List; -import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; @@ -37,12 +36,10 @@ import org.apache.wicket.model.Model; import org.apache.wicket.request.resource.CssResourceReference; import org.hippoecm.frontend.model.JcrNodeModel; -import org.hippoecm.frontend.model.event.IObserver; import org.hippoecm.frontend.model.properties.JcrPropertyModel; import org.hippoecm.frontend.plugin.IPluginContext; import org.hippoecm.frontend.plugin.config.IPluginConfig; import org.hippoecm.frontend.plugins.standards.ClassResourceModel; -import org.hippoecm.frontend.service.render.RenderPlugin; import org.onehippo.forge.ecmtagging.Tag; import org.onehippo.forge.ecmtagging.TagCollection; import org.onehippo.forge.ecmtagging.TagSuggestor; @@ -53,9 +50,6 @@ /** * Frontend Plugin that displays the tag suggestions to the user. - * - * @author Jeroen Tietema - * */ public class TagSuggestPlugin extends AbstractTagsPlugin { @SuppressWarnings("unused") @@ -81,7 +75,9 @@ } if ("edit".equals(mode)) { fragment = new Fragment("tag-view", "suggestions", this); - fragment.add(new Label("title", getCaptionModel(new ClassResourceModel("keyword_suggestions",TagSuggestPlugin.class)))); + + final String defaultCaption = new ClassResourceModel("keyword_suggestions", TagSuggestPlugin.class).getObject(); + fragment.add(new Label("title", getCaptionModel("tagsuggest", defaultCaption))); try { fragment.add(new TagSuggestView("view", ((JcrNodeModel) getModel()).getNode().getSession(), tagIndexLocation)); } catch (RepositoryException e) { @@ -103,11 +99,6 @@ } @Override - protected String getDefaultFieldName() { - return "tagsuggest"; - } - - @Override public void renderHead(final IHeaderResponse response) { super.renderHead(response); response.render(CssHeaderItem.forReference(CSS)); Modified: hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/TagsPlugin.java =================================================================== --- hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/TagsPlugin.java 2015-09-25 10:47:19 UTC (rev 55672) +++ hippo-cms7/plugins/content-tagging/branches/hippo-plugin-content-tagging-5.0.x/src/main/java/org/onehippo/forge/ecmtagging/editor/TagsPlugin.java 2015-09-25 14:20:59 UTC (rev 55673) @@ -18,7 +18,6 @@ import org.apache.wicket.markup.head.CssHeaderItem; import org.apache.wicket.markup.head.IHeaderResponse; import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.model.IModel; import org.apache.wicket.request.resource.CssResourceReference; import org.hippoecm.frontend.model.IModelReference; import org.hippoecm.frontend.model.JcrNodeModel; @@ -39,9 +38,6 @@ /** * Frontend Plugin that displays the current assigned tags of the document. - * - * @author Jeroen Tietema - * */ public class TagsPlugin extends AbstractTagsPlugin { @SuppressWarnings("unused") @@ -64,7 +60,8 @@ public TagsPlugin(IPluginContext context, IPluginConfig config) { super(context, config); - add(new Label("title", getCaptionModel(new ClassResourceModel("keywords", TagsPlugin.class)))); + final String defaultCaption = new ClassResourceModel("keywords", TagsPlugin.class).getObject(); + add(new Label("title", getCaptionModel("tags", defaultCaption))); nodeModel = (JcrNodeModel) getModel(); toLowerCase = config.getAsBoolean(LOWERCASE, false); @@ -124,11 +121,6 @@ } @Override - protected String getDefaultFieldName() { - return "tags"; - } - - @Override public void renderHead(final IHeaderResponse response) { super.renderHead(response); _______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn