Commit 8ad9e298 authored by Ate Douma's avatar Ate Douma

HREPTWO-4739: alignment of naming conventions

- hst-addon-component-editor will be renamed to hippo-addon-hst-component-editor (still to be done)
parents
This diff is collapsed.
/.classpath
/.project
/.settings
frontend/.classpath
frontend/.project
frontend/.settings
frontend/target
repository/.classpath
repository/.project
repository/.settings
repository/target
/target
This is the HST configuration editor for Hippo CMS 7.3
<?xml version="1.0"?>
<!--
Copyright 2008-2010 Hippo.
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>
<artifactId>hst-addon-configuration-editor</artifactId>
<groupId>org.onehippo.cms7</groupId>
<version>1.04.03-SNAPSHOT</version>
</parent>
<artifactId>hst-addon-configuration-editor-frontend</artifactId>
<name>HST Addon Configuration Editor Frontend</name>
<dependencies>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-cms-engine</artifactId>
<version>${cms.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-cms-api</artifactId>
<version>${cms.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-connector</artifactId>
<version>${repository.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-cms-editor-frontend</artifactId>
<version>${cms.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-cms-gallery-frontend</artifactId>
<version>${cms.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-cms-browse</artifactId>
<version>${cms.version}</version>
<scope>provided</scope>
</dependency>
<!-- JCR API and Hippo ECM API dependency -->
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
<version>${javax.jcr.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-api</artifactId>
<version>${repository.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>package</defaultGoal>
<resources>
<resource>
<filtering>false</filtering>
<directory>${basedir}/src/main/java</directory>
<includes>
<include>**/*.html</include>
<include>**/*.css</include>
<include>**/*.properties</include>
<include>**/*.jpg</include>
<include>**/*.png</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>always</forkMode>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
<!--
* Copyright 2008 Hippo
*
* 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.
-->
<html xmlns:wicket="http://wicket.apache.org/">
<wicket:head>
<wicket:link>
<link rel="stylesheet" type="text/css" href="style.css"/>
</wicket:link>
</wicket:head>
<wicket:panel>
<div yui:id="hst-perspective-wrapper" class="hst-perspective">
<div yui:id="hst-perspective-top"/>
<div class="hippo-browser-small" yui:id="hst-perspective-left">
<div yui:id="hst-perspective-left-body">
<div wicket:id="extension.navigator">navigator here</div>
</div>
</div>
<div yui:id="hst-perspective-center">
<div yui:id="hst-perspective-center-body">
<div wicket:id="extension.editor">[ Editor ]</div>
</div>
</div>
</div>
</wicket:panel>
</html>
/*
* Copyright 2009 Hippo.
*
* 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.hippoecm.hst.plugins.frontend;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.query.QueryManager;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.Session;
import org.hippoecm.frontend.model.JcrNodeModel;
import org.hippoecm.frontend.plugin.IPluginContext;
import org.hippoecm.frontend.plugin.config.IClusterConfig;
import org.hippoecm.frontend.plugin.config.IPluginConfig;
import org.hippoecm.frontend.plugin.config.IPluginConfigService;
import org.hippoecm.frontend.plugin.config.impl.JavaPluginConfig;
import org.hippoecm.frontend.plugins.standards.perspective.Perspective;
import org.hippoecm.frontend.session.UserSession;
import org.hippoecm.hst.plugins.frontend.editor.context.HstContext;
import org.hippoecm.repository.api.HippoQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HstEditorPerspective extends Perspective {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
private final static String SVN_ID = "$Id$";
static final Logger log = LoggerFactory.getLogger(HstEditorPerspective.class);
private static final String EDITOR_ROOT = "editor.root";
private static final String NAMESPACES_ROOT = "namespaces.root";
private HstContext hstContext;
private String currentMountPointNodePath;
public HstEditorPerspective(final IPluginContext context, final IPluginConfig config) {
super(context, config);
List<String> previewMountPointNodePaths = getPreviewMountPointNodePaths();
if (!previewMountPointNodePaths.isEmpty()) {
currentMountPointNodePath = previewMountPointNodePaths.get(0);
}
String rootModelPath = config.getString(EDITOR_ROOT, null);
if (!StringUtils.isBlank(rootModelPath) && previewMountPointNodePaths.contains(rootModelPath)) {
currentMountPointNodePath = rootModelPath;
}
}
@Override
protected void onStart() {
super.onStart();
setUpHstContext();
IPluginContext context = getPluginContext();
IPluginConfig config = getPluginConfig();
IPluginConfigService pluginConfig = context.getService(IPluginConfigService.class.getName(),
IPluginConfigService.class);
IClusterConfig cluster = pluginConfig.getCluster(config.getString("cluster.name"));
IPluginConfig parameters = new JavaPluginConfig(config.getPluginConfig("cluster.options"));
parameters.put("path", hstContext.config.getPath());
parameters.put("content.path", hstContext.content.getPath());
parameters.put("sitemap.path", hstContext.sitemap.getPath());
context.newCluster(cluster, parameters).start();
}
public void setUpHstContext() {
final IPluginContext context = getPluginContext();
final IPluginConfig config = getPluginConfig();
if (currentMountPointNodePath == null) {
log.warn("HstEditorPerspective has failed to find a valid mount point node of primary type hst:site and therefore can not start.");
return;
}
JcrNodeModel root = new JcrNodeModel(currentMountPointNodePath);
hstContext = new HstContext(root, config.getString(NAMESPACES_ROOT));
context.registerService(hstContext, HstContext.class.getName());
new ViewController(context, config, root) {
private static final long serialVersionUID = 1L;
@Override
protected String getExtensionPoint() {
return config.getString("extension.editor");
}
};
}
public String getCurrentMountPointNodePath() {
return currentMountPointNodePath;
}
public List<String> getPreviewMountPointNodePaths() {
List<String> mountPointNodePaths = new ArrayList<String>();
Set<String> mountPointNodePathSet = new HashSet<String>();
String query = "//element(*, hst:mount)[@hst:type = 'preview']";
javax.jcr.Session session = ((UserSession) Session.get()).getJcrSession();
try {
QueryManager queryManager = ((UserSession) Session.get()).getQueryManager();
HippoQuery hippoQuery = (HippoQuery) queryManager.createQuery(query, "xpath");
session.refresh(true);
NodeIterator nodeIt = hippoQuery.execute().getNodes();
while (nodeIt.hasNext()) {
Node mount = nodeIt.nextNode();
if (mount.hasProperty("hst:mountpoint")) {
String path = mount.getProperty("hst:mountpoint").getString();
if (!StringUtils.isBlank(path)) {
mountPointNodePathSet.add(path);
}
}
}
} catch (RepositoryException e) {
log.error("Error executing query[" + query + "]", e);
}
query = "//element(*, hst:sites)";
try {
QueryManager queryManager = ((UserSession) Session.get()).getQueryManager();
HippoQuery hippoQuery = (HippoQuery) queryManager.createQuery(query, "xpath");
hippoQuery.setLimit(1);
session.refresh(true);
NodeIterator nodeIt = hippoQuery.execute().getNodes();
if (nodeIt.hasNext()) {
Node hstSitesNode = nodeIt.nextNode();
NodeIterator nodeIt2 = hstSitesNode.getNodes();
while (nodeIt2.hasNext()) {
Node hstSiteNode = nodeIt2.nextNode();
String hstSiteNodePath = hstSiteNode.getPath();
if (mountPointNodePathSet.contains(hstSiteNodePath)) {
mountPointNodePaths.add(hstSiteNodePath);
}
}
}
} catch (RepositoryException e) {
log.error("Error executing query[" + query + "]", e);
}
return mountPointNodePaths;
}
}
/*
* Copyright 2008 Hippo.
*
* 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.hippoecm.hst.plugins.frontend;
import java.util.Iterator;
import java.util.List;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.wicket.IClusterable;
import org.apache.wicket.model.IModel;
import org.hippoecm.frontend.model.IModelReference;
import org.hippoecm.frontend.model.JcrNodeModel;
import org.hippoecm.frontend.model.ModelReference;
import org.hippoecm.frontend.model.event.IEvent;
import org.hippoecm.frontend.model.event.IObserver;
import org.hippoecm.frontend.plugin.IClusterControl;
import org.hippoecm.frontend.plugin.IPluginContext;
import org.hippoecm.frontend.plugin.config.IClusterConfig;
import org.hippoecm.frontend.plugin.config.IPluginConfig;
import org.hippoecm.frontend.plugin.config.IPluginConfigService;
import org.hippoecm.frontend.plugin.config.impl.JavaPluginConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class ViewController implements IClusterable {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
private final static String SVN_ID = "$Id$";
static final Logger log = LoggerFactory.getLogger(ViewController.class);
public static final String VIEWERS = "browser.viewers";
public static final String MODEL_ROOT = "browser.root";
public static final String MODEL = "browser.model";
private String viewerName;
private IClusterControl viewer;
private JcrNodeModel rootModel;
private IPluginContext context;
private IPluginConfig config;
protected ViewController(IPluginContext context, IPluginConfig config, JcrNodeModel rootModel) {
this.config = config;
this.context = context;
if (config.containsKey(MODEL_ROOT)) {
this.rootModel = new JcrNodeModel(config.getString(MODEL_ROOT));
} else {
this.rootModel = rootModel;
}
@SuppressWarnings("unchecked")
IModelReference<Node> modelService = context.getService(config.getString(MODEL), IModelReference.class);
if (modelService != null) {
onModelChanged(modelService.getModel());
} else {
final ModelReference<Node> modelRef = new ModelReference<Node>(config.getString(MODEL), this.rootModel);
modelRef.init(context);
context.registerService(new IObserver<IModelReference<?>>() {
private static final long serialVersionUID = 1L;
public IModelReference<?> getObservable() {
return modelRef;
}
public void onEvent(Iterator<? extends IEvent<IModelReference<?>>> event) {
onModelChanged(modelRef.getModel());
}
}, IObserver.class.getName());
onModelChanged(modelRef.getModel());
}
}
protected void onModelChanged(IModel<Node> model) {
boolean handled = false;
try {
Node node = model.getObject();
Node root = rootModel.getNode();
IPluginConfigService pluginConfig = context.getService(IPluginConfigService.class.getName(),
IPluginConfigService.class);
while (node != null && !handled) {
handled = handleNode(node, pluginConfig.listClusters(config.getString(VIEWERS)));
if (!node.isSame(root)) {
node = node.getParent();
} else {
break;
}
}
} catch (RepositoryException ex) {
log.error(ex.getMessage());
}
if (!handled) {
resetViewer();
}
}
protected boolean handleNode(Node node, List<String> viewers) throws RepositoryException {
for (String type : viewers) {
if (node.isNodeType(type)) {
//FIXME: a page is of nodeType hst:component instead of hst:page... So to load the correct editor I have to insert an ugly hack.
//Tnx Ard ‹^› ‹(•¿•)› ‹^›
if (node.isNodeType("hst:component")) {
Node par = node.getParent();
while (true) {
if (par.isNodeType("hst:components")) {
break;
}
if (par.isNodeType("hst:pages")) {
type = "hst:page";
break;
}
par = par.getParent();
}
}
if (!type.equals(viewerName)) {
resetViewer();
IPluginConfigService pluginConfig = context.getService(IPluginConfigService.class.getName(),
IPluginConfigService.class);
IClusterConfig cluster = pluginConfig.getCluster(config.getString(VIEWERS) + "/" + type);
IPluginConfig parameters = new JavaPluginConfig(config.getPluginConfig("viewer.options"));
parameters.put("wicket.id", getExtensionPoint());
parameters.put(MODEL, config.getString(MODEL));
onViewInit(parameters);
viewer = context.newCluster(cluster, parameters);
viewer.start();
viewerName = type;
onViewStarted();
}
return true;
}
}
return false;
}
protected void onViewInit(IPluginConfig parameters) {
}
protected void onViewStarted() {
}
private void resetViewer() {
if (viewer != null) {
viewer.stop();
viewer = null;
viewerName = null;
}
}
protected abstract String getExtensionPoint();
}
\ No newline at end of file
/*
* Copyright 2010 Hippo.
*
* 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.hippoecm.hst.plugins.frontend.browse;
import java.io.Serializable;
import java.util.Map;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.IClusterable;
import org.apache.wicket.Session;
import org.apache.wicket.util.value.IValueMap;
import org.hippoecm.frontend.model.JcrNodeModel;
import org.hippoecm.frontend.model.ModelReference;
import org.hippoecm.frontend.model.event.IObservable;
import org.hippoecm.frontend.plugin.IPluginContext;
import org.hippoecm.frontend.plugin.config.IPluginConfig;
import org.hippoecm.frontend.session.UserSession;
import org.hippoecm.hst.plugins.frontend.util.DelegatingObjectProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This subclass of org.hippoecm.frontend.plugins.cms.browse.tree.FolderTreePlugin restores pre 2.12 functionality
* without which clicks on a section won't call onModelChanged().
*/
public class FolderTreePlugin extends org.hippoecm.frontend.plugins.cms.browse.tree.FolderTreePlugin {
private static final long serialVersionUID = 1L;
static final Logger log = LoggerFactory.getLogger(FolderTreePlugin.class);
@SuppressWarnings("unused")
private final static String SVN_ID = "$Id$";
public FolderTreePlugin(IPluginContext context, IPluginConfig config) {
super(context,
(IPluginConfig) DelegatingObjectProxy.createProxy(
new Class [] { IPluginConfig.class, IValueMap.class, Map.class, IObservable.class, IClusterable.class, Serializable.class },
new PathAdjustedPluginConfigDelegator(config, getInheritableConfigurationNodePath(config.getString("path", "/"))),
config));
JcrNodeModel model = new JcrNodeModel(getInheritableConfigurationNodePath(config.getString("path", "/")));
ModelReference<Node> modelService = new ModelReference<Node>(context.getReference(this).getServiceId(), model);
modelService.init(context);
}
private static String getInheritableConfigurationNodePath(String path) {
javax.jcr.Session session = ((UserSession) Session.get()).getJcrSession();
try {
Node node = session.getRootNode().getNode(normalizePath(path));
if (node.hasProperty("hst:inheritsfrom") && !node.hasNodes()) {
String inheritsFrom = node.getProperty("hst:inheritsfrom").getString();
if (!StringUtils.isBlank(inheritsFrom)) {
node = node.getNode(inheritsFrom);
return node.getPath();
}
}