felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1450616 - in /felix/trunk/inventory/src/main/java/org/apache/felix/inventory: ./ impl/ impl/webconsole/
Date Wed, 27 Feb 2013 06:35:20 GMT
Author: cziegeler
Date: Wed Feb 27 06:35:20 2013
New Revision: 1450616

URL: http://svn.apache.org/r1450616
Log:
Distinguish between output format and delivery channel (web console or zip)

Modified:
    felix/trunk/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java
    felix/trunk/inventory/src/main/java/org/apache/felix/inventory/PrinterMode.java
    felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/AbstractWebConsolePlugin.java
    felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/DefaultWebConsolePlugin.java
    felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
    felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
    felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
    felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java

Modified: felix/trunk/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java
URL: http://svn.apache.org/viewvc/felix/trunk/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java?rev=1450616&r1=1450615&r2=1450616&view=diff
==============================================================================
--- felix/trunk/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java (original)
+++ felix/trunk/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java Wed
Feb 27 06:35:20 2013
@@ -66,6 +66,13 @@ public interface InventoryPrinter {
     String CONFIG_TITLE = "felix.inventory.printer.title"; //$NON-NLS-1$
 
     /**
+     * Optional property controlling whether the printer will be displayed
+     * in the web console. By default, a printer is displayed in the
+     * web console, unless this property is added with the value 'false'.
+     */
+    String CONFIG_WEBCONSOLE = "felix.inventory.printer.webconsole"; //$NON-NLS-1$
+
+    /**
      * Prints the configuration report to the given <code>printWriter</code>.
      * Implementations are free to print whatever information they deem useful.
      *
@@ -75,6 +82,7 @@ public interface InventoryPrinter {
      * @param mode The render mode.
      * @param printWriter where to write the configuration data. It might be flushed,
      * but must not be closed.
+     * @param isZip whether this is included in a zip file or used directly
      */
-    void print( PrinterMode mode, PrintWriter printWriter );
+    void print( PrinterMode mode, PrintWriter printWriter, boolean isZip );
 }

