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 2006/07/26 13:59:30 UTC
svn commit: r425715 - in /lenya/trunk/src/modules/resource/java:
src/org/apache/lenya/cms/publication/
src/org/apache/lenya/cms/site/usecases/ test/ test/org/ test/org/apache/
test/org/apache/lenya/ test/org/apache/lenya/cms/
test/org/apache/lenya/cms/...
Author: andreas
Date: Wed Jul 26 04:59:29 2006
New Revision: 425715
URL: http://svn.apache.org/viewvc?rev=425715&view=rev
Log:
Introduced ResourceWrapper, added tests for resource module
Added:
lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/
lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java
lenya/trunk/src/modules/resource/java/test/
lenya/trunk/src/modules/resource/java/test/org/
lenya/trunk/src/modules/resource/java/test/org/apache/
lenya/trunk/src/modules/resource/java/test/org/apache/lenya/
lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/
lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/publication/
lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/publication/ResourceWrapperTest.java
lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/
lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/usecases/
lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/usecases/ResourceLinkRewriterTest.java
Modified:
lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/site/usecases/CreateResource.java
lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/site/usecases/UploadResource.java
Added: lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java?rev=425715&view=auto
==============================================================================
--- lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java (added)
+++ lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/publication/ResourceWrapper.java Wed Jul 26 04:59:29 2006
@@ -0,0 +1,191 @@
+/*
+ * 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.publication;
+
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.util.Iterator;
+
+import javax.imageio.ImageIO;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.excalibur.source.ModifiableSource;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.TraversableSource;
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.metadata.MetaDataException;
+import org.apache.lenya.cms.repository.RepositoryException;
+
+/**
+ * Wrapper to handle resource documents.
+ */
+public class ResourceWrapper extends AbstractLogEnabled {
+
+ private ServiceManager manager;
+ private Document document;
+
+ /**
+ * @param document The document to wrap.
+ * @param manager The service manager.
+ * @param logger The logger.
+ */
+ public ResourceWrapper(Document document, ServiceManager manager, Logger logger) {
+ this.document = document;
+ this.manager = manager;
+ enableLogging(logger);
+ }
+
+ protected Document getDocument() {
+ return this.document;
+ }
+
+ /**
+ * @param file The part to write.
+ * @throws IOException
+ * @throws MetaDataException
+ * @throws ServiceException
+ * @throws RepositoryException
+ * @throws DocumentException
+ */
+ public void write(Part file) throws IOException, MetaDataException, ServiceException,
+ RepositoryException, DocumentException {
+
+ String mimeType = file.getMimeType();
+ String fileName = file.getFileName();
+ int fileSize = file.getSize();
+ InputStream inputStream = file.getInputStream();
+
+ write(inputStream, mimeType, fileName, fileSize);
+ }
+
+ /**
+ * Writes the content of the resource from a source.
+ * @param sourceUri The source URI.
+ * @throws ServiceException
+ * @throws MalformedURLException
+ * @throws IOException
+ * @throws RepositoryException
+ * @throws DocumentException
+ * @throws MetaDataException
+ */
+ public void write(String sourceUri) throws ServiceException, MalformedURLException,
+ IOException, RepositoryException, DocumentException, MetaDataException {
+ SourceResolver resolver = null;
+ TraversableSource source = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = (TraversableSource) resolver.resolveURI(sourceUri);
+ write(source.getInputStream(),
+ source.getMimeType(),
+ source.getName(),
+ source.getContentLength());
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ }
+
+ /**
+ * Writes the content of the resource.
+ * @param inputStream The input stream providing the content.
+ * @param mimeType The mime type.
+ * @param fileName The file name.
+ * @param fileSize The file size.
+ * @throws IOException
+ * @throws MetaDataException
+ * @throws ServiceException
+ * @throws MalformedURLException
+ * @throws RepositoryException
+ * @throws DocumentException
+ */
+ public void write(InputStream inputStream, String mimeType, String fileName, long fileSize)
+ throws IOException, MetaDataException, ServiceException, MalformedURLException,
+ RepositoryException, DocumentException {
+ final ByteArrayOutputStream sourceBos = new ByteArrayOutputStream();
+ IOUtils.copy(inputStream, sourceBos);
+
+ InputStream input = new ByteArrayInputStream(sourceBos.toByteArray());
+
+ MetaData mediaMeta = null;
+
+ SourceResolver resolver = null;
+ ModifiableSource source = null;
+ OutputStream destOutputStream = null;
+ try {
+ mediaMeta = document.getMetaData("http://apache.org/lenya/metadata/media/1.0");
+ addResourceMeta(fileName, mimeType, input, mediaMeta);
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = (ModifiableSource) resolver.resolveURI(document.getSourceURI());
+
+ // now that the source is determined, lock involved nodes
+ document.getRepositoryNode().lock();
+
+ destOutputStream = source.getOutputStream();
+ IOUtils.write(sourceBos.toByteArray(), destOutputStream);
+
+ document.setMimeType(mimeType);
+
+ } finally {
+ if (destOutputStream != null) {
+ destOutputStream.flush();
+ destOutputStream.close();
+ }
+ }
+
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("Resource::addResource() done.");
+ }
+
+ protected void addResourceMeta(String fileName, String mimeType, InputStream stream,
+ MetaData customMeta) throws MetaDataException, IOException {
+ if (customMeta != null) {
+ customMeta.setValue("filename", fileName);
+ }
+ if (canReadMimeType(mimeType)) {
+ BufferedImage input = ImageIO.read(stream);
+ String width = Integer.toString(input.getWidth());
+ String height = Integer.toString(input.getHeight());
+ customMeta.setValue("height", height);
+ customMeta.setValue("width", width);
+ }
+ }
+
+ /**
+ * Checks if a mime type denotes an image.
+ * @param mimeType The mime type.
+ * @return A boolean value.
+ */
+ public static boolean canReadMimeType(String mimeType) {
+ Iterator iter = ImageIO.getImageReadersByMIMEType(mimeType);
+ return iter.hasNext();
+ }
+
+}
Modified: lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/site/usecases/CreateResource.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/site/usecases/CreateResource.java?rev=425715&r1=425714&r2=425715&view=diff
==============================================================================
--- lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/site/usecases/CreateResource.java (original)
+++ lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/site/usecases/CreateResource.java Wed Jul 26 04:59:29 2006
@@ -16,30 +16,21 @@
*/
package org.apache.lenya.cms.site.usecases;
-import java.awt.image.BufferedImage;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Iterator;
-
-import javax.imageio.ImageIO;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.cocoon.servlet.multipart.Part;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.output.ByteArrayOutputStream;
-import org.apache.excalibur.source.ModifiableSource;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.lenya.cms.cocoon.source.RepositorySource;
-import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.MetaDataException;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.publication.ResourceWrapper;
+import org.apache.lenya.cms.repository.RepositoryException;
import org.apache.lenya.cms.usecase.UsecaseException;
+/**
+ * Create a new resource document.
+ */
public class CreateResource extends CreateDocument {
- // A media type document is an aggregation of different files.
/**
* Validates the request parameters.
@@ -81,8 +72,11 @@
* @throws IOException
* @throws ServiceException
* @throws DocumentException
+ * @throws MetaDataException
+ * @throws RepositoryException
*/
- protected void addResource() throws ServiceException, IOException, DocumentException {
+ protected void addResource() throws ServiceException, IOException, DocumentException,
+ RepositoryException, MetaDataException {
if (getLogger().isDebugEnabled())
getLogger().debug("Assets::addAsset() called");
@@ -93,61 +87,12 @@
String[] params = { Integer.toString(file.getSize()) };
addErrorMessage("upload-size-exceeded", params);
} else {
- addResource(file);
+ Document document = getNewDocument();
+ ResourceWrapper wrapper = new ResourceWrapper(document, this.manager, getLogger());
+ wrapper.write(file);
}
}
- /**
- * Adds the ressource.
- *
- * @param file The part.
- * @throws IOException
- * @throws ServiceException
- * @throws DocumentException
- */
- protected void addResource(Part file) throws IOException, ServiceException, DocumentException {
- Document document = getNewDocument();
- MetaData mediaMeta = null;
-
- SourceResolver resolver = null;
- ModifiableSource source = null;
- OutputStream destOutputStream = null;
- InputStream inputStream = file.getInputStream();
- try {
- mediaMeta = document.getMetaData("http://apache.org/lenya/metadata/media/1.0");
- addResourceMeta(file, mediaMeta);
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
-
- String destination = getNewDocument().getSourceURI();
- source = (ModifiableSource) resolver.resolveURI(destination);
-
- // now that the source is determined, lock involved nodes
- Node node = getRepositoryNode(destination);
- node.lock();
-
- destOutputStream = source.getOutputStream();
- final ByteArrayOutputStream sourceBos = new ByteArrayOutputStream();
- IOUtils.copy(inputStream, sourceBos);
- IOUtils.write(sourceBos.toByteArray(), destOutputStream);
-
- document.setMimeType(file.getMimeType());
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (destOutputStream != null) {
- destOutputStream.flush();
- destOutputStream.close();
- }
- if (inputStream != null) {
- inputStream.close();
- }
- }
-
- if (getLogger().isDebugEnabled())
- getLogger().debug("Resource::addResource() done.");
- }
-
protected String getSourceExtension() {
String extension = "";
@@ -162,52 +107,4 @@
return extension;
}
- protected void addResourceMeta(Part part, MetaData customMeta) throws MetaDataException,
- IOException {
- String fileName = part.getFileName();
- String mimeType = part.getMimeType();
- int fileSize = part.getSize();
- if (customMeta != null) {
- customMeta.setValue("filename", fileName);
- }
- if (canReadMimeType(mimeType)) {
- BufferedImage input = ImageIO.read(part.getInputStream());
- String width = Integer.toString(input.getWidth());
- String height = Integer.toString(input.getHeight());
- if (customMeta != null) {
- customMeta.setValue("height", height);
- customMeta.setValue("width", width);
- }
- }
- }
-
- public static boolean canReadMimeType(String mimeType) {
- Iterator iter = ImageIO.getImageReadersByMIMEType(mimeType);
- return iter.hasNext();
- }
-
- /**
- * @return The repository node that represents the document identified by the destination
- * string.
- */
- public Node getRepositoryNode(String destination) {
- Node node = null;
- SourceResolver resolver = null;
- RepositorySource documentSource = null;
- try {
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- documentSource = (RepositorySource) resolver.resolveURI(destination);
- node = documentSource.getNode();
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (resolver != null) {
- if (documentSource != null) {
- resolver.release(documentSource);
- }
- this.manager.release(resolver);
- }
- }
- return node;
- }
}
Modified: lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/site/usecases/UploadResource.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/site/usecases/UploadResource.java?rev=425715&r1=425714&r2=425715&view=diff
==============================================================================
--- lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/site/usecases/UploadResource.java (original)
+++ lenya/trunk/src/modules/resource/java/src/org/apache/lenya/cms/site/usecases/UploadResource.java Wed Jul 26 04:59:29 2006
@@ -16,26 +16,9 @@
*/
package org.apache.lenya.cms.site.usecases;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import javax.imageio.ImageIO;
-
-import org.apache.avalon.framework.service.ServiceException;
import org.apache.cocoon.servlet.multipart.Part;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.output.ByteArrayOutputStream;
-import org.apache.excalibur.source.ModifiableSource;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.lenya.cms.cocoon.source.RepositorySource;
-import org.apache.lenya.cms.metadata.MetaData;
-import org.apache.lenya.cms.metadata.MetaDataException;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.repository.Node;
-import org.apache.lenya.cms.repository.RepositoryException;
+import org.apache.lenya.cms.publication.ResourceWrapper;
import org.apache.lenya.cms.usecase.DocumentUsecase;
/**
@@ -45,13 +28,6 @@
public class UploadResource extends DocumentUsecase {
/**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
- protected void initParameters() {
- super.initParameters();
- }
-
- /**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
*/
protected void doExecute() throws Exception {
@@ -64,120 +40,10 @@
String[] params = { Integer.toString(file.getSize()) };
addErrorMessage("upload-size-exceeded", params);
} else {
- saveResource(file);
+ Document document = getSourceDocument();
+ ResourceWrapper wrapper = new ResourceWrapper(document, this.manager, getLogger());
+ wrapper.write(file);
}
}
- /**
- * Adds the ressource.
- *
- * @param file The part.
- * @throws IOException
- * @throws ServiceException
- * @throws DocumentException
- * @throws MetaDataException
- */
- protected void saveResource(Part file) throws IOException, ServiceException, DocumentException,
- MetaDataException {
- Document document = getSourceDocument();
- String destination = document.getSourceURI();
-
- SourceResolver resolver = null;
- ModifiableSource source = null;
- OutputStream destOutputStream = null;
- InputStream inputStream = file.getInputStream();
- try {
-
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- source = (ModifiableSource) resolver.resolveURI(destination);
-
- // now that the source is determined, lock involved nodes
- Node node = getRepositoryNode(destination);
- node.lock();
-
- destOutputStream = source.getOutputStream();
- final ByteArrayOutputStream sourceBos = new ByteArrayOutputStream();
- IOUtils.copy(inputStream, sourceBos);
- IOUtils.write(sourceBos.toByteArray(), destOutputStream);
-
- document.setMimeType(file.getMimeType());
- } catch (RepositoryException e) {
- throw new RuntimeException(e);
- } finally {
- if (destOutputStream != null) {
- destOutputStream.flush();
- destOutputStream.close();
- }
- if (inputStream != null) {
- inputStream.close();
- }
- }
-
- MetaData customMeta = document.getMetaData("http://apache.org/lenya/metadata/media/1.0");
- updateResourceMeta(file, customMeta);
-
- // update <lenya:extension>
- MetaData internalMeta = document.getMetaData("http://apache.org/lenya/metadata/document/1.0");
- internalMeta.setValue("extension", getSourceExtension());
-
- if (getLogger().isDebugEnabled())
- getLogger().debug("Resource::addResource() done.");
- }
-
- protected String getSourceExtension() {
- String extension = "";
-
- Part file = getPart("file");
- String fileName = file.getFileName();
- int lastDotIndex = fileName.lastIndexOf(".");
- if (lastDotIndex > -1) {
- extension = fileName.substring(lastDotIndex + 1);
- } else {
- addErrorMessage("Please upload a file with an extension.");
- }
- return extension;
- }
-
- protected void updateResourceMeta(Part part, MetaData customMeta) throws MetaDataException,
- IOException {
- String fileName = part.getFileName();
- String mimeType = part.getMimeType();
- if (customMeta != null) {
- customMeta.setValue("filename", fileName);
- }
- if (CreateResource.canReadMimeType(mimeType)) {
- BufferedImage input = ImageIO.read(part.getInputStream());
- String width = Integer.toString(input.getWidth());
- String height = Integer.toString(input.getHeight());
- if (customMeta != null) {
- customMeta.setValue("height", height);
- customMeta.setValue("width", width);
- }
- }
- }
-
- /**
- * @return The repository node that represents the document identified by the destination
- * string.
- */
- public Node getRepositoryNode(String destination) {
- Node node = null;
- SourceResolver resolver = null;
- RepositorySource documentSource = null;
- try {
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- documentSource = (RepositorySource) resolver.resolveURI(destination);
- node = documentSource.getNode();
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (resolver != null) {
- if (documentSource != null) {
- resolver.release(documentSource);
- }
- this.manager.release(resolver);
- }
- }
- return node;
- }
-}
+}
\ No newline at end of file
Added: lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/publication/ResourceWrapperTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/publication/ResourceWrapperTest.java?rev=425715&view=auto
==============================================================================
--- lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/publication/ResourceWrapperTest.java (added)
+++ lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/publication/ResourceWrapperTest.java Wed Jul 26 04:59:29 2006
@@ -0,0 +1,136 @@
+/*
+ * Copyright 1999-2005 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.publication;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.TraversableSource;
+import org.apache.lenya.ac.impl.AbstractAccessControlTest;
+import org.apache.lenya.cms.metadata.MetaDataException;
+import org.apache.lenya.cms.repository.RepositoryException;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.cms.site.SiteUtil;
+
+/**
+ * Resource wrapper test.
+ */
+public class ResourceWrapperTest extends AbstractAccessControlTest {
+
+ public static final String IMAGE_URL = "context://lenya/resources/images/project-logo.png";
+
+ /**
+ * @throws RepositoryException
+ * @throws PublicationException
+ * @throws ServiceException
+ * @throws MetaDataException
+ * @throws IOException
+ * @throws MalformedURLException
+ */
+ public void testResourceWrapper() throws RepositoryException, PublicationException,
+ ServiceException, MalformedURLException, IOException, MetaDataException {
+
+ String documentId = "/testResource";
+
+ Session session = RepositoryUtil.getSession(getManager(), getRequest());
+ DocumentFactory factory = DocumentUtil.createDocumentIdentityMap(getManager(), session);
+
+ Publication pub = PublicationUtil.getPublication(getManager(), "test");
+
+ Document doc = createResource(factory, pub, documentId, getManager(), getLogger());
+
+ SourceResolver resolver = null;
+ TraversableSource source = null;
+
+ try {
+ resolver = (SourceResolver) getManager().lookup(SourceResolver.ROLE);
+ source = (TraversableSource) resolver.resolveURI(IMAGE_URL);
+
+ assertEquals(doc.getMimeType(), source.getMimeType());
+ assertEquals(doc.getContentLength(), source.getContentLength());
+
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ getManager().release(resolver);
+ }
+
+ }
+
+ }
+
+ /**
+ * @param factory
+ * @param pub
+ * @param documentId
+ * @return
+ * @throws ServiceException
+ * @throws DocumentBuildException
+ * @throws PublicationException
+ * @throws MalformedURLException
+ * @throws IOException
+ * @throws RepositoryException
+ * @throws DocumentException
+ * @throws MetaDataException
+ */
+ public static Document createResource(DocumentFactory factory, Publication pub, String documentId,
+ ServiceManager manager, Logger logger)
+ throws ServiceException, DocumentBuildException, PublicationException,
+ MalformedURLException, IOException, RepositoryException, DocumentException,
+ MetaDataException {
+
+ String extension = "png";
+
+ Document doc = null;
+
+ ResourceType resourceType = null;
+ ServiceSelector selector = null;
+ DocumentManager docManager = null;
+
+ try {
+ docManager = (DocumentManager) manager.lookup(DocumentManager.ROLE);
+ doc = factory.get(pub, Publication.AUTHORING_AREA, documentId, pub.getDefaultLanguage());
+
+ SiteUtil.getSiteStructure(manager, doc).getRepositoryNode().lock();
+
+ selector = (ServiceSelector) manager.lookup(ResourceType.ROLE + "Selector");
+ resourceType = (ResourceType) selector.select("resource");
+
+ docManager.add(doc, resourceType, extension, "Test Resource", true);
+
+ ResourceWrapper resource = new ResourceWrapper(doc, manager, logger);
+ resource.write(IMAGE_URL);
+ } finally {
+ if (docManager != null) {
+ manager.release(docManager);
+ }
+ if (selector != null) {
+ manager.release(selector);
+ }
+ }
+ return doc;
+ }
+
+}
Added: lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/usecases/ResourceLinkRewriterTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/usecases/ResourceLinkRewriterTest.java?rev=425715&view=auto
==============================================================================
--- lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/usecases/ResourceLinkRewriterTest.java (added)
+++ lenya/trunk/src/modules/resource/java/test/org/apache/lenya/cms/site/usecases/ResourceLinkRewriterTest.java Wed Jul 26 04:59:29 2006
@@ -0,0 +1,51 @@
+/*
+ * 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.site.usecases;
+
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationUtil;
+import org.apache.lenya.cms.publication.ResourceWrapperTest;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
+
+/**
+ * Link rewriter test for the "resource" resource type.
+ */
+public class ResourceLinkRewriterTest extends LinkRewriterTest {
+
+ /**
+ * Check if the link rewriter doesn't try to rewrite links in resources.
+ * @throws Exception
+ */
+ public void testResourceLinkRewriting() throws Exception {
+ String documentId = "/testResourceLinkRewriting";
+
+ Session session = RepositoryUtil.getSession(getManager(), getRequest());
+ DocumentFactory factory = DocumentUtil.createDocumentIdentityMap(getManager(), session);
+
+ Publication pub = PublicationUtil.getPublication(getManager(), "test");
+
+
+ ResourceWrapperTest.createResource(factory, pub, documentId, getManager(), getLogger());
+
+ super.testLinkRewriter();
+
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org