You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/04/18 12:54:41 UTC
svn commit: r161753 - in lenya/trunk/src:
java/org/apache/lenya/cms/editors/InsertAsset.java
webapp/WEB-INF/cocoon-xconf.xsl webapp/lenya/usecases/edit/insertAsset.jx
Author: andreas
Date: Mon Apr 18 03:54:37 2005
New Revision: 161753
URL: http://svn.apache.org/viewcvs?view=rev&rev=161753
Log:
added InsertAsset usecase
Added:
lenya/trunk/src/java/org/apache/lenya/cms/editors/InsertAsset.java
lenya/trunk/src/webapp/lenya/usecases/edit/insertAsset.jx
Modified:
lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
Added: lenya/trunk/src/java/org/apache/lenya/cms/editors/InsertAsset.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/editors/InsertAsset.java?view=auto&rev=161753
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/editors/InsertAsset.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/editors/InsertAsset.java Mon Apr 18 03:54:37 2005
@@ -0,0 +1,120 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * 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.apache.lenya.cms.editors;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.lenya.cms.publication.Resource;
+import org.apache.lenya.cms.publication.ResourcesManager;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+import org.apache.lenya.cms.usecase.UsecaseInvoker;
+
+/**
+ * Usecase to insert an image into a document.
+ *
+ * @version $Id:$
+ */
+public class InsertAsset extends DocumentUsecase {
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
+ */
+ protected void initParameters() {
+ super.initParameters();
+ loadResources();
+ }
+
+ protected void loadResources() {
+ ResourcesManager resourcesManager = null;
+
+ try {
+ resourcesManager = (ResourcesManager) this.manager.lookup(ResourcesManager.ROLE);
+ Resource[] resources = resourcesManager.getResources(getSourceDocument());
+
+ List selectedResources = new ArrayList();
+ String mimeTypePrefix = getParameterAsString("mimeTypePrefix", "");
+ for (int i = 0; i < resources.length; i++) {
+ if (resources[i].getMimeType().startsWith(mimeTypePrefix)) {
+ selectedResources.add(resources[i]);
+ }
+ }
+
+ setParameter("assets", selectedResources);
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resourcesManager != null) {
+ this.manager.release(resourcesManager);
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#advance()
+ */
+ public void advance() throws UsecaseException {
+ super.advance();
+ if (getParameter("file") != null) {
+ UsecaseInvoker invoker = null;
+ try {
+ invoker = (UsecaseInvoker) this.manager.lookup(UsecaseInvoker.ROLE);
+ String usecaseName = getParameterAsString("asset-usecase");
+ invoker.invoke(getSourceURL(), usecaseName, getParameters());
+ loadResources();
+ }
+ catch (Exception e) {
+ throw new UsecaseException(e);
+ } finally {
+ if (invoker != null) {
+ this.manager.release(invoker);
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds an asset.
+ */
+ protected void addAsset() {
+ String title = getParameterAsString("title");
+ String creator = getParameterAsString("creator");
+ String rights = getParameterAsString("rights");
+ Part file = getPart("file");
+
+ Map metadata = new HashMap();
+ metadata.put("title", title);
+ metadata.put("creator", creator);
+ metadata.put("rights", rights);
+ ResourcesManager resourcesManager = null;
+ try {
+ resourcesManager = (ResourcesManager) this.manager.lookup(ResourcesManager.ROLE);
+ resourcesManager.addResource(getSourceDocument(), file, metadata);
+ } catch (final Exception e) {
+ getLogger().error("The resource could not be added: ", e);
+ addErrorMessage("The resource could not be added (see log files for details).");
+ } finally {
+ if (resourcesManager != null) {
+ this.manager.release(resourcesManager);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl?view=diff&r1=161752&r2=161753
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl (original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl Mon Apr 18 03:54:37 2005
@@ -417,6 +417,17 @@
class="org.apache.lenya.cms.editors.EditDocument">
<parameter name="sourceUri" value="cocoon:/request2document"/>
</component-instance>
+ <component-instance name="edit.insertImage" logger="lenya.publication"
+ class="org.apache.lenya.cms.editors.InsertAsset">
+ <view template="edit/insertAsset" menu="false"/>
+ <parameter name="mimeTypePrefix" value="image/"/>
+ <parameter name="asset-usecase" value="tab.assets"/>
+ </component-instance>
+ <component-instance name="edit.insertAsset" logger="lenya.publication"
+ class="org.apache.lenya.cms.editors.InsertAsset">
+ <view template="edit/insertAsset" menu="false"/>
+ <parameter name="asset-usecase" value="tab.assets"/>
+ </component-instance>
<component-instance name="edit.forms" logger="lenya.publication"
class="org.apache.lenya.cms.editors.forms.FormsEditor">
<transaction policy="pessimistic"/>
Added: lenya/trunk/src/webapp/lenya/usecases/edit/insertAsset.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/edit/insertAsset.jx?view=auto&rev=161753
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/edit/insertAsset.jx (added)
+++ lenya/trunk/src/webapp/lenya/usecases/edit/insertAsset.jx Mon Apr 18 03:54:37 2005
@@ -0,0 +1,136 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 1999-2004 The Apache Software Foundation
+
+ 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.
+-->
+
+<!-- $Id: assets.jx 161744 2005-04-18 08:54:26Z andreas $ -->
+
+<page:page xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
+ xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
+
+ <page:head>
+ <script>
+ ext = '';
+
+ function insertImage() {
+ var nodeid = '<jx:out value="${usecase.getParameter('document').getNodeId()}"/>/';
+ // var link = document.forms['image'].link.value;
+ var link = '';
+ var src = document.forms['image'].name.value;
+ var title = document.forms['image'].caption.value;
+ var type = document.forms['image'].type.value;
+ <![CDATA[
+ var content = '<object xmlns="'+window.opener.XHTMLNS+'" href="'+link+'" title="'+title+'" type="'+type+'" data="'+nodeid + src+'">'+src+'</object>';
+ ]]>
+ window.opener.bxe_insertContent(content,window.opener.bxe_ContextNode);
+ window.close();
+ }
+
+ function insertCaption(name, caption, type) {
+ document.forms['image'].name.value = name;
+ document.forms['image'].caption.value = caption;
+ document.forms['image'].type.value = type;
+ focus();
+ }
+ </script>
+ </page:head>
+
+ <page:body>
+ <form method="POST" name="image">
+ <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
+ <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+ <table class="lenya-table">
+ <tr>
+ <th/>
+ <th><i18n:text>Assets</i18n:text></th>
+ <th><i18n:text>Preview</i18n:text></th>
+ <th><i18n:text>Title</i18n:text></th>
+ <th><i18n:text>File Size</i18n:text></th>
+ <th><i18n:text>Creation Date</i18n:text></th>
+ </tr>
+ <jx:forEach var="asset" items="${usecase.getParameter('assets')}">
+ <tr>
+ <td><input type="radio" name="asset" value="${asset.getName()}"
+ onClick="javascript:insertCaption('${asset.getName()}', '${asset.getMetaData().getFirstValue('title')}', '${asset.getMimeType()}')"/></td>
+ <td><jx:out value="${asset.getName()}"/></td>
+ <td>
+ <jx:set var="mimeType" value="${asset.getMimeType()}"/>
+ <jx:if test="${mimeType.startsWith('image/')}">
+ <jx:set var="doc" value="${usecase.getParameter('document')}"/>
+ <img src="${request.getContextPath()}/${doc.getPublication().getId()}/authoring/${doc.getId()}/${asset.getName()}"
+ style="height: 32px; vertical-align: middle;"/> 
+ </jx:if>
+ </td>
+ <td><jx:out value="${asset.getMetaData().getFirstValue('title')}"/></td>
+ <td align="right"><jx:out value="${asset.getContentLength() / 1000}"/> kB</td>
+ <td align="right"><jx:out value="${java.text.DateFormat.getDateInstance().format(asset.getLastModified())}"/></td>
+ </tr>
+ </jx:forEach>
+ <tr>
+ <td colspan="6">
+ <div style="margin: 10px">
+ <i18n:text>Caption</i18n:text>: <input class="lenya-form-element" type="text" name="caption"/>
+ <input type="hidden" name="type" value=""/>
+ </div>
+ <div style="margin: 10px">
+ <input i18n:attr="value" type="submit" name="submit" value="Submit"
+ onClick="javascript:insertImage();" />
+  
+ <input i18n:attr="value" type="submit" name="cancel" value="Cancel"
+ onClick="location.href='javascript:window.close();';" />
+ </div>
+ </td>
+ </tr>
+ </table>
+ </form>
+ <jx:if test="${usecase.getParameter('document').getArea().equals('authoring')}">
+ <form method="POST" enctype="multipart/form-data">
+ <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
+ <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+ <table class="lenya-table-noborder">
+ <tr>
+ <td colspan="2">
+ <jx:import uri="templates/messages.jx"/>
+ </td>
+ </tr>
+ <tr>
+ <td class="lenya-entry-caption"><i18n:text>File</i18n:text> *</td>
+ <td><input type="file" name="file" class="lenya-form-element"/></td>
+ </tr>
+ <tr>
+ <td class="lenya-entry-caption"><i18n:text>Title</i18n:text> *</td>
+ <td><input type="text" name="title" class="lenya-form-element" value="${usecase.getParameter('title')}"/></td>
+ </tr>
+ <tr>
+ <td class="lenya-entry-caption"><i18n:text>Creator</i18n:text> *</td>
+ <td><input type="text" name="creator" class="lenya-form-element" value="${usecase.getParameter('creator')}"/></td>
+ </tr>
+ <tr>
+ <td class="lenya-entry-caption"><i18n:text>Rights</i18n:text> *</td>
+ <td><input type="text" name="rights" class="lenya-form-element" value="${usecase.getParameter('rights')}"/></td>
+ </tr>
+ <tr>
+ <td/>
+ <td>
+ <input i18n:attr="value" type="submit" value="New Asset"/>
+ </td>
+ </tr>
+ </table>
+ </form>
+ </jx:if>
+ </page:body>
+</page:page>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org