Modified: felix/trunk/inventory/src/main/java/org/apache/felix/inventory/PrinterMode.java
URL: http://svn.apache.org/viewvc/felix/trunk/inventory/src/main/java/org/apache/felix/inventory/PrinterMode.java?rev=1450616&r1=1450615&r2=1450616&view=diff
==============================================================================
--- felix/trunk/inventory/src/main/java/org/apache/felix/inventory/PrinterMode.java (original)
+++ felix/trunk/inventory/src/main/java/org/apache/felix/inventory/PrinterMode.java Wed Feb
27 06:35:20 2013
@@ -26,18 +26,12 @@ public final class PrinterMode {
     // plain text
     public static PrinterMode TEXT = new PrinterMode("TEXT");
 
-    // HTML which can be placed inside a HTML body element (no external references)
-    public static PrinterMode HTML_BODY = new PrinterMode("HTML_BODY");
+    // valid HTML fragment (no external references)
+    public static PrinterMode HTML_FRAGMENT = new PrinterMode("HTML_FRAGMENT");
 
     // JSON output
     public static PrinterMode JSON = new PrinterMode("JSON");
 
-    // file content for a zip
-    public static PrinterMode ZIP_FILE_TEXT = new PrinterMode("ZIP_FILE_TEXT");
-
-    // json file content for a zip
-    public static PrinterMode ZIP_FILE_JSON = new PrinterMode("ZIP_FILE_JSON");
-
     private final String mode;
 
     private PrinterMode(final String mode) {
@@ -47,14 +41,10 @@ public final class PrinterMode {
     public static PrinterMode valueOf(final String m) {
         if ( TEXT.name().equals(m) ) {
             return TEXT;
-        } else if ( HTML_BODY.name().equals(m) ) {
-            return HTML_BODY;
+        } else if ( HTML_FRAGMENT.name().equals(m) ) {
+            return HTML_FRAGMENT;
         } else if ( JSON.name().equals(m) ) {
             return JSON;
-        } else if ( ZIP_FILE_TEXT.name().equals(m) ) {
-            return ZIP_FILE_TEXT;
-        } else if ( ZIP_FILE_JSON.name().equals(m) ) {
-            return ZIP_FILE_JSON;
         }
         return null;
     }

Modified: felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/AbstractWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/AbstractWebConsolePlugin.java?rev=1450616&r1=1450615&r2=1450616&view=diff
==============================================================================
--- felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/AbstractWebConsolePlugin.java
(original)
+++ felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/AbstractWebConsolePlugin.java
Wed Feb 27 06:35:20 2013
@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.Writer;
-import java.text.MessageFormat;
 import java.util.Date;
 import java.util.zip.Deflater;
 import java.util.zip.ZipEntry;
@@ -139,9 +138,8 @@ public abstract class AbstractWebConsole
             zip.closeEntry();
 
             final ZipConfigurationWriter pw = new ZipConfigurationWriter( zip );
-            printConfigurationInventory( pw, PrinterMode.ZIP_FILE_TEXT, handler );
-            pw.counter = 0;
-            printConfigurationInventory( pw, PrinterMode.ZIP_FILE_JSON, handler );
+            printConfigurationInventory( pw, PrinterMode.TEXT, handler );
+            printConfigurationInventory( pw, PrinterMode.JSON, handler );
 
             zip.finish();
         } else if ( request.getPathInfo().endsWith( ".nfo" ) ) {
@@ -157,11 +155,15 @@ public abstract class AbstractWebConsole
             pw.println ( "<html xmlns=\"http://www.w3.org/1999/xhtml\">" );
             pw.println ( "<head><title>dummy</title></head><body><div>"
);
 
-            if ( handler.supports(PrinterMode.HTML_BODY) ) {
-                handler.print(PrinterMode.HTML_BODY, pw);
+            if ( handler.supports(PrinterMode.HTML_FRAGMENT) ) {
+                handler.print(PrinterMode.HTML_FRAGMENT, pw, false);
+            } else if ( handler.supports(PrinterMode.TEXT) ) {
+                pw.enableFilter( true );
+                handler.print(PrinterMode.TEXT, pw, false);
+                pw.enableFilter( false );
             } else {
                 pw.enableFilter( true );
-                handler.print(PrinterMode.TEXT, pw);
+                handler.print(PrinterMode.JSON, pw, false);
                 pw.enableFilter( false );
             }
             pw.println( "</div></body></html>" );
@@ -218,20 +220,18 @@ public abstract class AbstractWebConsole
             if ( handler.supports(PrinterMode.JSON) ) {
                 pw.print("<button type=\"button\" class=\"downloadJson\" style=\"float:
right; margin-right: 30px; margin-top: 5px;\">Download As JSON</button>");
             }
-            if ( handler.supports(PrinterMode.ZIP_FILE_TEXT) || handler.supports(PrinterMode.ZIP_FILE_JSON)
) {
-                pw.print("<button type=\"button\" class=\"downloadZip\" style=\"float:
right; margin-right: 30px; margin-top: 5px;\">Download As Zip</button>");
-            }
+            pw.print("<button type=\"button\" class=\"downloadZip\" style=\"float: right;
margin-right: 30px; margin-top: 5px;\">Download As Zip</button>");
             if ( handler.supports(PrinterMode.TEXT ) ) {
                 pw.print("<button type=\"button\" class=\"downloadTxt\" style=\"float:
right; margin-right: 30px; margin-top: 5px;\">Download As Text</button>");
             }
 
             pw.println("<br/>&nbsp;</p>"); // status line
             pw.print("<div>");
-            if ( handler.supports(PrinterMode.HTML_BODY) ) {
-                handler.print(PrinterMode.HTML_BODY, pw);
+            if ( handler.supports(PrinterMode.HTML_FRAGMENT) ) {
+                handler.print(PrinterMode.HTML_FRAGMENT, pw, false);
             } else {
                 pw.enableFilter( true );
-                handler.print(PrinterMode.TEXT, pw);
+                handler.print(PrinterMode.TEXT, pw, false);
                 pw.enableFilter( false );
             }
             pw.print("</div>");
@@ -261,7 +261,7 @@ public abstract class AbstractWebConsole
                 final InventoryPrinterHandler handler)
         throws IOException {
             this.title(handler.getTitle());
-            handler.print(mode, this);
+            handler.print(mode, this, false);
             this.end();
         }
     }
@@ -412,54 +412,34 @@ public abstract class AbstractWebConsole
 
         private final ZipOutputStream zip;
 
-        private int counter;
-
         ZipConfigurationWriter( final ZipOutputStream zip ) {
             super( new OutputStreamWriter( zip ) );
             this.zip = zip;
         }
 
-        private String getFormattedTitle(final String title) {
-            return MessageFormat.format( "{0,number,000}-{1}", new Object[]
-                    { new Integer( counter ), title } );
-        }
-
-        protected void title( final String title ) throws IOException {
-            counter++;
-
-            final String name = getFormattedTitle(title).concat(".txt");
-
-            final ZipEntry entry = new ZipEntry( name );
-            zip.putNextEntry( entry );
-        }
-
-        protected void end() throws IOException {
-            flush();
-
-            zip.closeEntry();
-        }
-
         public void printInventory(
                 final PrinterMode mode,
                 final InventoryPrinterHandler handler)
         throws IOException {
-            if ( mode == PrinterMode.ZIP_FILE_TEXT ) {
-                super.printInventory(mode, handler);
-                final String title = getFormattedTitle(handler.getTitle());
-                handler.addAttachments(title.concat("/"), this.zip);
-            } else {
-                counter++;
-                final String title = getFormattedTitle(handler.getTitle());
-                final String name = "json/".concat(title).concat(".json");
+            if ( mode == PrinterMode.TEXT ) {
+                final ZipEntry entry = new ZipEntry( handler.getName().concat(".txt") );
+                zip.putNextEntry( entry );
+                handler.print(mode, this, false);
+                flush();
+                zip.closeEntry();
+
+                handler.addAttachments(handler.getName().concat("/"), this.zip);
+            } else if ( mode == PrinterMode.JSON ) {
+                final String name = "json/".concat(handler.getName()).concat(".json");
 
                 final ZipEntry entry = new ZipEntry( name );
                 zip.putNextEntry( entry );
-                handler.print(PrinterMode.ZIP_FILE_JSON, this);
+                handler.print(PrinterMode.JSON, this, true);
                 flush();
 
                 zip.closeEntry();
-                if ( !handler.supports(PrinterMode.ZIP_FILE_TEXT) ) {
-                    handler.addAttachments(title.concat("/"), this.zip);
+                if ( !handler.supports(PrinterMode.TEXT) ) {
+                    handler.addAttachments(handler.getName().concat("/"), this.zip);
                 }
             }
         }

Modified: felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/DefaultWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/DefaultWebConsolePlugin.java?rev=1450616&r1=1450615&r2=1450616&view=diff
==============================================================================
--- felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/DefaultWebConsolePlugin.java
(original)
+++ felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/DefaultWebConsolePlugin.java
Wed Feb 27 06:35:20 2013
@@ -77,9 +77,9 @@ public class DefaultWebConsolePlugin ext
     }
 
     /**
-     * @see org.apache.felix.inventory.InventoryPrinter#print(org.apache.felix.inventory.PrinterMode,
java.io.PrintWriter)
+     * @see org.apache.felix.inventory.InventoryPrinter#print(org.apache.felix.inventory.PrinterMode,
java.io.PrintWriter, boolean)
      */
-    public void print(final PrinterMode mode, final PrintWriter printWriter) {
+    public void print(final PrinterMode mode, final PrintWriter printWriter, final boolean
isZip) {
         final InventoryPrinterHandler[] handlers = this.inventoryPrinterManager.getAllHandlers();
         printWriter.print("Currently registered ");
         printWriter.print(String.valueOf(handlers.length));

Modified: felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java?rev=1450616&r1=1450615&r2=1450616&view=diff
==============================================================================
--- felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
(original)
+++ felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
Wed Feb 27 06:35:20 2013
@@ -56,7 +56,7 @@ public class InventoryPrinterAdapter imp
 
             // print(String, PrintWriter)
             printMethod = ClassUtils.searchMethod(service.getClass(), "print",
-                    new Class[] {String.class, PrintWriter.class});
+                    new Class[] {String.class, PrintWriter.class, Boolean.class});
             if ( printMethod == null ) {
                 return null;
             }
@@ -113,9 +113,11 @@ public class InventoryPrinterAdapter imp
     }
 
     public void registerConsole(final BundleContext context, final InventoryPrinterManagerImpl
manager) {
-        if ( this.registration == null &&
-             (supports(PrinterMode.HTML_BODY) || supports(PrinterMode.TEXT))) {
-            this.registration = WebConsolePlugin.register(context, manager, this.description);
+        if ( this.registration == null ) {
+            final Object value = this.description.getServiceReference().getProperty(InventoryPrinter.CONFIG_WEBCONSOLE);
+            if ( value == null || !"false".equalsIgnoreCase(value.toString()) ) {
+                this.registration = WebConsolePlugin.register(context, manager, this.description);
+            }
         }
     }
 
@@ -176,12 +178,13 @@ public class InventoryPrinterAdapter imp
      * @see org.apache.felix.inventory.InventoryPrinter#print(org.apache.felix.inventory.PrinterMode,
java.io.PrintWriter)
      */
     public void print(final PrinterMode mode,
-            final PrintWriter printWriter) {
+            final PrintWriter printWriter,
+            final boolean isZip) {
         if ( this.supports(mode) ) {
             if ( this.printer instanceof InventoryPrinter ) {
-                ((InventoryPrinter)this.printer).print(mode, printWriter);
+                ((InventoryPrinter)this.printer).print(mode, printWriter, isZip);
             } else {
-                ClassUtils.invoke(this.printer, this.printMethod, new Object[] {mode.toString(),
printWriter});
+                ClassUtils.invoke(this.printer, this.printMethod, new Object[] {mode.toString(),
printWriter, Boolean.valueOf(isZip)});
             }
         }
     }

Modified: felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java?rev=1450616&r1=1450615&r2=1450616&view=diff
==============================================================================
--- felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
(original)
+++ felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
Wed Feb 27 06:35:20 2013
@@ -43,12 +43,26 @@ public class InventoryPrinterDescription
         // check modes
         final Object modesCfg = ref.getProperty(InventoryPrinter.CONFIG_PRINTER_MODES);
         if ( modesCfg instanceof String ) {
-            this.modes = new PrinterMode[] { PrinterMode.valueOf((String)modesCfg)};
+            final PrinterMode mode = PrinterMode.valueOf((String)modesCfg);
+            if ( mode != null ) {
+                this.modes = new PrinterMode[] {mode};
+            } else {
+                this.modes = null;
+            }
         } else if ( modesCfg instanceof String[] ) {
             final String[] modesCfgArray = (String[])modesCfg;
-            this.modes = new PrinterMode[modesCfgArray.length];
+            final PrinterMode[] pModes = new PrinterMode[modesCfgArray.length];
+            boolean invalid = false;
             for(int i=0; i<modesCfgArray.length;i++) {
-                this.modes[i] = PrinterMode.valueOf(modesCfgArray[i]);
+                pModes[i] = PrinterMode.valueOf(modesCfgArray[i]);
+                if ( pModes[i] == null ) {
+                    invalid = true;
+                }
+            }
+            if ( invalid ) {
+                this.modes = null;
+            } else {
+                this.modes = pModes;
             }
         } else {
             this.modes = null;

Modified: felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java?rev=1450616&r1=1450615&r2=1450616&view=diff
==============================================================================
--- felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
(original)
+++ felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
Wed Feb 27 06:35:20 2013
@@ -184,11 +184,11 @@ public class ConfigurationPrinterAdapter
     public String[] getPrinterModes() {
         final Set list = new HashSet();
         if ( this.match(ConsoleConstants.MODE_TXT) || this.match(ConsoleConstants.MODE_ZIP)
) {
-            list.add(PrinterMode.ZIP_FILE_TEXT.name());
+            list.add(PrinterMode.TEXT.name());
         }
         if ( this.match(ConsoleConstants.MODE_WEB) ) {
             if ( !escapeHtml ) {
-                list.add(PrinterMode.HTML_BODY.name());
+                list.add(PrinterMode.HTML_FRAGMENT.name());
             } else {
                 list.add(PrinterMode.TEXT.name());
             }

Modified: felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java?rev=1450616&r1=1450615&r2=1450616&view=diff
==============================================================================
--- felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java
(original)
+++ felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java
Wed Feb 27 06:35:20 2013
@@ -162,13 +162,13 @@ public class WebConsoleAdapter implement
         /**
          * @see org.apache.felix.inventory.InventoryPrinter#print(org.apache.felix.inventory.PrinterMode,
java.io.PrintWriter)
          */
-        public void print(final PrinterMode mode, final PrintWriter printWriter) {
+        public void print(final PrinterMode mode, final PrintWriter printWriter, final boolean
isZip ) {
             final String m;
-            if ( mode == PrinterMode.HTML_BODY ) {
+            if ( !isZip && mode == PrinterMode.HTML_FRAGMENT ) {
                 m = ConsoleConstants.MODE_WEB;
-            } else if ( mode == PrinterMode.TEXT ) {
+            } else if ( !isZip && mode == PrinterMode.TEXT ) {
                 m = ConsoleConstants.MODE_TXT;
-            } else if ( mode == PrinterMode.ZIP_FILE_TEXT ) {
+            } else if (isZip && (mode == PrinterMode.TEXT || mode == PrinterMode.HTML_FRAGMENT)
) {
                 m = ConsoleConstants.MODE_ZIP;
             } else {
                 m = null;



Mime
View raw message