You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by ma...@apache.org on 2012/08/27 14:44:32 UTC
svn commit: r1377657 - in /rave/sandbox/content-services/rave-jcr-console:
./ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/rave/ src/main/java/org/apache/rave/jcr/
src/main/java/org/apache/rave/jcr/console/ src/m...
Author: marijan
Date: Mon Aug 27 12:44:31 2012
New Revision: 1377657
URL: http://svn.apache.org/viewvc?rev=1377657&view=rev
Log:
- add JSON export / import plugins to console
Added:
rave/sandbox/content-services/rave-jcr-console/src/main/java/
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/DownloadJsonLink.java (with props)
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.html (with props)
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.java (with props)
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.html (with props)
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.java (with props)
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.html (with props)
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.java (with props)
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.properties (with props)
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.html (with props)
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.java (with props)
rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.properties (with props)
Modified:
rave/sandbox/content-services/rave-jcr-console/pom.xml
rave/sandbox/content-services/rave-jcr-console/src/main/webapp/WEB-INF/jcr-console.xml
Modified: rave/sandbox/content-services/rave-jcr-console/pom.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/pom.xml?rev=1377657&r1=1377656&r2=1377657&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/pom.xml (original)
+++ rave/sandbox/content-services/rave-jcr-console/pom.xml Mon Aug 27 12:44:31 2012
@@ -34,6 +34,7 @@
<properties>
<hippo-jcr-console.version>1.01.00-SNAPSHOT</hippo-jcr-console.version>
<hippo-jcr-console.springframework.version>3.0.5.RELEASE</hippo-jcr-console.springframework.version>
+ <hippo-cms-plugins.version>2.23.01-SNAPSHOT</hippo-cms-plugins.version>
</properties>
<!-- temporarily add hippo snapshot repository until hippo-jcr-console is released -->
@@ -51,11 +52,16 @@
<dependencies>
<dependency>
+ <groupId>org.apache.rave.sandbox.jcr</groupId>
+ <artifactId>rave-jcr-config</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.onehippo.jcr.console</groupId>
<artifactId>hippo-jcr-console-dependencies</artifactId>
<version>${hippo-jcr-console.version}</version>
<type>pom</type>
- <scope>runtime</scope>
</dependency>
<dependency>
@@ -103,6 +109,22 @@
</configuration>
</plugin>
</plugins>
+ <resources>
+ <resource>
+ <filtering>false</filtering>
+ <directory>${basedir}/src/main/java</directory>
+ <includes>
+ <include>**/*.html</include>
+ <include>**/*.js</include>
+ <include>**/*.png</include>
+ <include>**/*.css</include>
+ <include>**/*.jpg</include>
+ </includes>
+ <excludes>
+ <exclude>**/*.java</exclude>
+ </excludes>
+ </resource>
+ </resources>
</build>
</project>
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/DownloadJsonLink.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/DownloadJsonLink.java?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/DownloadJsonLink.java (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/DownloadJsonLink.java Mon Aug 27 12:44:31 2012
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.jcr.console;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.rave.jcr.exporting.ContentExporter;
+import org.apache.wicket.Application;
+import org.apache.wicket.IRequestTarget;
+import org.apache.wicket.RequestCycle;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.protocol.http.WebResponse;
+import org.apache.wicket.util.time.Time;
+import org.onehippo.jcr.console.engine.model.IModelReference;
+import org.onehippo.jcr.console.engine.model.JcrNodeModel;
+import org.onehippo.jcr.console.repository.util.RepositoryUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+public class DownloadJsonLink extends Link<Node> {
+
+ private static Logger log = LoggerFactory.getLogger(DownloadJsonLink.class);
+ private static final long serialVersionUID = 1L;
+ private final IModelReference<Node> modelReference;
+
+ public DownloadJsonLink(String id, IModelReference<Node> modelReference) {
+ super(id, modelReference.getModel());
+ this.modelReference = modelReference;
+ }
+
+ @Override
+ public void onClick() {
+ JcrNodeModel model = (JcrNodeModel) getModel();
+ modelReference.setModel(model);
+ IRequestTarget rsrt = new JcrExportRequestTarget(model.getNode());
+ RequestCycle.get().setRequestTarget(rsrt);
+ }
+
+ private class JcrExportRequestTarget implements IRequestTarget {
+
+ private File tempFile;
+ private FileInputStream fis;
+ private Node node;
+ private String fileName = "export.json";
+
+ JcrExportRequestTarget(Node node) {
+ this.node = node;
+ try {
+ fileName = RepositoryUtils.getNodeNameCodec().decode(node.getName()) + ".json";
+ } catch (RepositoryException e) {
+ log.error("Unable to get node name for file name, using default", e);
+ }
+ }
+
+ /**
+ * @see org.apache.wicket.IRequestTarget#respond(org.apache.wicket.RequestCycle)
+ */
+ public void respond(RequestCycle requestCycle) {
+
+ final Application app = Application.get();
+
+ // Determine encoding
+ final String encoding = app.getRequestCycleSettings().getResponseRequestEncoding();
+
+ // Set content type based on markup type for page
+ final WebResponse response = (WebResponse) requestCycle.getResponse();
+ response.setCharacterEncoding(encoding);
+ response.setContentType("application/json; charset=" + encoding);
+
+ // Make sure it is not cached by a client
+ response.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
+ response.setHeader("Cache-Control", "no-cache, must-revalidate");
+ response.setHeader("Pragma", "no-cache");
+ response.setLastModifiedTime(Time.now());
+
+ // set filename
+ response.setAttachmentHeader(fileName);
+
+ try {
+ tempFile = File.createTempFile("export-" + Time.now().toString() + '-', ".json");
+ FileOutputStream fos = new FileOutputStream(tempFile);
+ try {
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
+ try {
+ ContentExporter exporter = new ContentExporter(node.getSession());
+ final Writer writer = new StringWriter(1024 * 1024);
+ exporter.exportContent(node.getPath(), writer);
+ bos.write(writer.toString().getBytes());
+
+ } finally {
+ bos.close();
+ }
+ } finally {
+ fos.close();
+ }
+ fis = new FileInputStream(tempFile);
+ response.write(fis);
+ } catch (FileNotFoundException e) {
+ log.error("Tempfile missing during export", e);
+ } catch (IOException e) {
+ log.error("IOException during export", e);
+ } catch (Exception e) {
+ log.error("Repository during export", e);
+ }
+ }
+
+ /**
+ * @see org.apache.wicket.IRequestTarget#detach(org.apache.wicket.RequestCycle)
+ */
+ public void detach(RequestCycle requestCycle) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ tempFile.delete();
+ }
+ }
+
+}
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/DownloadJsonLink.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/DownloadJsonLink.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.html
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.html?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.html (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.html Mon Aug 27 12:44:31 2012
@@ -0,0 +1,21 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+ -->
+<wicket:panel>
+ <span wicket:id="link"></span>
+</wicket:panel>
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.html
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.java?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.java (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.java Mon Aug 27 12:44:31 2012
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.jcr.console;
+
+import javax.jcr.Node;
+
+import org.apache.rave.jcr.console.dialog.JsonExportDialog;
+import org.apache.wicket.model.Model;
+import org.onehippo.jcr.console.engine.dialog.DialogLink;
+import org.onehippo.jcr.console.engine.dialog.IDialogFactory;
+import org.onehippo.jcr.console.engine.dialog.IDialogService;
+import org.onehippo.jcr.console.engine.model.JcrNodeModel;
+import org.onehippo.jcr.console.engine.plugin.IPluginContext;
+import org.onehippo.jcr.console.engine.plugin.config.IPluginConfig;
+import org.onehippo.jcr.console.engine.service.render.RenderPlugin;
+import org.onehippo.jcr.console.plugins.NodeModelReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * @version "$Id$"
+ */
+public class JsonExportPlugin extends RenderPlugin<Node> {
+
+ private static Logger log = LoggerFactory.getLogger(JsonExportPlugin.class);
+
+
+ private static final long serialVersionUID = 1L;
+
+ public JsonExportPlugin(IPluginContext context, IPluginConfig config) {
+ super(context, config);
+ IDialogFactory factory = new IDialogFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings("unchecked")
+ public IDialogService.Dialog createDialog() {
+ return new JsonExportDialog(new NodeModelReference(JsonExportPlugin.this, (JcrNodeModel) getDefaultModel()));
+ }
+ };
+ add(new DialogLink("link", new Model<String>("JSON Export"), factory, getDialogService()));
+ }
+
+}
+
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonExportPlugin.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.html
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.html?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.html (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.html Mon Aug 27 12:44:31 2012
@@ -0,0 +1,18 @@
+<!--
+ * Copyright 2011 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.
+-->
+<wicket:panel>
+ <span wicket:id="link"></span>
+</wicket:panel>
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.html
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.java?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.java (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.java Mon Aug 27 12:44:31 2012
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.jcr.console;
+
+import javax.jcr.Node;
+
+import org.apache.rave.jcr.console.dialog.JsonImportDialog;
+import org.apache.wicket.model.Model;
+import org.onehippo.jcr.console.engine.dialog.DialogLink;
+import org.onehippo.jcr.console.engine.dialog.IDialogFactory;
+import org.onehippo.jcr.console.engine.dialog.IDialogService;
+import org.onehippo.jcr.console.engine.model.JcrNodeModel;
+import org.onehippo.jcr.console.engine.plugin.IPluginContext;
+import org.onehippo.jcr.console.engine.plugin.config.IPluginConfig;
+import org.onehippo.jcr.console.engine.service.render.RenderPlugin;
+import org.onehippo.jcr.console.plugins.NodeModelReference;
+
+/**
+ * @version "$Id$"
+ */
+public class JsonImportPlugin extends RenderPlugin<Node> {
+
+ private static final long serialVersionUID = 1L;
+
+ public JsonImportPlugin(IPluginContext context, IPluginConfig config) {
+ super(context, config);
+ IDialogFactory factory = new IDialogFactory() {
+ private static final long serialVersionUID = 1L;
+
+ public IDialogService.Dialog createDialog() {
+ return new JsonImportDialog(new NodeModelReference(JsonImportPlugin.this, (JcrNodeModel) getDefaultModel()));
+ }
+ };
+ add(new DialogLink("link", new Model<String>("JSON Import"), factory, getDialogService()));
+ }
+
+
+}
+
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/JsonImportPlugin.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.html
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.html?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.html (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.html Mon Aug 27 12:44:31 2012
@@ -0,0 +1,38 @@
+<!--
+ * Copyright 2007 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:extend>
+ <div wicket:id="message" class="message"/>
+ <div style="padding-left:10px;padding-bottom:10px;">
+ <input type="checkbox" wicket:id="skip-binaries"> <span wicket:id="skip-binaries-text"/></input>
+ </div>
+ <ul>
+ <li>
+ <a wicket:id="download-link">
+ - <span wicket:id="download-link-text"/>
+ </a>
+ </li>
+ <li style="padding-top: 4px;">
+ <a wicket:id="view-link">
+ - <span wicket:id="view-link-text"/>
+ </a>
+ </li>
+ </ul>
+ <div class="xml-dump">
+ <textarea readonly="true" style="width: 820px; height: 280px;" wicket:id="dump"/>
+ </div>
+</wicket:extend>
+</html>
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.html
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.java?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.java (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.java Mon Aug 27 12:44:31 2012
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.jcr.console.dialog;
+
+import java.io.StringWriter;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.rave.jcr.console.DownloadJsonLink;
+import org.apache.rave.jcr.exporting.ContentExporter;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.model.StringResourceModel;
+import org.onehippo.jcr.console.engine.dialog.AbstractDialog;
+import org.onehippo.jcr.console.engine.model.IModelReference;
+import org.onehippo.jcr.console.engine.model.JcrNodeModel;
+import org.onehippo.jcr.console.plugins.menu.content.ContentExportDialog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+public class JsonExportDialog extends AbstractDialog<Node> {
+
+ private static final Logger log = LoggerFactory.getLogger(ContentExportDialog.class);
+ private static final long serialVersionUID = 1L;
+
+ private boolean skipBinary = false;
+
+ public JsonExportDialog(final IModelReference<Node> modelReference) {
+ final JcrNodeModel nodeModel = (JcrNodeModel) modelReference.getModel();
+ setModel(nodeModel);
+
+ try {
+ String path = nodeModel.getNode().getPath();
+ add(new Label("message", new StringResourceModel("dialog.message", this, null, new Object[]{path})));
+
+ } catch (RepositoryException e) {
+ log.error("Error getting node from model for contant import", e);
+ throw new RuntimeException("Error getting node from model for contant import: " + e.getMessage());
+ }
+
+ IModel<Boolean> skipBinaryModel = new PropertyModel<Boolean>(this, "skipBinary");
+ AjaxCheckBox skipBinaries = new AjaxCheckBox("skip-binaries", skipBinaryModel) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target) {
+ }
+ };
+ skipBinaries.add(new Label("skip-binaries-text", new Model<String>("Do not include binary properties in export")));
+ add(skipBinaries);
+
+ // use JSON link:
+ DownloadJsonLink link = new DownloadJsonLink("download-link", modelReference);
+ link.add(new Label("download-link-text", "Download (or right click and choose \"Save as...\")"));
+ add(link);
+ setFocus(link);
+
+ final Label dump = new Label("dump");
+ dump.setOutputMarkupId(true);
+ add(dump);
+
+ AjaxLink<String> viewLink = new AjaxLink<String>("view-link") {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ String export;
+ try {
+ Node node = nodeModel.getNode();
+ ContentExporter exporter = new ContentExporter(node.getSession());
+ final StringWriter writer = new StringWriter(1024 * 1024 * 2);
+ exporter.exportContent(node.getPath(), writer);
+ export = writer.toString();
+ IModel<Node> newNodeModel = new JcrNodeModel(node);
+ modelReference.setModel(newNodeModel);
+ } catch (Exception e) {
+ export = e.getMessage();
+ }
+ dump.setDefaultModel(new Model<String>(export));
+ target.addComponent(dump);
+ }
+ };
+ viewLink.add(new Label("view-link-text", "Show export in this window"));
+ add(viewLink);
+
+ setOkVisible(false);
+ }
+
+ public IModel<String> getTitle() {
+ JcrNodeModel nodeModel = (JcrNodeModel) getModel();
+ String path;
+ try {
+ path = nodeModel.getNode().getPath();
+ } catch (RepositoryException e) {
+ path = e.getMessage();
+ }
+ return new Model<String>("Export " + path);
+ }
+
+ public boolean isSkipBinary() {
+ return skipBinary;
+ }
+
+ public void setSkipBinary(boolean skipBinary) {
+ this.skipBinary = skipBinary;
+ }
+
+
+}
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.properties
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.properties?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.properties (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.properties Mon Aug 27 12:44:31 2012
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+dialog.message=Export content from: {0}
\ No newline at end of file
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonExportDialog.properties
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.html
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.html?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.html (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.html Mon Aug 27 12:44:31 2012
@@ -0,0 +1,38 @@
+<!--
+ * Copyright 2007 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:extend>
+ <div wicket:id="message" class="message"/>
+ <div class="import-properties">
+ <p>
+ <legend>
+ <strong>UUID resolution: </strong>
+ </legend>
+ <fieldset>
+ <select wicket:id="uuidBehaviors"/>
+ </fieldset>
+ </p>
+ <p>
+ <legend>
+ <strong>Select file: </strong>
+ </legend>
+ <fieldset>
+ <input wicket:id="fileInput" id="upload" type="file"/>
+ </fieldset>
+ </p>
+ </div>
+</wicket:extend>
+</html>
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.html
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.java?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.java (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.java Mon Aug 27 12:44:31 2012
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.jcr.console.dialog;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.InvalidSerializedDataException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.version.VersionException;
+
+import org.apache.rave.jcr.importing.ContentImporter;
+import org.apache.rave.jcr.importing.ImportBehavior;
+import org.apache.rave.jcr.importing.ImportException;
+import org.apache.wicket.Session;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.upload.FileUpload;
+import org.apache.wicket.markup.html.form.upload.FileUploadField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.model.StringResourceModel;
+import org.apache.wicket.util.value.IValueMap;
+import org.onehippo.jcr.console.engine.dialog.AbstractDialog;
+import org.onehippo.jcr.console.engine.model.IModelReference;
+import org.onehippo.jcr.console.engine.model.JcrNodeModel;
+import org.onehippo.jcr.console.engine.session.UserSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+public class JsonImportDialog extends AbstractDialog<Node> {
+
+ private static Logger log = LoggerFactory.getLogger(JsonImportDialog.class);
+ private static final long serialVersionUID = 1L;
+
+
+ private final IModelReference<Node> modelReference;
+
+ public class LookupHashMap<K, V> extends HashMap<K, V> {
+ private static final long serialVersionUID = 1L;
+
+ public K getFirstKey(Object value) {
+ if (value == null) {
+ return null;
+ }
+ for (Map.Entry<K, V> e : entrySet()) {
+ if (value.equals(e.getValue())) {
+ return e.getKey();
+ }
+ }
+ return null;
+ }
+ }
+
+ private final LookupHashMap<Integer, String> uuidOpts = new LookupHashMap<Integer, String>();
+
+
+ private final JcrNodeModel nodeModel;
+ private FileUploadField fileUploadField;
+
+ // hard coded defaults
+ private String uuidBehavior = "Create new uuids on import";
+ private String mergeBehavior = "Disable merging";
+ private String derefBehavior = "Throw error when not found";
+
+ private void InitMaps() {
+ uuidOpts.put(ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING, "Remove existing node with same uuid");
+ uuidOpts.put(ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING, "Replace existing node with same uuid");
+ uuidOpts.put(ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, "Throw error on uuid collision");
+ uuidOpts.put(ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, "Create new uuids on import");
+ }
+
+ public JsonImportDialog(IModelReference<Node> modelReference) {
+ this.modelReference = modelReference;
+ InitMaps();
+ this.nodeModel = (JcrNodeModel) modelReference.getModel();
+
+ DropDownChoice<String> uuid = new DropDownChoice<String>("uuidBehaviors", new PropertyModel<String>(this, "uuidBehavior"), new ArrayList<String>(uuidOpts.values()));
+
+ add(uuid.setNullValid(false).setRequired(true));
+
+ // file upload
+ setMultiPart(true);
+ setNonAjaxSubmit();
+ add(fileUploadField = new FileUploadField("fileInput"));
+
+ setOkLabel("import");
+ setFocus(uuid);
+
+ try {
+ String path = this.nodeModel.getNode().getPath();
+ add(new Label("message", new StringResourceModel("dialog.message", this, null, new Object[]{path})));
+
+ //info("Import content from a file to node: " + nodeModel.getNode().getPath());
+ } catch (RepositoryException e) {
+ log.error("Error getting node from model for contant import", e);
+ throw new RuntimeException("Error getting node from model for contant import: " + e.getMessage());
+ }
+ }
+
+ public IModel<String> getTitle() {
+ return new Model<String>("Import content from file");
+ }
+
+ @Override
+ protected void onOk() {
+ final FileUpload upload = fileUploadField.getFileUpload();
+
+ int uuidOpt = uuidOpts.getFirstKey(uuidBehavior);
+
+ if (upload != null) {
+ info("File uploaded. Start import..");
+
+ // do import
+ try {
+ InputStream contentStream = new BufferedInputStream(upload.getInputStream());
+ String absPath = nodeModel.getNode().getPath();
+ log.info("Starting import: importDereferencedXML(" + absPath + ',' + upload.getClientFileName() + ',' + uuidBehavior + ',' + mergeBehavior + ',' + derefBehavior);
+
+ final javax.jcr.Session session = ((UserSession) Session.get()).getJcrSession();
+ ContentImporter importer = new ContentImporter(session);
+ //((UserSession) Session.get()).getJcrSession().importXML(absPath, contentStream, uuidOpt);
+ importer.importContent(absPath, upload.getClientFileName(), contentStream, ImportBehavior.MERGE);
+ // TODO if we want the imported node to be selected in the browser tree, we need to get to the new imported (top) node
+ // modelReference.setModel(newNodeModel);
+ info("Import done.");
+
+ } catch (PathNotFoundException ex) {
+ log.error("Error initializing content in '" + nodeModel.getItemModel().getPath() + "' : " + ex.getMessage(), ex);
+ error("Import failed: " + ex.getMessage());
+ } catch (ItemExistsException ex) {
+ log.error("Error initializing content in '" + nodeModel.getItemModel().getPath() + "' : " + ex.getMessage(), ex);
+ error("Import failed: " + ex.getMessage());
+ } catch (ConstraintViolationException ex) {
+ log.error("Error initializing content in '" + nodeModel.getItemModel().getPath() + "' : " + ex.getMessage(), ex);
+ error("Import failed: " + ex.getMessage());
+ } catch (VersionException ex) {
+ log.error("Error initializing content in '" + nodeModel.getItemModel().getPath() + "' : " + ex.getMessage(), ex);
+ error("Import failed: " + ex.getMessage());
+ } catch (InvalidSerializedDataException ex) {
+ log.error("Error initializing content in '" + nodeModel.getItemModel().getPath() + "' : " + ex.getMessage(), ex);
+ error("Import failed: " + ex.getMessage());
+ } catch (LockException ex) {
+ log.error("Error initializing content in '" + nodeModel.getItemModel().getPath() + "' : " + ex.getMessage(), ex);
+ error("Import failed: " + ex.getMessage());
+ } catch (RepositoryException ex) {
+ log.error("Error initializing content in '" + nodeModel.getItemModel().getPath() + "' : " + ex.getMessage(), ex);
+ error("Import failed: " + ex.getMessage());
+ } catch (IOException ex) {
+ log.error("IOException initializing content in '" + nodeModel.getItemModel().getPath() + "' : " + ex.getMessage(), ex);
+ error("Import failed: " + ex.getMessage());
+ } catch (ImportException e) {
+ log.error("Error importing JSON content", e);
+ }
+ }
+ }
+
+ public void setMergeBehavior(String mergeBehavior) {
+ this.mergeBehavior = mergeBehavior;
+ }
+
+ public String getMergeBehavior() {
+ return mergeBehavior;
+ }
+
+ public void setDerefBehavior(String derefBehavior) {
+ this.derefBehavior = derefBehavior;
+ }
+
+ public String getDerefBehavior() {
+ return derefBehavior;
+ }
+
+ public void setUuidBehavior(String uuidBehavior) {
+ this.uuidBehavior = uuidBehavior;
+ }
+
+ public String getUuidBehavior() {
+ return uuidBehavior;
+ }
+
+ @Override
+ public IValueMap getProperties() {
+ return MEDIUM;
+ }
+
+}
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.properties
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.properties?rev=1377657&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.properties (added)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.properties Mon Aug 27 12:44:31 2012
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+dialog.message=Import content from a file into node: {0}
\ No newline at end of file
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-console/src/main/java/org/apache/rave/jcr/console/dialog/JsonImportDialog.properties
------------------------------------------------------------------------------
svn:keywords = Id
Modified: rave/sandbox/content-services/rave-jcr-console/src/main/webapp/WEB-INF/jcr-console.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-console/src/main/webapp/WEB-INF/jcr-console.xml?rev=1377657&r1=1377656&r2=1377657&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-console/src/main/webapp/WEB-INF/jcr-console.xml (original)
+++ rave/sandbox/content-services/rave-jcr-console/src/main/webapp/WEB-INF/jcr-console.xml Mon Aug 27 12:44:31 2012
@@ -332,6 +332,45 @@
</map>
</plugin>
<plugin>
+ <name>jsonexport</name>
+ <map>
+ <entry>
+ <key>wicket.model</key>
+ <value>service.model</value>
+ </entry>
+ <entry>
+ <key>plugin.class</key>
+ <value>org.apache.rave.jcr.console.JsonExportPlugin</value>
+ </entry>
+ <entry>
+ <key>wicket.id</key>
+ <value>service.menu.item</value>
+ </entry>
+ <entry>
+ <key>label</key>
+ <value>XML Export</value>
+ </entry>
+ </map>
+ </plugin>
+ <plugin>
+ <name>jsonimport</name>
+ <map>
+ <entry>
+ <key>wicket.model</key>
+ <value>service.model</value>
+ </entry>
+ <entry>
+ <key>plugin.class</key>
+ <value>org.apache.rave.jcr.console.JsonImportPlugin</value>
+ </entry>
+ <entry>
+ <key>wicket.id</key>
+ <value>service.menu.item</value>
+ </entry>
+ </map>
+ </plugin>
+
+ <plugin>
<name>checkinout</name>
<map>
<entry>