Commit ea9c74e5 authored by Ate Douma's avatar Ate Douma

TRIVIAL cleanup master

parent 1375276f
*.iml
/.idea/
.project/
.settings
target/
demo/storage/
This diff is collapsed.
Hippo Plugin Selections
Copyright 2009-2018 Hippo B.V. (http://www.onehippo.com)
This product includes software developed by:
Hippo B.V., Amsterdam, The Netherlands (http://www.onehippo.com/);
The Apache Software Foundation (http://www.apache.org/).
NOTICE: Only our own original work is licensed under the terms of the
Apache License Version 2.0. The licenses of some libraries might impose
different redistribution or general licensing terms than those stated in the
Apache License. Users and redistributors are hereby requested to verify these
conditions and agree upon them.
# Selections Plugin
# This is not the branch you're looking for...
This is the Selections plugin for Hippo CMS. Documentation on how to use this
plugin in your Hippo project can be found at:
BloomReach only provides the git trees for the release tags of Hippo CMS, as explained on https://www.onehippo.org/about/open-source-release-policy.html
http://www.onehippo.org/library/concepts/plugins/selections/about.html
To checkout the code for a specific release tag, after cloning this repository, use the following:
## Plugin Demo
## to show the available tags
A demo project is provided to see the plugin in action.
git tag
### Requirements
## to checkout a specific tag
* Java 8 JDK
* Maven 3
git checkout <tag name>
### Download, Build and Run the Demo Project
## to modify a project
If you want to make modifications to a project, for example to create a patch, create a new fork branch from the specific tag like this:
1. Download the plugin's source code from https://code.onehippo.org/cms-community/hippo-plugin-selections
* Alternatively you can clone the git repository on your local machine.
* Use the latest stable branch named "release/x" (or "demo/x" in case the
demo is tagged seperately) where "x" is the version number.
* If you want to build the master branch demo you must configure the Hippo
Maven snapshot repository. See
http://www.onehippo.org/library/development/build-hippo-cms-from-scratch.html
for instructions.
2. Extract the archive on your local file system.
3. Use Maven to build and run the demo project:
```bash
cd hippo-plugin-selections/demo
mvn verify
mvn -P cargo.run
```
4. Hippo CMS will be available at http://localhost:8080/cms/ (login using
credentials `admin`/`admin`).
The demo website will be available at http://localhost:8080/site/.
### Development Branches
To build and run the demo from a development branch you may need to configure
access to the Hippo Maven snapshots repository. For more information see the
following documentation page:
http://www.onehippo.org/library/development/build-hippo-cms-from-scratch.html
git checkout -b forked-<tag name> <tag name>
For the latter, also see the **Build from Source** documentation at https://www.onehippo.org/library/development/build-hippo-cms-from-scratch.html
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2010-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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-plugin-selections</artifactId>
<version>5.3.0-SNAPSHOT</version>
</parent>
<name>Hippo Plugin Selections Addon CMS</name>
<description>Hippo Plugin Selections Addon CMS</description>
<artifactId>hippo-plugin-selections-addon-cms</artifactId>
<dependencies>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-cms-api</artifactId>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-cms-editor-frontend</artifactId>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-cms-perspectives</artifactId>
</dependency>
<dependency>
<artifactId>jcr</artifactId>
<groupId>javax.jcr</groupId>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-api</artifactId>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-builtin</artifactId>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-cms-translation-common</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>${basedir}/src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.html</include>
<include>**/*.css</include>
<include>**/*.png</include>
<include>**/*.gif</include>
</includes>
</resource>
</resources>
</build>
</project>
/*
* Copyright 2011-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.forge.selection.frontend;
/** Namespace constants */
public final class Namespace {
public class Property {
public static final String KEY = "selection:key";
public static final String LABEL = "selection:label";
}
public class Type {
public static final String VALUE_LIST = "selection:valuelist";
public static final String VALUE_LIST_ITEM = "selection:listitem";
}
private Namespace() {
}
}
\ No newline at end of file
/*
* Copyright 2010-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.forge.selection.frontend.model;
import java.io.Serializable;
/**
* List item object reflecting the list item in a value list document.
*
* @author Jeroen Hoffman
* @author Dennis Dam
*/
public class ListItem implements Serializable {
private static final long serialVersionUID = -7549187735023108422L;
private final String key;
private final String label;
private final String group;
/**
* Constructor for this class
* @param key the key of the list item
* @param label the label of the list item
*/
public ListItem(final String key, final String label) {
this.key = key;
this.label = label;
this.group=null;
}
/**
* Constructor for this class
* @param key the key of the list item
* @param label the label of the list item
* @param group the group to which this item belongs
*/
public ListItem(final String key, final String label, final String group) {
this.key = key;
this.label = label;
this.group=group;
}
public String getKey() {
return key;
}
public String getLabel() {
return label;
}
public String getGroup() {
return group;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return getKey();
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
return result;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj){ return true;}
if (obj == null){ return false;}
if (getClass() != obj.getClass()){ return false;}
ListItem other = (ListItem) obj;
if (key == null) {
if (other.key != null){ return false;}
} else if (!key.equals(other.key)){ return false;}
if (group == null){
if (other.group != null){ return false;}
} else if (!group.equals(other.group)){ return false; }
return true;
}
}
/*
* Copyright 2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.forge.selection.frontend.model;
import java.io.Serializable;
import java.util.Iterator;
import org.apache.wicket.model.LoadableDetachableModel;
import org.hippoecm.frontend.model.event.EventCollection;
import org.hippoecm.frontend.model.event.IEvent;
import org.hippoecm.frontend.model.event.IObservable;
import org.hippoecm.frontend.model.event.IObservationContext;
import org.hippoecm.frontend.model.event.Observer;
import org.hippoecm.frontend.model.properties.JcrPropertyValueModel;
/**
* Observable wrapper around a JcrPropertyValueModel
*/
public class ObservableValueModel<T extends Serializable> extends LoadableDetachableModel<T> implements IObservable {
private final JcrPropertyValueModel<T> valueModel;
private IObservationContext<? extends IObservable> context;
private Observer<IObservable> observer;
public ObservableValueModel(JcrPropertyValueModel<T> valueModel) {
this.valueModel = valueModel;
}
public JcrPropertyValueModel<T> getValueModel() {
return valueModel;
}
@Override
protected T load() {
return valueModel.getObject();
}
@Override
public void setObservationContext(final IObservationContext<? extends IObservable> context) {
this.context = context;
}
@Override
public void startObservation() {
observer = new Observer<IObservable>(valueModel.getJcrPropertymodel()) {
@Override
public void onEvent(final Iterator<? extends IEvent<IObservable>> events) {
context.notifyObservers(new EventCollection(events));
}
};
context.registerObserver(observer);
}
@Override
public void stopObservation() {
context.unregisterObserver(observer);
}
}
/*
* Copyright 2010-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.forge.selection.frontend.model;
import java.util.ArrayList;
import org.apache.wicket.util.io.IClusterable;
/**
* Value list object, i.e. an array list with ListItem objects, reflecting a
* value list document.
*
* @author Jeroen Hoffman
* @author Dennis Dam
*/
public class ValueList extends ArrayList<ListItem> implements IClusterable {
private static final long serialVersionUID = 1361292197145754639L;
/**
* Constructor.
*/
public ValueList() {
super();
}
/**
* The index of the specified object in this list.
*
* The object can be either a listitem or a string. If it
* is a string, then it represents the key of a list item.
*
* @param element a listitem or a string
* @return index of a list item in the list
*/
@Override
public int indexOf(Object element) {
if (element instanceof ListItem) {
return super.indexOf(element);
}
// string value is considered as the key
if (element instanceof String) {
for (int i = 0; i < size(); i++) {
if (get(i).getKey().equals(element)) {
return i;
}
}
}
return -1;
}
/**
* Returns the key of the list item associated with the provided object.
* The object can be either a listitem or a string. If it
* is a string, then it represents the key of a list item.
*
* @param object a listitem or a string
* @return the key associated with the listitem/string
*/
public String getKey(Object object) {
if (object instanceof ListItem) {
return ((ListItem) object).getKey();
}
// string value is considered as the key itself
if (object instanceof String) {
return (String) object;
}
return null;
}
/**
* Returns the label of the list item associated with the provided object.
* The object can be either a listitem or a string. If it
* is a string, then it represents the key of a list item.
*
* @param object a listitem or a string
* @return the label associated with the listitem/string
*/
public String getLabel(Object object) {
if (object instanceof ListItem) {
return ((ListItem) object).getLabel();
}
// string value is considered as the key
if (object instanceof String) {
for (int i = 0; i < size(); i++) {
if (get(i).getKey().equals(object)) {
return get(i).getLabel();
}
}
}
return null;
}
/**
* Looks up a listitem by matching the given key.
* @param key the key of a listitem
* @return the listitem of which the key is equal to the given key
*/
public ListItem getListItemByKey(String key){
for (int i = 0; i < size(); i++) {
ListItem valueListItem = get(i);
if (valueListItem.getKey().equals(key)) {
return valueListItem;
}
}
return null;
}
}
/*
* Copyright 2010-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.forge.selection.frontend.plugin;
import java.util.Locale;
import org.apache.commons.lang.StringUtils;
import org.hippoecm.frontend.editor.ITemplateEngine;
import org.hippoecm.frontend.model.properties.JcrPropertyValueModel;
import org.hippoecm.frontend.plugin.IPluginContext;
import org.hippoecm.frontend.plugin.config.IPluginConfig;
import org.hippoecm.frontend.service.render.RenderPlugin;
import org.onehippo.forge.selection.frontend.model.ValueList;
import org.onehippo.forge.selection.frontend.plugin.sorting.SortHelper;
import org.onehippo.forge.selection.frontend.provider.IValueListProvider;
import org.onehippo.forge.selection.frontend.utils.SelectionUtils;
/**
* Base class for CMS widgets that enable the user to select an item from a list.
* Contains logic for fetching the list and generic plugin functionalities.
* The list is backed by a ValueListProvider service that provides a ValueList
* object.
*
* The default DocumentValueListProvider reads a document of the type
* 'selection:valuelist', which contains key label pairs used to display values
* and labels in the dropdown.
*
* The plugin configuration must then be provided with a <code>source</code>
* property, which can either be a valid UUID of a handle or the path to the
* document based on the JCR root.
*/
public abstract class AbstractChoicePlugin extends RenderPlugin<String> {
private static final long serialVersionUID = 1L;
private static final ValueList EMPTY_VALUE_LIST = new ValueList();
private final SortHelper sortHelper = new SortHelper();
/**
* Constructor for this class.
*
* @param context plugin context
* @param config plugin config
*/
public AbstractChoicePlugin(IPluginContext context, IPluginConfig config) {
super(context, config);
}
/**
* Returns whether plugin is in edit mode
*
* @return true if plugin is in edit mode
*/
protected boolean isInEditMode() {
final String mode = getPluginConfig().getString(ITemplateEngine.MODE);
return "edit".equals(mode);
}
/**
* Returns the list of value items that is used to populate
* the choices for this selectable widget
*
* @return list of values
*/
protected ValueList getValueList() {
// configured provider
ValueList valueList = getValueListFromProvider();
if (valueList != null) {
return valueList;
}
return EMPTY_VALUE_LIST;
}
/**
* Returns the value list provided by the provider configured for this plugin.
*
* @return value list from configured value list provider
*/
private ValueList getValueListFromProvider() {
IValueListProvider selectedProvider = getValueListProvider();
if (selectedProvider == null) {
return null;
}
final Locale locale = SelectionUtils.getLocale(SelectionUtils.getNode(getModel()));
final ValueList valueList = selectedProvider.getValueList(getPluginConfig().getString(Config.SOURCE), locale);
sortHelper.sort(valueList, getPluginConfig());
return valueList;
}
/**
* Returns the value list provider configured for this plugin.
*/
private IValueListProvider getValueListProvider() {
String providerName = getPluginConfig().getString(Config.VALUELIST_PROVIDER, IValueListProvider.SERVICE_VALUELIST_DEFAULT);
if (StringUtils.isNotBlank(providerName)) {
return getPluginContext().getService(providerName, IValueListProvider.class);
}
return null;
}
/**
* Returns the property value model associated with this plugin.
*
* @return property value model
*/
protected JcrPropertyValueModel<String> getValueModel() {
return (JcrPropertyValueModel<String>) getModel();
}
}