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/27 15:55:30 UTC
svn commit: r903666 - in
/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole:
BinaryConfigurationPrinter.java internal/misc/ConfigurationRender.java
Author: cziegeler
Date: Wed Jan 27 14:55:30 2010
New Revision: 903666
URL: http://svn.apache.org/viewvc?rev=903666&view=rev
Log:
FELIX-1993 : Enhance configuration printer support
Add new BinaryConfigurationPrinter which allows to add a set of files to the downloadable zip (POC)
Added:
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java (with props)
Modified:
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
Added: 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/BinaryConfigurationPrinter.java?rev=903666&view=auto
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java (added)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java Wed Jan 27 14:55:30 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.felix.webconsole;
+
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+
+/**
+ * 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.
+ *
+ * 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.
+ * @since 3.0
+ */
+public interface BinaryConfigurationPrinter
+ extends ConfigurationPrinter
+{
+
+ /**
+ * 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.
+ */
+ 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;
+}
Propchange: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/BinaryConfigurationPrinter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=903666&r1=903665&r2=903666&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 Wed Jan 27 14:55:30 2010
@@ -100,10 +100,11 @@
zip.setLevel( 9 );
zip.setMethod( ZipOutputStream.DEFLATED );
- ConfigurationWriter pw = new ZipConfigurationWriter( zip );
+ final ZipConfigurationWriter pw = new ZipConfigurationWriter( zip );
printConfigurationStatus( pw, ConfigurationPrinter.MODE_ZIP );
pw.flush();
+ addBinaries( pw );
zip.finish();
}
else
@@ -264,8 +265,8 @@
private void printConfigurationPrinter( final ConfigurationWriter pw,
- final ConfigurationPrinter cp,
- final String mode )
+ final ConfigurationPrinter cp,
+ final String mode )
{
pw.title( cp.getTitle() );
if ( cp instanceof ModeAwareConfigurationPrinter )
@@ -541,6 +542,35 @@
}
}
+ private void addBinaries( final ZipConfigurationWriter cf )
+ throws IOException
+ {
+ final String mode = ConfigurationPrinter.MODE_ZIP;
+ for ( Iterator cpi = getConfigurationPrinters().iterator(); cpi.hasNext(); )
+ {
+ // check if printer supports zip mode
+ final PrinterDesc desc = (PrinterDesc) cpi.next();
+ if ( desc.match(mode) )
+ {
+ // check if printer implements binary configuration printer
+ if ( desc.printer instanceof BinaryConfigurationPrinter )
+ {
+ final String[] names = ((BinaryConfigurationPrinter)desc.printer).getFilenames(mode);
+ if ( names != null )
+ {
+ for(int i = 0; i < names.length; i++)
+ {
+ final OutputStream os = cf.startFile(desc.printer.getTitle(), names[i]);
+ ((BinaryConfigurationPrinter)desc.printer).writeFile(names[i], mode, os);
+ cf.end();
+ }
+ }
+ }
+ }
+ }
+
+ }
+
private static final class PrinterDesc
{
private final String[] modes;
@@ -670,6 +700,21 @@
}
}
+ public OutputStream startFile( String title, String name)
+ {
+ final String path = MessageFormat.format( "{0,number,000}-{1}/{2}", new Object[]
+ { new Integer( counter ), title, name } );
+ ZipEntry entry = new ZipEntry( path );
+ try
+ {
+ zip.putNextEntry( entry );
+ }
+ catch ( IOException ioe )
+ {
+ // should handle
+ }
+ return zip;
+ }
public void end()
{