You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2010/01/28 09:08:01 UTC
svn commit: r903993 - in
/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole:
AttachmentProvider.java BinaryConfigurationPrinter.java
internal/misc/ConfigurationRender.java
Author: cziegeler
Date: Thu Jan 28 08:08:00 2010
New Revision: 903993
URL: http://svn.apache.org/viewvc?rev=903993&view=rev
Log:
FELIX-1993 : Enhance configuration printer support
Replaced BinaryConfigurationPrinter with AtachmentProvider - this gives more flexibility and reduces the number of methods to a single call.
Added:
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AttachmentProvider.java
- copied, changed from r903987, felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java
Removed:
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java
Modified:
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
Copied: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AttachmentProvider.java (from r903987, felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java)
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AttachmentProvider.java?p2=felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AttachmentProvider.java&p1=felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java&r1=903987&r2=903993&rev=903993&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AttachmentProvider.java Thu Jan 28 08:08:00 2010
@@ -19,42 +19,30 @@
package org.apache.felix.webconsole;
-import java.io.IOException;
-import java.io.OutputStream;
+import java.net.URL;
/**
* This is an optional extension of the {@link ConfigurationPrinter}.
* If a configuration printer implements this interface, the printer
- * can add additional files to the output of the configuration rendering.
+ * can add additional attamchemtns to the output of the configuration rendering.
*
* Currently this is only supported for the ZIP mode.
*
* A service implementing this method must still register itself
* as a {@link ConfigurationPrinter} but not as a
- * {@link BinaryConfigurationPrinter} service.
+ * {@link AttachmentProvider} service.
* @since 3.0
*/
-public interface BinaryConfigurationPrinter
- extends ConfigurationPrinter
+public interface AttachmentProvider
{
/**
- * Return a list of filename for the render mode.
- * The returned list should just contain filenames without
- * any path information.
- * @return An array of filenames or null.
+ * Return an array of attachments for the given render mode.
+ * The returned list should contain URLs pointing to the
+ * attachments for this mode.
+ * @param mode The render mode.
+ * @return An array of urls or null.
*/
- String[] getFilenames(String mode);
-
- /**
- * Write the contents of the file to the output stream.
- * @param name The filename.
- * @param out The output stream.
- * @throws IOException If any problem occurs during writing.
- * @throws IllegalArgumentException If the name is null or not
- * one from the list returned by {@link #getFilenames(String)}.
- */
- void writeFile(String name, String mode, OutputStream out)
- throws IOException;
+ URL[] getAttachments(String mode);
}
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java?rev=903993&r1=903992&r2=903993&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java Thu Jan 28 08:08:00 2010
@@ -18,6 +18,7 @@
import java.io.*;
+import java.net.URL;
import java.text.*;
import java.util.*;
import java.util.zip.ZipEntry;
@@ -27,6 +28,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.io.IOUtils;
import org.apache.felix.webconsole.*;
import org.apache.felix.webconsole.internal.BaseWebConsolePlugin;
import org.apache.felix.webconsole.internal.Util;
@@ -553,15 +555,37 @@
if ( desc.match(mode) )
{
// check if printer implements binary configuration printer
- if ( desc.printer instanceof BinaryConfigurationPrinter )
+ if ( desc.printer instanceof AttachmentProvider )
{
- final String[] names = ((BinaryConfigurationPrinter)desc.printer).getFilenames(mode);
- if ( names != null )
+ final URL[] attachments = ((AttachmentProvider)desc.printer).getAttachments(mode);
+ if ( attachments != null )
{
- for(int i = 0; i < names.length; i++)
+ for(int i = 0; i < attachments.length; i++)
{
- final OutputStream os = cf.startFile(desc.printer.getTitle(), names[i]);
- ((BinaryConfigurationPrinter)desc.printer).writeFile(names[i], mode, os);
+ final URL current = attachments[i];
+ final String path = current.getPath();
+ final String name;
+ if ( path == null || path.length() == 0 )
+ {
+ // sanity code, we should have a path, but if not let's just create
+ // some random name
+ name = UUID.randomUUID().toString();
+ }
+ else
+ {
+ final int pos = path.lastIndexOf('/');
+ name = (pos == -1 ? path : path.substring(pos + 1));
+ }
+ final OutputStream os = cf.startFile(desc.printer.getTitle(), name);
+ final InputStream is = current.openStream();
+ try
+ {
+ IOUtils.copy(is, os);
+ }
+ finally
+ {
+ IOUtils.closeQuietly(is);
+ }
cf.end();
}
}