felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1424847 - in /felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status: ZipAttachmentProvider.java impl/AbstractWebConsolePlugin.java
Date Fri, 21 Dec 2012 10:24:44 GMT
Author: cziegeler
Date: Fri Dec 21 10:24:44 2012
New Revision: 1424847

URL: http://svn.apache.org/viewvc?rev=1424847&view=rev
Log:
Improve zip handling

Modified:
    felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/ZipAttachmentProvider.java
    felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/impl/AbstractWebConsolePlugin.java

Modified: felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/ZipAttachmentProvider.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/ZipAttachmentProvider.java?rev=1424847&r1=1424846&r2=1424847&view=diff
==============================================================================
--- felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/ZipAttachmentProvider.java
(original)
+++ felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/ZipAttachmentProvider.java
Fri Dec 21 10:24:44 2012
@@ -24,7 +24,8 @@ import java.util.zip.ZipOutputStream;
 /**
  * This is an optional extension of the {@link StatusPrinter}.
  * If a status printer implements this interface, the printer
- * can add additional attachments to the output of the configuration zip.
+ * can add additional attachments to the output of the
+ * configuration zip.
  *
  * A service implementing this method must still register itself
  * as a {@link StatusPrinter} but not as a
@@ -33,10 +34,19 @@ import java.util.zip.ZipOutputStream;
 public interface ZipAttachmentProvider extends StatusPrinter {
 
     /**
-     * Return an array of attachments
-     * The returned list should contain URLs pointing to the
-     * attachments.
-     * @return An array of URLs or null.
+     * Add attachments to the zip output stream.
+     * The attachment provider can add as many attachments in any format
+     * as it wants. However it should use the namePrefix to create unique
+     * names / paths inside the zip.
+     *
+     * The general pattern is: creating a zip entry by using the name prefix
+     * and a name, adding the entry to the zip output stream, writing
+     * the content of the file to the stream, and finally ending the
+     * zip entry.
+     *
+     * @param namePrefix Name prefix to use for zip entries. Ends with a slash.
+     * @param zos The zip output stream.
+     * @throws IOException
      */
     void addAttachments(final String namePrefix, final ZipOutputStream zos)
     throws IOException;

Modified: felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/impl/AbstractWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/impl/AbstractWebConsolePlugin.java?rev=1424847&r1=1424846&r2=1424847&view=diff
==============================================================================
--- felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/impl/AbstractWebConsolePlugin.java
(original)
+++ felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/impl/AbstractWebConsolePlugin.java
Fri Dec 21 10:24:44 2012
@@ -55,32 +55,29 @@ public abstract class AbstractWebConsole
 
     protected abstract StatusPrinterHandler getStatusPrinterHandler();
 
-    private void printConfigurationStatus( final ConfigurationWriter pw, final PrinterMode
mode, final StatusPrinterHandler handler )
+    private void printSingleConfigurationStatus(final ConfigurationWriter pw,
+            final PrinterMode mode,
+            final StatusPrinterHandler handler)
     throws IOException {
-        if ( handler == null ) {
-            for(final StatusPrinterHandler sph : this.statusPrinterManager.getHandlers(mode))
{
-                pw.title(sph.getTitle());
-                sph.print(mode, pw);
-                pw.end();
-            }
-        } else {
-            if ( handler.supports(mode) ) {
-                pw.title(handler.getTitle());
-                handler.print(mode, pw);
-                pw.end();
-            }
+        final ZipConfigurationWriter zcw = (pw instanceof ZipConfigurationWriter ? (ZipConfigurationWriter)pw
: null);
+        pw.title(handler.getTitle());
+        handler.print(mode, pw);
+        pw.end();
+        if ( zcw != null ) {
+            handler.addAttachments(zcw.getAttachmentPrefix(handler.getTitle()), zcw.getZipOutputStream());
         }
+
     }
 
-    private void addAttachments( final ZipConfigurationWriter cf, final StatusPrinterHandler
handler )
+    private void printConfigurationStatus( final ConfigurationWriter pw, final PrinterMode
mode, final StatusPrinterHandler handler )
     throws IOException {
         if ( handler == null ) {
-            for(final StatusPrinterHandler sph : this.statusPrinterManager.getHandlers(PrinterMode.ZIP_FILE))
{
-                sph.addAttachments(cf.getAttachmentPrefix(sph.getTitle()), cf.getZipOutputStream());
+            for(final StatusPrinterHandler sph : this.statusPrinterManager.getHandlers(mode))
{
+                printSingleConfigurationStatus(pw, mode, sph);
             }
         } else {
-            if ( handler.supports(PrinterMode.ZIP_FILE) ) {
-                handler.addAttachments(cf.getAttachmentPrefix(handler.getTitle()), cf.getZipOutputStream());
+            if ( handler.supports(mode) ) {
+                printSingleConfigurationStatus(pw, mode, handler);
             }
         }
     }
@@ -157,7 +154,6 @@ public abstract class AbstractWebConsole
             final ZipConfigurationWriter pw = new ZipConfigurationWriter( zip );
             printConfigurationStatus( pw, PrinterMode.ZIP_FILE, handler );
 
-            this.addAttachments( pw, handler );
             zip.finish();
         } else if ( request.getPathInfo().endsWith( ".nfo" ) ) {
             if ( handler == null ) {
@@ -417,7 +413,6 @@ public abstract class AbstractWebConsole
         }
 
         public ZipOutputStream getZipOutputStream() {
-            counter++;
             return this.zip;
         }
     }



Mime
View raw message