felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1426150 - /felix/sandbox/cziegeler/status-printer/src/main/java/org/apache/felix/status/impl/AbstractWebConsolePlugin.java
Date Thu, 27 Dec 2012 09:58:43 GMT
Author: cziegeler
Date: Thu Dec 27 09:58:43 2012
New Revision: 1426150

URL: http://svn.apache.org/viewvc?rev=1426150&view=rev
Log:
Add json to the status zip

Modified:
    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/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=1426150&r1=1426149&r2=1426150&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
Thu Dec 27 09:58:43 2012
@@ -55,29 +55,17 @@ public abstract class AbstractWebConsole
 
     protected abstract StatusPrinterHandler getStatusPrinterHandler();
 
-    private void printSingleConfigurationStatus(final ConfigurationWriter pw,
+    private void printConfigurationStatus( final ConfigurationWriter pw,
             final PrinterMode mode,
-            final StatusPrinterHandler handler)
-    throws IOException {
-        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 printConfigurationStatus( final ConfigurationWriter pw, final PrinterMode
mode, final StatusPrinterHandler handler )
+            final StatusPrinterHandler handler )
     throws IOException {
         if ( handler == null ) {
             for(final StatusPrinterHandler sph : this.statusPrinterManager.getHandlers(mode))
{
-                printSingleConfigurationStatus(pw, mode, sph);
+                pw.printStatus(mode, sph);
             }
         } else {
             if ( handler.supports(mode) ) {
-                printSingleConfigurationStatus(pw, mode, handler);
+                pw.printStatus(mode, handler);
             }
         }
     }
@@ -241,14 +229,23 @@ public abstract class AbstractWebConsole
             super( delegatee );
         }
 
-        public void title( final String title ) throws IOException {
+        protected void title( final String title ) throws IOException {
             // dummy implementation
         }
 
 
-        public void end() throws IOException {
+        protected void end() throws IOException {
             // dummy implementation
         }
+
+        public void printStatus(
+                final PrinterMode mode,
+                final StatusPrinterHandler handler)
+        throws IOException {
+            this.title(handler.getTitle());
+            handler.print(mode, this);
+            this.end();
+        }
     }
 
     private static class HtmlConfigurationWriter extends ConfigurationWriter {
@@ -365,7 +362,7 @@ public abstract class AbstractWebConsole
         }
 
         @Override
-        public void title( final String title ) throws IOException {
+        protected void title( final String title ) throws IOException {
             print( "*** " );
             print( title );
             println( ":" );
@@ -373,7 +370,7 @@ public abstract class AbstractWebConsole
 
 
         @Override
-        public void end() throws IOException {
+        protected void end() throws IOException {
             println();
         }
     }
@@ -390,7 +387,7 @@ public abstract class AbstractWebConsole
         }
 
         @Override
-        public void title( final String title ) throws IOException {
+        protected void title( final String title ) throws IOException {
             counter++;
 
             final String name = MessageFormat.format( "{0,number,000}-{1}.txt", new Object[]
@@ -401,19 +398,35 @@ public abstract class AbstractWebConsole
         }
 
         @Override
-        public void end() throws IOException {
+        protected void end() throws IOException {
             flush();
 
             zip.closeEntry();
         }
 
-        public String getAttachmentPrefix(final String title) {
+        private String getAttachmentPrefix(final String title) {
             return MessageFormat.format( "{0,number,000}-{1}/", new Object[]
                     { new Integer( counter ), title } );
         }
 
-        public ZipOutputStream getZipOutputStream() {
-            return this.zip;
+        @Override
+        public void printStatus(
+                final PrinterMode mode,
+                final StatusPrinterHandler handler)
+        throws IOException {
+            super.printStatus(mode, handler);
+            handler.addAttachments(this.getAttachmentPrefix(handler.getTitle()), this.zip);
+            if ( handler.supports(PrinterMode.JSON) ) {
+                final String name = MessageFormat.format( "json/{0,number,000}-{1}.json",
new Object[]
+                        { new Integer( counter ), handler.getTitle() } );
+
+                final ZipEntry entry = new ZipEntry( name );
+                zip.putNextEntry( entry );
+                handler.print(PrinterMode.JSON, this);
+                flush();
+
+                zip.closeEntry();
+            }
         }
     }
 }
\ No newline at end of file



Mime
View raw message