Reformat to Apache Felix code conventions
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1451624 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java b/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java
index 3916753..d1807cf 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java
@@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -24,16 +24,18 @@
* The <code>InventoryPrinter</code> is a service interface to be
* implemented by providers which want to hook into the display of the
* current configuration and state of the OSGi framework and application.
- *
- * A inventory printer must configure at least these three configuration properties
+ *
+ * A inventory printer must configure at least these three configuration
+ * properties
* <ul>
- * <li>{@link #CONFIG_PRINTER_MODES} - the supported modes</li>
- * <li>{@link #CONFIG_TITLE} - the printer title</li>
- * <li>{@link #CONFIG_NAME} - the printer name</li>
+ * <li>{@link #CONFIG_PRINTER_MODES} - the supported modes</li>
+ * <li>{@link #CONFIG_TITLE} - the printer title</li>
+ * <li>{@link #CONFIG_NAME} - the printer name</li>
* </ul>
- *
+ *
*/
-public interface InventoryPrinter {
+public interface InventoryPrinter
+{
/**
* The service name under which services of this class must be registered
@@ -43,9 +45,10 @@
/**
* The property defining the supported rendering modes.
- * The value of this property is either a string or a string array containing
+ * The value of this property is either a string or a string array
+ * containing
* valid names of {@link PrinterMode}.
- *
+ *
* If this property is missing or contains invalid values,
* the printer is ignored.
*/
@@ -77,19 +80,21 @@
/**
* Prints the configuration report to the given <code>printWriter</code>.
* Implementations are free to print whatever information they deem useful.
- *
- * If a printer is invoked with a mode it doesn't support ({@link #CONFIG_PRINTER_MODES})
+ *
+ * If a printer is invoked with a mode it doesn't support (
+ * {@link #CONFIG_PRINTER_MODES})
* the printer should just do/print nothing and directly return.
- *
+ *
* A printer might be used in one of two different situations: either for
* directly displaying the information to a user (like in the web console)
* or the output is included in a ZIP. The printer might want to return
* different output depending on the usage situation.
- *
+ *
* @param mode The render mode.
- * @param printWriter where to write the configuration data. It might be flushed,
- * but must not be closed.
+ * @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, boolean isZip );
+ void print(PrinterMode mode, PrintWriter printWriter, boolean isZip);
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/PrinterMode.java b/inventory/src/main/java/org/apache/felix/inventory/PrinterMode.java
index 478c4d0..dac525f 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/PrinterMode.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/PrinterMode.java
@@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -21,7 +21,8 @@
/**
* Enumeration for the different printer modes.
*/
-public final class PrinterMode {
+public final class PrinterMode
+{
// plain text
public static PrinterMode TEXT = new PrinterMode("TEXT");
@@ -34,43 +35,56 @@
private final String mode;
- private PrinterMode(final String mode) {
+ private PrinterMode(final String mode)
+ {
this.mode = mode;
}
- public static PrinterMode valueOf(final String m) {
- if ( TEXT.name().equals(m) ) {
+ public static PrinterMode valueOf(final String m)
+ {
+ if (TEXT.name().equals(m))
+ {
return TEXT;
- } else if ( HTML_FRAGMENT.name().equals(m) ) {
+ }
+ else if (HTML_FRAGMENT.name().equals(m))
+ {
return HTML_FRAGMENT;
- } else if ( JSON.name().equals(m) ) {
+ }
+ else if (JSON.name().equals(m))
+ {
return JSON;
}
return null;
}
- public String name() {
+ public String name()
+ {
return this.mode;
}
/**
* @see java.lang.Object#hashCode()
*/
- public int hashCode() {
+ public int hashCode()
+ {
return mode.hashCode();
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
- public boolean equals(Object obj) {
- if (this == obj) {
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
return true;
}
- if (obj == null) {
+ if (obj == null)
+ {
return false;
}
- if (getClass() != obj.getClass()) {
+ if (getClass() != obj.getClass())
+ {
return false;
}
final PrinterMode other = (PrinterMode) obj;
diff --git a/inventory/src/main/java/org/apache/felix/inventory/ZipAttachmentProvider.java b/inventory/src/main/java/org/apache/felix/inventory/ZipAttachmentProvider.java
index a90ad09..7fb53df 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/ZipAttachmentProvider.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/ZipAttachmentProvider.java
@@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -26,30 +26,30 @@
* If a inventory printer implements this interface, the printer
* can add additional attachments to the output of the
* configuration ZIP.
- *
+ *
* A service implementing this method must still register itself
- * as a {@link InventoryPrinter} but not as a
- * {@link ZipAttachmentProvider} service and the provider
- * should either support {@link PrinterMode.ZIP_FILE_JSON}
- * or {@link PrinterMode.ZIP_FILE_TEXT}
+ * as a {@link InventoryPrinter} but not as a {@link ZipAttachmentProvider}
+ * service and the provider
+ * should either support {@link PrinterMode.ZIP_FILE_JSON} or
+ * {@link PrinterMode.ZIP_FILE_TEXT}
*/
-public interface ZipAttachmentProvider {
+public interface ZipAttachmentProvider
+{
/**
* 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;
+ void addAttachments(final String namePrefix, final ZipOutputStream zos) throws IOException;
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/AbstractWebConsolePlugin.java b/inventory/src/main/java/org/apache/felix/inventory/impl/AbstractWebConsolePlugin.java
index 312e09f..2cb6db5 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/AbstractWebConsolePlugin.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/AbstractWebConsolePlugin.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -35,7 +35,8 @@
/**
* The web console plugin for a inventory printer.
*/
-public abstract class AbstractWebConsolePlugin extends HttpServlet {
+public abstract class AbstractWebConsolePlugin extends HttpServlet
+{
private static final long serialVersionUID = 1L;
@@ -44,25 +45,31 @@
/**
* Constructor
+ *
* @param inventoryPrinterManager The manager
*/
- AbstractWebConsolePlugin(final InventoryPrinterManagerImpl inventoryPrinterManager) {
+ AbstractWebConsolePlugin(final InventoryPrinterManagerImpl inventoryPrinterManager)
+ {
this.inventoryPrinterManager = inventoryPrinterManager;
}
protected abstract InventoryPrinterHandler getInventoryPrinterHandler();
- private void printConfigurationInventory( final ConfigurationWriter pw,
- final PrinterMode mode,
- final InventoryPrinterHandler handler )
- throws IOException {
- if ( handler == null ) {
+ private void printConfigurationInventory(final ConfigurationWriter pw, final PrinterMode mode,
+ final InventoryPrinterHandler handler) throws IOException
+ {
+ if (handler == null)
+ {
final InventoryPrinterHandler[] adapters = this.inventoryPrinterManager.getHandlers(mode);
- for(int i = 0; i < adapters.length; i++) {
+ for (int i = 0; i < adapters.length; i++)
+ {
pw.printInventory(mode, adapters[i]);
}
- } else {
- if ( handler.supports(mode) ) {
+ }
+ else
+ {
+ if (handler.supports(mode))
+ {
pw.printInventory(mode, handler);
}
}
@@ -75,10 +82,11 @@
* <p>
* This method sets the <code>Cache-Control</code>, <code>Expires</code>,
* and <code>Pragma</code> headers.
- *
+ *
* @param response The response for which to set the cache prevention
*/
- private final void setNoCache(final HttpServletResponse response) {
+ private final void setNoCache(final HttpServletResponse response)
+ {
response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
response.addHeader("Cache-Control", "no-store"); //$NON-NLS-1$ //$NON-NLS-2$
response.addHeader("Cache-Control", "must-revalidate"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -87,47 +95,54 @@
response.setHeader("Pragma", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
}
- protected void doGet(final HttpServletRequest request,
- final HttpServletResponse response)
- throws ServletException, IOException {
- this.setNoCache( response );
+ protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
+ IOException
+ {
+ this.setNoCache(response);
// full request?
final InventoryPrinterHandler handler;
- if ( request.getPathInfo().lastIndexOf('/') > 0 ) {
+ if (request.getPathInfo().lastIndexOf('/') > 0)
+ {
handler = null; // all;
- } else {
+ }
+ else
+ {
handler = this.getInventoryPrinterHandler();
- if ( handler == null ) {
- response.sendError( HttpServletResponse.SC_NOT_FOUND );
+ if (handler == null)
+ {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
- if ( request.getPathInfo().endsWith( ".txt" ) ) { //$NON-NLS-2$
- response.setContentType( "text/plain; charset=utf-8" ); //$NON-NLS-2$
- final ConfigurationWriter pw = new PlainTextConfigurationWriter( response.getWriter() );
- printConfigurationInventory( pw, PrinterMode.TEXT, handler );
+ if (request.getPathInfo().endsWith(".txt")) { //$NON-NLS-2$
+ response.setContentType("text/plain; charset=utf-8"); //$NON-NLS-2$
+ final ConfigurationWriter pw = new PlainTextConfigurationWriter(response.getWriter());
+ printConfigurationInventory(pw, PrinterMode.TEXT, handler);
pw.flush();
- } else if ( request.getPathInfo().endsWith( ".zip" ) ) { //$NON-NLS-2$
- String type = getServletContext().getMimeType( request.getPathInfo() );
- if ( type == null ) {
+ }
+ else if (request.getPathInfo().endsWith(".zip")) { //$NON-NLS-2$
+ String type = getServletContext().getMimeType(request.getPathInfo());
+ if (type == null)
+ {
type = "application/x-zip"; //$NON-NLS-2$
}
- response.setContentType( type );
+ response.setContentType(type);
- final ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
- zip.setLevel( Deflater.BEST_SPEED );
- zip.setMethod( ZipOutputStream.DEFLATED );
+ final ZipOutputStream zip = new ZipOutputStream(response.getOutputStream());
+ zip.setLevel(Deflater.BEST_SPEED);
+ zip.setMethod(ZipOutputStream.DEFLATED);
final Date now = new Date();
// create time stamp entry
- final ZipEntry entry = new ZipEntry( "timestamp.txt" ); //$NON-NLS-2$
+ final ZipEntry entry = new ZipEntry("timestamp.txt"); //$NON-NLS-2$
entry.setTime(now.getTime());
- zip.putNextEntry( entry );
+ zip.putNextEntry(entry);
final StringBuilder sb = new StringBuilder();
sb.append("Date: ");
- synchronized ( InventoryPrinterAdapter.DISPLAY_DATE_FORMAT ) {
+ synchronized (InventoryPrinterAdapter.DISPLAY_DATE_FORMAT)
+ {
sb.append(InventoryPrinterAdapter.DISPLAY_DATE_FORMAT.format(now));
}
sb.append(" (");
@@ -137,50 +152,64 @@
zip.write(sb.toString().getBytes("UTF-8"));
zip.closeEntry();
- final ZipConfigurationWriter pw = new ZipConfigurationWriter( zip );
- printConfigurationInventory( pw, PrinterMode.TEXT, handler );
- printConfigurationInventory( pw, PrinterMode.JSON, handler );
+ final ZipConfigurationWriter pw = new ZipConfigurationWriter(zip);
+ printConfigurationInventory(pw, PrinterMode.TEXT, handler);
+ printConfigurationInventory(pw, PrinterMode.JSON, handler);
zip.finish();
- } else if ( request.getPathInfo().endsWith( ".nfo" ) ) {
- if ( handler == null ) {
- response.sendError( HttpServletResponse.SC_NOT_FOUND);
+ }
+ else if (request.getPathInfo().endsWith(".nfo"))
+ {
+ if (handler == null)
+ {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
- response.setContentType( "text/html; charset=utf-8" );
+ response.setContentType("text/html; charset=utf-8");
- final HtmlConfigurationWriter pw = new HtmlConfigurationWriter( response.getWriter() );
- pw.println ( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" );
- pw.println ( " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" );
- pw.println ( "<html xmlns=\"http://www.w3.org/1999/xhtml\">" );
- pw.println ( "<head><title>dummy</title></head><body><div>" );
+ final HtmlConfigurationWriter pw = new HtmlConfigurationWriter(response.getWriter());
+ pw.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
+ pw.println(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
+ pw.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
+ pw.println("<head><title>dummy</title></head><body><div>");
- if ( handler.supports(PrinterMode.HTML_FRAGMENT) ) {
+ 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.JSON, pw, false);
- pw.enableFilter( false );
}
- pw.println( "</div></body></html>" );
+ 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.JSON, pw, false);
+ pw.enableFilter(false);
+ }
+ pw.println("</div></body></html>");
return;
- } else if ( request.getPathInfo().endsWith(".json") ) {
- if ( handler == null ) {
- response.sendError( HttpServletResponse.SC_NOT_FOUND);
+ }
+ else if (request.getPathInfo().endsWith(".json"))
+ {
+ if (handler == null)
+ {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
- response.setContentType( "application/json" ); //$NON-NLS-1$
- response.setCharacterEncoding( "UTF-8" ); //$NON-NLS-1$
+ response.setContentType("application/json"); //$NON-NLS-1$
+ response.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
final JSONConfigurationWriter jcw = new JSONConfigurationWriter(response.getWriter());
- printConfigurationInventory( jcw, PrinterMode.JSON, handler );
- } else {
- if ( handler == null ) {
- response.sendError( HttpServletResponse.SC_NOT_FOUND);
+ printConfigurationInventory(jcw, PrinterMode.JSON, handler);
+ }
+ else
+ {
+ if (handler == null)
+ {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
final HtmlConfigurationWriter pw = new HtmlConfigurationWriter(response.getWriter());
@@ -206,10 +235,11 @@
pw.println("});");
pw.println("// ]]>");
pw.println("</script>");
- pw.println( "<br/><p class=\"statline\">");
+ pw.println("<br/><p class=\"statline\">");
final Date currentTime = new Date();
- synchronized ( InventoryPrinterAdapter.DISPLAY_DATE_FORMAT ) {
+ synchronized (InventoryPrinterAdapter.DISPLAY_DATE_FORMAT)
+ {
pw.print("Date: ");
pw.println(InventoryPrinterAdapter.DISPLAY_DATE_FORMAT.format(currentTime));
}
@@ -217,22 +247,27 @@
pw.print("<button type=\"button\" class=\"downloadFullZip\" style=\"float: right; margin-right: 30px; margin-top: 5px;\">Download Full Zip</button>");
pw.print("<button type=\"button\" class=\"downloadFullTxt\" style=\"float: right; margin-right: 30px; margin-top: 5px;\">Download Full Text</button>");
- if ( handler.supports(PrinterMode.JSON) ) {
+ 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>");
}
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 ) ) {
+ 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/> </p>"); // status line
pw.print("<div>");
- if ( handler.supports(PrinterMode.HTML_FRAGMENT) ) {
+ if (handler.supports(PrinterMode.HTML_FRAGMENT))
+ {
handler.print(PrinterMode.HTML_FRAGMENT, pw, false);
- } else {
- pw.enableFilter( true );
+ }
+ else
+ {
+ pw.enableFilter(true);
handler.print(PrinterMode.TEXT, pw, false);
- pw.enableFilter( false );
+ pw.enableFilter(false);
}
pw.print("</div>");
}
@@ -241,25 +276,26 @@
/**
* Base class for all configuration writers.
*/
- private abstract static class ConfigurationWriter extends PrintWriter {
+ private abstract static class ConfigurationWriter extends PrintWriter
+ {
- ConfigurationWriter( final Writer delegatee ) {
- super( delegatee );
+ ConfigurationWriter(final Writer delegatee)
+ {
+ super(delegatee);
}
- protected void title( final String title ) throws IOException {
+ protected void title(final String title) throws IOException
+ {
// dummy implementation
}
-
- protected void end() throws IOException {
+ protected void end() throws IOException
+ {
// dummy implementation
}
- public void printInventory(
- final PrinterMode mode,
- final InventoryPrinterHandler handler)
- throws IOException {
+ public void printInventory(final PrinterMode mode, final InventoryPrinterHandler handler) throws IOException
+ {
this.title(handler.getTitle());
handler.print(mode, this, false);
this.end();
@@ -269,57 +305,68 @@
/**
* The JSON configuration writer
*/
- private static class JSONConfigurationWriter extends ConfigurationWriter {
+ private static class JSONConfigurationWriter extends ConfigurationWriter
+ {
- JSONConfigurationWriter( final Writer delegatee ) {
- super( delegatee );
+ JSONConfigurationWriter(final Writer delegatee)
+ {
+ super(delegatee);
}
}
/**
* The HTML configuration writer outputs the status as an HTML snippet.
*/
- private static class HtmlConfigurationWriter extends ConfigurationWriter {
+ private static class HtmlConfigurationWriter extends ConfigurationWriter
+ {
// whether or not to filter "<" signs in the output
private boolean doFilter;
-
- HtmlConfigurationWriter( final Writer delegatee ) {
- super( delegatee );
+ HtmlConfigurationWriter(final Writer delegatee)
+ {
+ super(delegatee);
}
-
- void enableFilter( final boolean doFilter ) {
+ void enableFilter(final boolean doFilter)
+ {
this.doFilter = doFilter;
}
// IE has an issue with white-space:pre in our case so, we write
// <br/> instead of [CR]LF to get the line break. This also works
// in other browsers.
- public void println() {
- if ( doFilter ) {
+ public void println()
+ {
+ if (doFilter)
+ {
this.write('\n'); // write <br/>
- } else {
+ }
+ else
+ {
super.println();
}
}
- // some VM implementation directly write in underlying stream, instead of
- // delegation to the write() method. So we need to override this, to make
+ // some VM implementation directly write in underlying stream, instead
+ // of
+ // delegation to the write() method. So we need to override this, to
+ // make
// sure, that everything is escaped correctly
- public void print(final String str) {
+ public void print(final String str)
+ {
final char[] chars = str.toCharArray();
write(chars, 0, chars.length);
}
-
private final char[] oneChar = new char[1];
// always delegate to write(char[], int, int) otherwise in some VM
// it cause endless cycle and StackOverflowError
- public void write(final int character) {
- synchronized (oneChar) {
+ public void write(final int character)
+ {
+ synchronized (oneChar)
+ {
oneChar[0] = (char) character;
write(oneChar, 0, 1);
}
@@ -327,8 +374,10 @@
// write the characters unmodified unless filtering is enabled in
// which case the writeFiltered(String) method is called for filtering
- public void write(char[] chars, int off, int len) {
- if (doFilter) {
+ public void write(char[] chars, int off, int len)
+ {
+ if (doFilter)
+ {
chars = this.escapeHtml(new String(chars, off, len)).toCharArray();
off = 0;
len = chars.length;
@@ -338,22 +387,26 @@
// write the string unmodified unless filtering is enabled in
// which case the writeFiltered(String) method is called for filtering
- public void write( final String string, final int off, final int len ) {
+ public void write(final String string, final int off, final int len)
+ {
write(string.toCharArray(), off, len);
}
/**
* Escapes HTML special chars like: <>&\r\n and space
- *
- *
+ *
+ *
* @param text the text to escape
* @return the escaped text
*/
- private String escapeHtml(final String text) {
+ private String escapeHtml(final String text)
+ {
final StringBuilder sb = new StringBuilder(text.length() * 4 / 3);
char ch, oldch = '_';
- for (int i = 0; i < text.length(); i++) {
- switch (ch = text.charAt(i)) {
+ for (int i = 0; i < text.length(); i++)
+ {
+ switch (ch = text.charAt(i))
+ {
case '<':
sb.append("<"); //$NON-NLS-1$
break;
@@ -368,7 +421,8 @@
break;
case '\r':
case '\n':
- if (oldch != '\r' && oldch != '\n') // don't add twice <br>
+ if (oldch != '\r' && oldch != '\n') // don't add twice
+ // <br>
sb.append("<br/>\n"); //$NON-NLS-1$
break;
default:
@@ -384,20 +438,23 @@
/**
* The plain text configuration writer outputs the status as plain text.
*/
- private static class PlainTextConfigurationWriter extends ConfigurationWriter {
+ private static class PlainTextConfigurationWriter extends ConfigurationWriter
+ {
- PlainTextConfigurationWriter( final Writer delegatee ) {
- super( delegatee );
+ PlainTextConfigurationWriter(final Writer delegatee)
+ {
+ super(delegatee);
}
- protected void title( final String title ) throws IOException {
- print( "*** " );
- print( title );
- println( ":" );
+ protected void title(final String title) throws IOException
+ {
+ print("*** ");
+ print(title);
+ println(":");
}
-
- protected void end() throws IOException {
+ protected void end() throws IOException
+ {
println();
}
}
@@ -408,37 +465,41 @@
* - json output of a inventory printers (if supported)
* - attachments from a inventory printer (if supported)
*/
- private static class ZipConfigurationWriter extends ConfigurationWriter {
+ private static class ZipConfigurationWriter extends ConfigurationWriter
+ {
private final ZipOutputStream zip;
- ZipConfigurationWriter( final ZipOutputStream zip ) {
- super( new OutputStreamWriter( zip ) );
+ ZipConfigurationWriter(final ZipOutputStream zip)
+ {
+ super(new OutputStreamWriter(zip));
this.zip = zip;
}
- public void printInventory(
- final PrinterMode mode,
- final InventoryPrinterHandler handler)
- throws IOException {
- if ( mode == PrinterMode.TEXT ) {
- final ZipEntry entry = new ZipEntry( handler.getName().concat(".txt") );
- zip.putNextEntry( entry );
+ public void printInventory(final PrinterMode mode, final InventoryPrinterHandler handler) throws IOException
+ {
+ 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 ) {
+ }
+ else if (mode == PrinterMode.JSON)
+ {
final String name = "json/".concat(handler.getName()).concat(".json");
- final ZipEntry entry = new ZipEntry( name );
- zip.putNextEntry( entry );
+ final ZipEntry entry = new ZipEntry(name);
+ zip.putNextEntry(entry);
handler.print(PrinterMode.JSON, this, true);
flush();
zip.closeEntry();
- if ( !handler.supports(PrinterMode.TEXT) ) {
+ if (!handler.supports(PrinterMode.TEXT))
+ {
handler.addAttachments(handler.getName().concat("/"), this.zip);
}
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java b/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
index 14a1b57..12b44c4 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -23,7 +23,8 @@
/**
* Activate bridges and internal manager.
*/
-public class Activator implements BundleActivator {
+public class Activator implements BundleActivator
+{
private InventoryPrinterManagerImpl printerManager;
@@ -32,20 +33,24 @@
/**
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
- public void start(final BundleContext context) throws Exception {
+ public void start(final BundleContext context) throws Exception
+ {
this.webAdapter = new WebConsoleAdapter(context);
this.printerManager = new InventoryPrinterManagerImpl(context);
-}
+ }
/**
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
- public void stop(final BundleContext context) throws Exception {
- if ( this.printerManager != null ) {
+ public void stop(final BundleContext context) throws Exception
+ {
+ if (this.printerManager != null)
+ {
this.printerManager.dispose();
this.printerManager = null;
}
- if ( this.webAdapter != null ) {
+ if (this.webAdapter != null)
+ {
this.webAdapter.dispose();
this.webAdapter = null;
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/ClassUtils.java b/inventory/src/main/java/org/apache/felix/inventory/impl/ClassUtils.java
index fca742b..cc24dc4 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/ClassUtils.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/ClassUtils.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -21,22 +21,30 @@
/**
* Utility methods for dynamic method invocations
*/
-public class ClassUtils {
+public class ClassUtils
+{
/**
* Search a method with the given name and signature.
+ *
* @return The method or <code>null</code> if not found.
*/
- public static Method searchMethod(final Class clazz, final String mName, final Class[] params) {
- try {
+ public static Method searchMethod(final Class clazz, final String mName, final Class[] params)
+ {
+ try
+ {
final Method m = clazz.getMethod(mName, params);
m.setAccessible(true);
return m;
- } catch (Throwable nsme) {
- // ignore, we catch Throwable above to not only catch NoSuchMethodException
+ }
+ catch (Throwable nsme)
+ {
+ // ignore, we catch Throwable above to not only catch
+ // NoSuchMethodException
// but also other ones like ClassDefNotFoundError etc.
}
- if ( clazz.getSuperclass() != null ) {
+ if (clazz.getSuperclass() != null)
+ {
// try super class
return searchMethod(clazz.getSuperclass(), mName, params);
}
@@ -45,12 +53,18 @@
/**
* Invoke the method on the object with the arguments.
- * @return The result of the method invocation or <code>null</code> if an exception occurs.
+ *
+ * @return The result of the method invocation or <code>null</code> if an
+ * exception occurs.
*/
- public static Object invoke(final Object obj, final Method m, final Object[] args) {
- try {
+ public static Object invoke(final Object obj, final Method m, final Object[] args)
+ {
+ try
+ {
return m.invoke(obj, args);
- } catch (final Throwable e) {
+ }
+ catch (final Throwable e)
+ {
// ignore
}
return null;
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/DefaultWebConsolePlugin.java b/inventory/src/main/java/org/apache/felix/inventory/impl/DefaultWebConsolePlugin.java
index 48d5536..f0e3424 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/DefaultWebConsolePlugin.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/DefaultWebConsolePlugin.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -32,88 +32,103 @@
/**
* The web console plugin for a inventory printer.
*/
-public class DefaultWebConsolePlugin extends AbstractWebConsolePlugin implements InventoryPrinterHandler {
+public class DefaultWebConsolePlugin extends AbstractWebConsolePlugin implements InventoryPrinterHandler
+{
private static final long serialVersionUID = 1L;
/**
* Constructor
+ *
* @param inventoryPrinterAdapter The adapter
*/
- DefaultWebConsolePlugin(final InventoryPrinterManagerImpl inventoryPrinterManager) {
+ DefaultWebConsolePlugin(final InventoryPrinterManagerImpl inventoryPrinterManager)
+ {
super(inventoryPrinterManager);
}
- protected InventoryPrinterHandler getInventoryPrinterHandler() {
+ protected InventoryPrinterHandler getInventoryPrinterHandler()
+ {
return this;
}
/**
* @see org.apache.felix.inventory.impl.InventoryPrinterHandler#getTitle()
*/
- public String getTitle() {
+ public String getTitle()
+ {
return "Overview";
}
/**
* @see org.apache.felix.inventory.impl.InventoryPrinterHandler#getName()
*/
- public String getName() {
+ public String getName()
+ {
return "config";
}
/**
* @see org.apache.felix.inventory..implInventoryPrinterHandler#getModes()
*/
- public PrinterMode[] getModes() {
- return new PrinterMode[] {PrinterMode.TEXT};
+ public PrinterMode[] getModes()
+ {
+ return new PrinterMode[]
+ { PrinterMode.TEXT };
}
/**
* @see org.apache.felix.inventory.impl.InventoryPrinterHandler#supports(org.apache.felix.inventory.PrinterMode)
*/
- public boolean supports(final PrinterMode mode) {
+ public boolean supports(final PrinterMode mode)
+ {
return mode == PrinterMode.TEXT;
}
/**
- * @see org.apache.felix.inventory.InventoryPrinter#print(org.apache.felix.inventory.PrinterMode, java.io.PrintWriter, boolean)
+ * @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, final boolean isZip) {
+ 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));
printWriter.println(" printer(s).");
printWriter.println();
- for(int i=0; i<handlers.length; i++) {
+ for (int i = 0; i < handlers.length; i++)
+ {
printWriter.println(handlers[i].getTitle());
}
}
/**
- * @see org.apache.felix.inventory.ZipAttachmentProvider#addAttachments(java.lang.String, java.util.zip.ZipOutputStream)
+ * @see org.apache.felix.inventory.ZipAttachmentProvider#addAttachments(java.lang.String,
+ * java.util.zip.ZipOutputStream)
*/
- public void addAttachments(String namePrefix, ZipOutputStream zos)
- throws IOException {
+ public void addAttachments(String namePrefix, ZipOutputStream zos) throws IOException
+ {
// no attachments support
}
- public static ServiceRegistration register(final BundleContext context,
- final InventoryPrinterManagerImpl manager) {
+ public static ServiceRegistration register(final BundleContext context, final InventoryPrinterManagerImpl manager)
+ {
final DefaultWebConsolePlugin dwcp = new DefaultWebConsolePlugin(manager);
final Dictionary props = new Hashtable();
props.put(ConsoleConstants.PLUGIN_LABEL, dwcp.getName());
props.put(ConsoleConstants.PLUGIN_TITLE, dwcp.getTitle());
props.put(ConsoleConstants.PLUGIN_CATEGORY, ConsoleConstants.WEB_CONSOLE_CATEGORY);
- return context.registerService(ConsoleConstants.INTERFACE_SERVLET, new ServiceFactory() {
+ return context.registerService(ConsoleConstants.INTERFACE_SERVLET, new ServiceFactory()
+ {
- public void ungetService(final Bundle bundle, final ServiceRegistration registration,
- final Object service) {
+ public void ungetService(final Bundle bundle, final ServiceRegistration registration, final Object service)
+ {
// nothing to do
}
- public Object getService(final Bundle bundle, final ServiceRegistration registration) {
+ public Object getService(final Bundle bundle, final ServiceRegistration registration)
+ {
return dwcp;
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
index a896647..12f6c68 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -32,56 +32,61 @@
/**
* Helper class for a inventory printer.
- *
+ *
* The adapter simplifies accessing and working with the inventory printer.
*/
-public class InventoryPrinterAdapter implements InventoryPrinterHandler, Comparable {
+public class InventoryPrinterAdapter implements InventoryPrinterHandler, Comparable
+{
/**
* Formatter pattern to render the current time of inventory generation.
*/
- static final DateFormat DISPLAY_DATE_FORMAT = DateFormat.getDateTimeInstance( DateFormat.LONG,
- DateFormat.LONG, Locale.US );
+ static final DateFormat DISPLAY_DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG,
+ Locale.US);
/**
- * Create a new adapter if the provided service is either a printer or provides
+ * Create a new adapter if the provided service is either a printer or
+ * provides
* the print method.
+ *
* @return An adapter or <code>null</code> if the method is missing.
*/
public static InventoryPrinterAdapter createAdapter(final InventoryPrinterDescription description,
- final Object service) {
+ final Object service)
+ {
Method printMethod = null;
- if ( !(service instanceof InventoryPrinter) ) {
+ if (!(service instanceof InventoryPrinter))
+ {
// print(String, PrintWriter)
- printMethod = ClassUtils.searchMethod(service.getClass(), "print",
- new Class[] {String.class, PrintWriter.class, Boolean.class});
- if ( printMethod == null ) {
+ printMethod = ClassUtils.searchMethod(service.getClass(), "print", new Class[]
+ { String.class, PrintWriter.class, Boolean.class });
+ if (printMethod == null)
+ {
return null;
}
}
Method attachmentMethod = null;
- if ( !(service instanceof ZipAttachmentProvider) ) {
+ if (!(service instanceof ZipAttachmentProvider))
+ {
// addAttachments()
- attachmentMethod = ClassUtils.searchMethod(service.getClass(), "addAttachments",
- new Class[] {String.class, ZipOutputStream.class});
+ attachmentMethod = ClassUtils.searchMethod(service.getClass(), "addAttachments", new Class[]
+ { String.class, ZipOutputStream.class });
}
- return new InventoryPrinterAdapter(
- description,
- service,
- printMethod,
- attachmentMethod);
+ return new InventoryPrinterAdapter(description, service, printMethod, attachmentMethod);
}
/**
* Comparator for adapters based on the service ranking.
*/
- public static final Comparator RANKING_COMPARATOR = new Comparator() {
+ public static final Comparator RANKING_COMPARATOR = new Comparator()
+ {
- public int compare(final Object o1, final Object o2) {
- return ((InventoryPrinterAdapter)o1).description.compareTo(((InventoryPrinterAdapter)o2).description);
+ public int compare(final Object o1, final Object o2)
+ {
+ return ((InventoryPrinterAdapter) o1).description.compareTo(((InventoryPrinterAdapter) o2).description);
}
};
@@ -102,27 +107,31 @@
/**
* Constructor.
*/
- public InventoryPrinterAdapter( final InventoryPrinterDescription description,
- final Object printer,
- final Method printMethod,
- final Method attachmentMethod) {
+ public InventoryPrinterAdapter(final InventoryPrinterDescription description, final Object printer,
+ final Method printMethod, final Method attachmentMethod)
+ {
this.description = description;
this.printer = printer;
this.printMethod = printMethod;
this.attachmentMethod = attachmentMethod;
}
- public void registerConsole(final BundleContext context, final InventoryPrinterManagerImpl manager) {
- if ( this.registration == null ) {
+ public void registerConsole(final BundleContext context, final InventoryPrinterManagerImpl manager)
+ {
+ if (this.registration == null)
+ {
final Object value = this.description.getServiceReference().getProperty(InventoryPrinter.CONFIG_WEBCONSOLE);
- if ( value == null || !"false".equalsIgnoreCase(value.toString()) ) {
+ if (value == null || !"false".equalsIgnoreCase(value.toString()))
+ {
this.registration = WebConsolePlugin.register(context, manager, this.description);
}
}
}
- public void unregisterConsole() {
- if ( this.registration != null ) {
+ public void unregisterConsole()
+ {
+ if (this.registration != null)
+ {
this.registration.unregister();
this.registration = null;
}
@@ -131,43 +140,54 @@
/**
* The human readable title for the inventory printer.
*/
- public String getTitle() {
+ public String getTitle()
+ {
return this.description.getTitle();
}
/**
* The unique name of the printer.
*/
- public String getName() {
+ public String getName()
+ {
return this.description.getName();
}
/**
* All supported modes.
*/
- public PrinterMode[] getModes() {
+ public PrinterMode[] getModes()
+ {
return this.description.getModes();
}
/**
- * @see org.apache.felix.inventory.ZipAttachmentProvider#addAttachments(java.lang.String, java.util.zip.ZipOutputStream)
+ * @see org.apache.felix.inventory.ZipAttachmentProvider#addAttachments(java.lang.String,
+ * java.util.zip.ZipOutputStream)
*/
- public void addAttachments(final String namePrefix, final ZipOutputStream zos)
- throws IOException {
+ public void addAttachments(final String namePrefix, final ZipOutputStream zos) throws IOException
+ {
// check if printer implements ZipAttachmentProvider
- if ( printer instanceof ZipAttachmentProvider ) {
- ((ZipAttachmentProvider)printer).addAttachments(namePrefix, zos);
- } else if ( this.attachmentMethod != null ) {
- ClassUtils.invoke(this.printer, this.attachmentMethod, new Object[] {namePrefix, zos});
+ if (printer instanceof ZipAttachmentProvider)
+ {
+ ((ZipAttachmentProvider) printer).addAttachments(namePrefix, zos);
+ }
+ else if (this.attachmentMethod != null)
+ {
+ ClassUtils.invoke(this.printer, this.attachmentMethod, new Object[]
+ { namePrefix, zos });
}
}
/**
* Whether the printer supports this mode.
*/
- public boolean supports(final PrinterMode mode) {
- for(int i=0; i<this.description.getModes().length; i++) {
- if ( this.description.getModes()[i] == mode ) {
+ public boolean supports(final PrinterMode mode)
+ {
+ for (int i = 0; i < this.description.getModes().length; i++)
+ {
+ if (this.description.getModes()[i] == mode)
+ {
return true;
}
}
@@ -175,16 +195,21 @@
}
/**
- * @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)
*/
- public void print(final PrinterMode mode,
- final PrintWriter printWriter,
- final boolean isZip) {
- if ( this.supports(mode) ) {
- if ( this.printer instanceof InventoryPrinter ) {
- ((InventoryPrinter)this.printer).print(mode, printWriter, isZip);
- } else {
- ClassUtils.invoke(this.printer, this.printMethod, new Object[] {mode.toString(), printWriter, Boolean.valueOf(isZip)});
+ public void print(final PrinterMode mode, final PrintWriter printWriter, final boolean isZip)
+ {
+ if (this.supports(mode))
+ {
+ if (this.printer instanceof InventoryPrinter)
+ {
+ ((InventoryPrinter) this.printer).print(mode, printWriter, isZip);
+ }
+ else
+ {
+ ClassUtils.invoke(this.printer, this.printMethod, new Object[]
+ { mode.toString(), printWriter, Boolean.valueOf(isZip) });
}
}
}
@@ -192,18 +217,21 @@
/**
* @see java.lang.Object#toString()
*/
- public String toString() {
+ public String toString()
+ {
return printer.getClass() + "(" + super.toString() + ")";
}
/**
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
- public int compareTo(final Object spa) {
- return this.description.getSortKey().compareTo(((InventoryPrinterAdapter)spa).description.getSortKey());
+ public int compareTo(final Object spa)
+ {
+ return this.description.getSortKey().compareTo(((InventoryPrinterAdapter) spa).description.getSortKey());
}
- public InventoryPrinterDescription getDescription() {
+ public InventoryPrinterDescription getDescription()
+ {
return this.description;
}
- }
+}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
index 8b20eff..a563ddf 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -25,7 +25,8 @@
/**
* Helper class for a configuration printer.
*/
-public class InventoryPrinterDescription implements Comparable {
+public class InventoryPrinterDescription implements Comparable
+{
private final ServiceReference reference;
@@ -37,95 +38,128 @@
private final String sortKey;
- public InventoryPrinterDescription(final ServiceReference ref) {
+ public InventoryPrinterDescription(final ServiceReference ref)
+ {
this.reference = ref;
// check modes
final Object modesCfg = ref.getProperty(InventoryPrinter.CONFIG_PRINTER_MODES);
- if ( modesCfg instanceof String ) {
- final PrinterMode mode = PrinterMode.valueOf((String)modesCfg);
- if ( mode != null ) {
- this.modes = new PrinterMode[] {mode};
- } else {
+ if (modesCfg instanceof String)
+ {
+ 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;
+ }
+ else if (modesCfg instanceof String[])
+ {
+ final String[] modesCfgArray = (String[]) modesCfg;
final PrinterMode[] pModes = new PrinterMode[modesCfgArray.length];
boolean invalid = false;
- for(int i=0; i<modesCfgArray.length;i++) {
+ for (int i = 0; i < modesCfgArray.length; i++)
+ {
pModes[i] = PrinterMode.valueOf(modesCfgArray[i]);
- if ( pModes[i] == null ) {
+ if (pModes[i] == null)
+ {
invalid = true;
}
}
- if ( invalid ) {
+ if (invalid)
+ {
this.modes = null;
- } else {
+ }
+ else
+ {
this.modes = pModes;
}
- } else {
+ }
+ else
+ {
this.modes = null;
}
// check name
- if ( ref.getProperty(InventoryPrinter.CONFIG_NAME) != null ) {
+ if (ref.getProperty(InventoryPrinter.CONFIG_NAME) != null)
+ {
this.name = ref.getProperty(InventoryPrinter.CONFIG_NAME).toString();
- } else {
+ }
+ else
+ {
this.name = null;
}
// check title
- if ( ref.getProperty(InventoryPrinter.CONFIG_TITLE) != null ) {
+ if (ref.getProperty(InventoryPrinter.CONFIG_TITLE) != null)
+ {
this.title = ref.getProperty(InventoryPrinter.CONFIG_TITLE).toString();
- if ( this.title.startsWith("%") ) {
+ if (this.title.startsWith("%"))
+ {
this.sortKey = this.title.substring(1);
- } else {
+ }
+ else
+ {
this.sortKey = this.title;
}
- } else {
+ }
+ else
+ {
this.title = null;
this.sortKey = null;
}
}
- public String getTitle() {
+ public String getTitle()
+ {
return this.title;
}
- public String getSortKey() {
+ public String getSortKey()
+ {
return this.sortKey;
}
- public String getName() {
+ public String getName()
+ {
return this.name;
}
- public PrinterMode[] getModes() {
+ public PrinterMode[] getModes()
+ {
return this.modes;
}
- public ServiceReference getServiceReference() {
+ public ServiceReference getServiceReference()
+ {
return this.reference;
}
/**
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
- public int compareTo(final Object spa) {
- return this.reference.compareTo(((InventoryPrinterDescription)spa).reference);
+ public int compareTo(final Object spa)
+ {
+ return this.reference.compareTo(((InventoryPrinterDescription) spa).reference);
}
- public boolean equals(final Object obj) {
+ public boolean equals(final Object obj)
+ {
return this.reference.equals(obj);
}
- public int hashCode() {
+ public int hashCode()
+ {
return this.reference.hashCode();
}
- public String toString() {
- return "InventoryPrinterDescription [title=" + title + ", name=" + name
- + ", modes=" + Arrays.toString(modes) + ", sortKey=" + sortKey + "]";
+ public String toString()
+ {
+ return "InventoryPrinterDescription [title=" + title + ", name=" + name + ", modes=" + Arrays.toString(modes)
+ + ", sortKey=" + sortKey + "]";
}
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterHandler.java b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterHandler.java
index 3da5c16..b630b6e 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterHandler.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterHandler.java
@@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -22,15 +22,15 @@
import org.apache.felix.inventory.PrinterMode;
import org.apache.felix.inventory.ZipAttachmentProvider;
-
/**
* The inventory printer handler can be used by clients to access
* a inventory printer.
- *
+ *
* For clients using inventory printers, a handler simplifies accessing and
* working with the inventory printer.
*/
-public interface InventoryPrinterHandler extends InventoryPrinter, ZipAttachmentProvider {
+public interface InventoryPrinterHandler extends InventoryPrinter, ZipAttachmentProvider
+{
/** The unique name of the printer. */
String getName();
@@ -42,5 +42,5 @@
PrinterMode[] getModes();
/** Whether the printer supports this mode. */
- boolean supports( final PrinterMode mode );
+ boolean supports(final PrinterMode mode);
}
\ No newline at end of file
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
index 2335221..df3f48a 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -16,7 +16,6 @@
*/
package org.apache.felix.inventory.impl;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -39,24 +38,27 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* The manager keeps track of all inventory printers and maintains them
* based on their name. If more than one printer with the same name
* is registered, the one with highest service ranking is used.
*/
-public class InventoryPrinterManagerImpl implements ServiceTrackerCustomizer {
+public class InventoryPrinterManagerImpl implements ServiceTrackerCustomizer
+{
/** Logger. */
private final Logger logger = LoggerFactory.getLogger(this.getClass());
- /** Bundle Context .*/
+ /** Bundle Context . */
private final BundleContext bundleContext;
/** Service tracker for Inventory printers. */
private final ServiceTracker cfgPrinterTracker;
- /** All adapters mapped by their name. Type of the map: String, List<InventoryPrinterAdapter> */
+ /**
+ * All adapters mapped by their name. Type of the map: String,
+ * List<InventoryPrinterAdapter>
+ */
private final Map allAdapters = new HashMap();
/** Used adapters. Type of the set: InventoryPrinterAdapter */
@@ -67,16 +69,17 @@
/**
* Create the inventory printer manager
+ *
* @param btx Bundle Context
- * @throws InvalidSyntaxException Should only happen if we have an error in the code
+ * @throws InvalidSyntaxException Should only happen if we have an error in
+ * the code
*/
- public InventoryPrinterManagerImpl(final BundleContext btx) throws InvalidSyntaxException {
+ public InventoryPrinterManagerImpl(final BundleContext btx) throws InvalidSyntaxException
+ {
this.bundleContext = btx;
- this.cfgPrinterTracker = new ServiceTracker( this.bundleContext,
- this.bundleContext.createFilter("(&(" + InventoryPrinter.CONFIG_PRINTER_MODES + "=*)"
- + "(" + InventoryPrinter.CONFIG_NAME + "=*)"
- + "(" + InventoryPrinter.CONFIG_TITLE + "=*))"),
- this );
+ this.cfgPrinterTracker = new ServiceTracker(this.bundleContext, this.bundleContext.createFilter("(&("
+ + InventoryPrinter.CONFIG_PRINTER_MODES + "=*)" + "(" + InventoryPrinter.CONFIG_NAME + "=*)" + "("
+ + InventoryPrinter.CONFIG_TITLE + "=*))"), this);
this.cfgPrinterTracker.open();
this.pluginRegistration = DefaultWebConsolePlugin.register(btx, this);
@@ -85,12 +88,15 @@
/**
* Dispose this service
*/
- public void dispose() {
- if ( this.pluginRegistration != null ) {
+ public void dispose()
+ {
+ if (this.pluginRegistration != null)
+ {
this.pluginRegistration.unregister();
}
this.cfgPrinterTracker.close();
- synchronized ( this.allAdapters ) {
+ synchronized (this.allAdapters)
+ {
this.allAdapters.clear();
}
this.usedAdapters.clear();
@@ -99,117 +105,151 @@
/**
* @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
*/
- public Object addingService(final ServiceReference reference) {
+ public Object addingService(final ServiceReference reference)
+ {
final Object obj = this.bundleContext.getService(reference);
- if ( obj != null ) {
+ if (obj != null)
+ {
this.addService(reference, obj);
}
return obj;
}
/**
- * @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference, java.lang.Object)
+ * @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference,
+ * java.lang.Object)
*/
- public void modifiedService(final ServiceReference reference, final Object service) {
+ public void modifiedService(final ServiceReference reference, final Object service)
+ {
this.removeService(reference);
this.addService(reference, service);
}
- private void addService(final ServiceReference reference, final Object obj) {
+ private void addService(final ServiceReference reference, final Object obj)
+ {
final InventoryPrinterDescription desc = new InventoryPrinterDescription(reference);
boolean valid = true;
- if ( desc.getModes() == null ) {
+ if (desc.getModes() == null)
+ {
logger.info("Ignoring inventory printer - printer modes configuration is missing: {}", reference);
valid = false;
}
- if ( desc.getName() == null ) {
+ if (desc.getName() == null)
+ {
logger.info("Ignoring inventory printer - name configuration is missing: {}", reference);
valid = false;
}
- if ( desc.getTitle() == null ) {
+ if (desc.getTitle() == null)
+ {
logger.info("Ignoring inventory printer - title configuration is missing: {}", reference);
valid = false;
}
- if ( valid ) {
+ if (valid)
+ {
final InventoryPrinterAdapter adapter = InventoryPrinterAdapter.createAdapter(desc, obj);
- if ( adapter == null ) {
+ if (adapter == null)
+ {
logger.info("Ignoring inventory printer - printer method is missing: {}", reference);
- } else {
+ }
+ else
+ {
this.addAdapter(adapter);
}
}
}
- private void addAdapter(final InventoryPrinterAdapter adapter) {
+ private void addAdapter(final InventoryPrinterAdapter adapter)
+ {
InventoryPrinterAdapter removeAdapter = null;
InventoryPrinterAdapter addAdapter = null;
final String key = adapter.getName();
- synchronized ( this.allAdapters ) {
+ synchronized (this.allAdapters)
+ {
List list = (List) this.allAdapters.get(key);
final InventoryPrinterAdapter first;
- if ( list == null ) {
+ if (list == null)
+ {
list = new LinkedList();
this.allAdapters.put(key, list);
first = null;
- } else {
+ }
+ else
+ {
first = (InventoryPrinterAdapter) list.get(0);
}
list.add(adapter);
Collections.sort(list, InventoryPrinterAdapter.RANKING_COMPARATOR);
- if ( first != null ) {
- if ( first != list.get(0) ) {
+ if (first != null)
+ {
+ if (first != list.get(0))
+ {
// update
removeAdapter = first;
addAdapter = adapter;
}
- } else {
+ }
+ else
+ {
// add
addAdapter = adapter;
}
}
- if ( removeAdapter != null ) {
+ if (removeAdapter != null)
+ {
final Iterator i = this.usedAdapters.iterator();
- while ( i.hasNext() ) {
- if ( i.next() == removeAdapter ) {
+ while (i.hasNext())
+ {
+ if (i.next() == removeAdapter)
+ {
i.remove();
break;
}
}
removeAdapter.unregisterConsole();
}
- if ( addAdapter != null ) {
+ if (addAdapter != null)
+ {
this.usedAdapters.add(addAdapter);
addAdapter.registerConsole(this.bundleContext, this);
}
}
/**
- * @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference, java.lang.Object)
+ * @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference,
+ * java.lang.Object)
*/
- public void removedService(final ServiceReference reference, final Object service) {
+ public void removedService(final ServiceReference reference, final Object service)
+ {
this.removeService(reference);
this.bundleContext.ungetService(reference);
}
- private void removeService(final ServiceReference reference) {
- synchronized ( this.allAdapters ) {
+ private void removeService(final ServiceReference reference)
+ {
+ synchronized (this.allAdapters)
+ {
final Iterator i = this.allAdapters.entrySet().iterator();
- while ( i.hasNext() ) {
+ while (i.hasNext())
+ {
final Map.Entry entry = (Entry) i.next();
final Iterator iter = ((List) entry.getValue()).iterator();
boolean removed = false;
- while ( iter.hasNext() ) {
+ while (iter.hasNext())
+ {
final InventoryPrinterAdapter adapter = (InventoryPrinterAdapter) iter.next();
- if ( adapter.getDescription().getServiceReference().compareTo(reference) == 0 ) {
+ if (adapter.getDescription().getServiceReference().compareTo(reference) == 0)
+ {
iter.remove();
removed = true;
break;
}
}
- if ( removed ) {
- if ( ((List)entry.getValue()).size() == 0 ) {
+ if (removed)
+ {
+ if (((List) entry.getValue()).size() == 0)
+ {
i.remove();
}
break;
@@ -217,9 +257,11 @@
}
}
final Iterator iter = this.usedAdapters.iterator();
- while ( iter.hasNext() ) {
+ while (iter.hasNext())
+ {
final InventoryPrinterAdapter adapter = (InventoryPrinterAdapter) iter.next();
- if ( adapter.getDescription().getServiceReference().compareTo(reference) == 0 ) {
+ if (adapter.getDescription().getServiceReference().compareTo(reference) == 0)
+ {
iter.remove();
adapter.unregisterConsole();
break;
@@ -229,22 +271,29 @@
/**
* Get all inventory printer handlers.
+ *
* @return A list of handlers - might be empty.
*/
- public InventoryPrinterHandler[] getAllHandlers() {
- return (InventoryPrinterHandler[]) this.usedAdapters.toArray(new InventoryPrinterHandler[this.usedAdapters.size()]);
+ public InventoryPrinterHandler[] getAllHandlers()
+ {
+ return (InventoryPrinterHandler[]) this.usedAdapters.toArray(new InventoryPrinterHandler[this.usedAdapters
+ .size()]);
}
/**
* Get all handlers supporting the mode.
+ *
* @return A list of handlers - might be empty.
*/
- public InventoryPrinterHandler[] getHandlers(final PrinterMode mode) {
+ public InventoryPrinterHandler[] getHandlers(final PrinterMode mode)
+ {
final List result = new ArrayList();
final Iterator i = this.usedAdapters.iterator();
- while ( i .hasNext() ) {
+ while (i.hasNext())
+ {
final InventoryPrinterAdapter printer = (InventoryPrinterAdapter) i.next();
- if ( printer.supports(mode) ) {
+ if (printer.supports(mode))
+ {
result.add(printer);
}
}
@@ -253,13 +302,17 @@
/**
* Return a handler for the unique name.
+ *
* @return The corresponding handler or <code>null</code>.
*/
- public InventoryPrinterHandler getHandler(final String name) {
+ public InventoryPrinterHandler getHandler(final String name)
+ {
final Iterator i = this.usedAdapters.iterator();
- while ( i .hasNext() ) {
+ while (i.hasNext())
+ {
final InventoryPrinterAdapter printer = (InventoryPrinterAdapter) i.next();
- if ( name.equals(printer.getName()) ) {
+ if (name.equals(printer.getName()))
+ {
return printer;
}
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/WebConsolePlugin.java b/inventory/src/main/java/org/apache/felix/inventory/impl/WebConsolePlugin.java
index 7740c90..dfbc8b1 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/WebConsolePlugin.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/WebConsolePlugin.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -28,7 +28,8 @@
/**
* The web console plugin for a inventory printer.
*/
-public class WebConsolePlugin extends AbstractWebConsolePlugin {
+public class WebConsolePlugin extends AbstractWebConsolePlugin
+{
private static final long serialVersionUID = 1L;
@@ -37,35 +38,38 @@
/**
* Constructor
+ *
* @param inventoryPrinterManager The inventory printer manager.
* @param printerName The name of the printer this plugin is displaying.
*/
- WebConsolePlugin(final InventoryPrinterManagerImpl inventoryPrinterManager,
- final String printerName) {
+ WebConsolePlugin(final InventoryPrinterManagerImpl inventoryPrinterManager, final String printerName)
+ {
super(inventoryPrinterManager);
this.printerName = printerName;
}
- protected InventoryPrinterHandler getInventoryPrinterHandler() {
+ protected InventoryPrinterHandler getInventoryPrinterHandler()
+ {
return this.inventoryPrinterManager.getHandler(this.printerName);
}
- public static ServiceRegistration register(
- final BundleContext context,
- final InventoryPrinterManagerImpl manager,
- final InventoryPrinterDescription desc) {
+ public static ServiceRegistration register(final BundleContext context, final InventoryPrinterManagerImpl manager,
+ final InventoryPrinterDescription desc)
+ {
final Dictionary props = new Hashtable();
props.put(ConsoleConstants.PLUGIN_LABEL, "status-" + desc.getName());
props.put(ConsoleConstants.PLUGIN_TITLE, desc.getTitle());
props.put(ConsoleConstants.PLUGIN_CATEGORY, ConsoleConstants.WEB_CONSOLE_CATEGORY);
- return context.registerService(ConsoleConstants.INTERFACE_SERVLET, new ServiceFactory() {
+ return context.registerService(ConsoleConstants.INTERFACE_SERVLET, new ServiceFactory()
+ {
- public void ungetService(final Bundle bundle, final ServiceRegistration registration,
- final Object service) {
+ public void ungetService(final Bundle bundle, final ServiceRegistration registration, final Object service)
+ {
// nothing to do
}
- public Object getService(final Bundle bundle, final ServiceRegistration registration) {
+ public Object getService(final Bundle bundle, final ServiceRegistration registration)
+ {
return new WebConsolePlugin(manager, desc.getName());
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
index 01c9559..fad6d6c 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -31,7 +31,8 @@
/**
* Helper class for a configuration printer.
*/
-public class ConfigurationPrinterAdapter {
+public class ConfigurationPrinterAdapter
+{
private final Object printer;
public String title;
@@ -42,24 +43,30 @@
private final Method attachmentMethod;
private static final List CUSTOM_MODES = new ArrayList();
- static {
- CUSTOM_MODES.add( ConsoleConstants.MODE_TXT);
- CUSTOM_MODES.add( ConsoleConstants.MODE_WEB );
- CUSTOM_MODES.add( ConsoleConstants.MODE_ZIP );
+ static
+ {
+ CUSTOM_MODES.add(ConsoleConstants.MODE_TXT);
+ CUSTOM_MODES.add(ConsoleConstants.MODE_WEB);
+ CUSTOM_MODES.add(ConsoleConstants.MODE_ZIP);
}
/**
* Check whether the class implements the configuration printer.
- * This is done manually to avoid having the configuration printer class available.
+ * This is done manually to avoid having the configuration printer class
+ * available.
*/
- private static boolean isConfigurationPrinter(final Class clazz) {
+ private static boolean isConfigurationPrinter(final Class clazz)
+ {
final Class[] interf = clazz.getInterfaces();
- for(int i=0; i<interf.length; i++) {
- if ( interf[i].getName().equals(ConsoleConstants.INTERFACE_CONFIGURATION_PRINTER) ) {
+ for (int i = 0; i < interf.length; i++)
+ {
+ if (interf[i].getName().equals(ConsoleConstants.INTERFACE_CONFIGURATION_PRINTER))
+ {
return true;
}
}
- if ( clazz.getSuperclass() != null ) {
+ if (clazz.getSuperclass() != null)
+ {
return isConfigurationPrinter(clazz.getSuperclass());
}
return false;
@@ -68,107 +75,127 @@
/**
* Try to create a new configuration printer adapter.
*/
- public static ConfigurationPrinterAdapter createAdapter(
- final Object service,
- final ServiceReference ref) {
+ public static ConfigurationPrinterAdapter createAdapter(final Object service, final ServiceReference ref)
+ {
String title;
Object modes = null;
- if ( isConfigurationPrinter(service.getClass()) ) {
+ if (isConfigurationPrinter(service.getClass()))
+ {
modes = ref.getProperty(ConsoleConstants.CONFIG_PRINTER_MODES);
- if ( modes == null ) {
- modes = ref.getProperty( ConsoleConstants.PROPERTY_MODES );
+ if (modes == null)
+ {
+ modes = ref.getProperty(ConsoleConstants.PROPERTY_MODES);
}
final Method titleMethod = ClassUtils.searchMethod(service.getClass(), "getTitle", null);
- if ( titleMethod == null ) {
+ if (titleMethod == null)
+ {
return null;
}
- title = (String)ClassUtils.invoke(service, titleMethod, null);
- } else {
- modes = ref.getProperty( ConsoleConstants.CONFIG_PRINTER_MODES );
- title = (String)ref.getProperty( ConsoleConstants.PLUGIN_TITLE );
+ title = (String) ClassUtils.invoke(service, titleMethod, null);
+ }
+ else
+ {
+ modes = ref.getProperty(ConsoleConstants.CONFIG_PRINTER_MODES);
+ title = (String) ref.getProperty(ConsoleConstants.PLUGIN_TITLE);
}
Object cfgPrinter = null;
Method printMethod = null;
// first: printConfiguration(PrintWriter, String)
- final Method method2Params = ClassUtils.searchMethod(service.getClass(), "printConfiguration",
- new Class[] {PrintWriter.class, String.class});
- if ( method2Params != null ) {
+ final Method method2Params = ClassUtils.searchMethod(service.getClass(), "printConfiguration", new Class[]
+ { PrintWriter.class, String.class });
+ if (method2Params != null)
+ {
cfgPrinter = service;
printMethod = method2Params;
}
- if ( cfgPrinter == null ) {
+ if (cfgPrinter == null)
+ {
// second: printConfiguration(PrintWriter)
- final Method method1Params = ClassUtils.searchMethod(service.getClass(), "printConfiguration",
- new Class[] {PrintWriter.class});
- if ( method1Params != null ) {
+ final Method method1Params = ClassUtils.searchMethod(service.getClass(), "printConfiguration", new Class[]
+ { PrintWriter.class });
+ if (method1Params != null)
+ {
cfgPrinter = service;
printMethod = method1Params;
}
}
- if ( cfgPrinter != null ) {
- final Object label = ref.getProperty( ConsoleConstants.PLUGIN_LABEL );
+ if (cfgPrinter != null)
+ {
+ final Object label = ref.getProperty(ConsoleConstants.PLUGIN_LABEL);
// check escaping
boolean webUnescaped;
- Object ehObj = ref.getProperty( ConsoleConstants.CONFIG_PRINTER_WEB_UNESCAPED );
- if ( ehObj instanceof Boolean ) {
- webUnescaped = ( ( Boolean ) ehObj ).booleanValue();
- } else if ( ehObj instanceof String ) {
- webUnescaped = Boolean.valueOf( ( String ) ehObj ).booleanValue();
- } else {
+ Object ehObj = ref.getProperty(ConsoleConstants.CONFIG_PRINTER_WEB_UNESCAPED);
+ if (ehObj instanceof Boolean)
+ {
+ webUnescaped = ((Boolean) ehObj).booleanValue();
+ }
+ else if (ehObj instanceof String)
+ {
+ webUnescaped = Boolean.valueOf((String) ehObj).booleanValue();
+ }
+ else
+ {
webUnescaped = false;
}
final String[] modesArray;
// check modes
- if ( modes == null || !( modes instanceof String || modes instanceof String[] ) ) {
+ if (modes == null || !(modes instanceof String || modes instanceof String[]))
+ {
modesArray = null;
- } else {
- if ( modes instanceof String ) {
- if ( CUSTOM_MODES.contains(modes) ) {
- modesArray = new String[] {modes.toString()};
- } else {
+ }
+ else
+ {
+ if (modes instanceof String)
+ {
+ if (CUSTOM_MODES.contains(modes))
+ {
+ modesArray = new String[]
+ { modes.toString() };
+ }
+ else
+ {
modesArray = null;
}
- } else {
- final String[] values = (String[])modes;
+ }
+ else
+ {
+ final String[] values = (String[]) modes;
boolean valid = values.length > 0;
- for(int i=0; i<values.length; i++) {
- if ( !CUSTOM_MODES.contains(values[i]) ) {
+ for (int i = 0; i < values.length; i++)
+ {
+ if (!CUSTOM_MODES.contains(values[i]))
+ {
valid = false;
break;
}
}
- if ( valid) {
+ if (valid)
+ {
modesArray = values;
- } else {
+ }
+ else
+ {
modesArray = null;
}
}
}
- return new ConfigurationPrinterAdapter(
- cfgPrinter,
- printMethod,
- ClassUtils.searchMethod(cfgPrinter.getClass(), "getAttachments", new Class[] {String.class}),
- title,
- (label instanceof String ? (String)label : null),
- modesArray,
- !webUnescaped);
+ return new ConfigurationPrinterAdapter(cfgPrinter, printMethod, ClassUtils.searchMethod(
+ cfgPrinter.getClass(), "getAttachments", new Class[]
+ { String.class }), title, (label instanceof String ? (String) label : null), modesArray,
+ !webUnescaped);
}
return null;
}
- private ConfigurationPrinterAdapter( final Object printer,
- final Method printMethod,
- final Method attachmentMethod,
- final String title,
- final String label,
- final String[] modesArray,
- final boolean escapeHtml ) {
+ private ConfigurationPrinterAdapter(final Object printer, final Method printMethod, final Method attachmentMethod,
+ final String title, final String label, final String[] modesArray, final boolean escapeHtml)
+ {
this.printer = printer;
this.title = title;
this.label = label;
@@ -181,46 +208,65 @@
/**
* Map the modes to inventory printer modes
*/
- public String[] getPrinterModes() {
+ public String[] getPrinterModes()
+ {
final Set list = new HashSet();
- if ( this.match(ConsoleConstants.MODE_TXT) || this.match(ConsoleConstants.MODE_ZIP) ) {
+ if (this.match(ConsoleConstants.MODE_TXT) || this.match(ConsoleConstants.MODE_ZIP))
+ {
list.add(PrinterMode.TEXT.name());
}
- if ( this.match(ConsoleConstants.MODE_WEB) ) {
- if ( !escapeHtml ) {
+ if (this.match(ConsoleConstants.MODE_WEB))
+ {
+ if (!escapeHtml)
+ {
list.add(PrinterMode.HTML_FRAGMENT.name());
- } else {
+ }
+ else
+ {
list.add(PrinterMode.TEXT.name());
}
}
return (String[]) list.toArray(new String[list.size()]);
}
- private boolean match(final String mode) {
- if ( this.modes == null) {
+ private boolean match(final String mode)
+ {
+ if (this.modes == null)
+ {
return true;
}
- for(int i=0; i<this.modes.length; i++) {
- if ( this.modes[i].equals(mode) ) {
+ for (int i = 0; i < this.modes.length; i++)
+ {
+ if (this.modes[i].equals(mode))
+ {
return true;
}
}
return false;
}
- public final void printConfiguration( final PrintWriter pw, final String mode ) {
- if ( printMethod.getParameterTypes().length > 1 ) {
- ClassUtils.invoke(this.printer, this.printMethod, new Object[] {pw, mode});
- } else {
- ClassUtils.invoke(this.printer, this.printMethod, new Object[] {pw});
+ public final void printConfiguration(final PrintWriter pw, final String mode)
+ {
+ if (printMethod.getParameterTypes().length > 1)
+ {
+ ClassUtils.invoke(this.printer, this.printMethod, new Object[]
+ { pw, mode });
+ }
+ else
+ {
+ ClassUtils.invoke(this.printer, this.printMethod, new Object[]
+ { pw });
}
}
- public URL[] getAttachments() {
+ public URL[] getAttachments()
+ {
// check if printer implements binary configuration printer
URL[] attachments = null;
- if ( attachmentMethod != null ) {
- attachments = (URL[])ClassUtils.invoke(printer, attachmentMethod, new Object[] {ConsoleConstants.MODE_ZIP});
+ if (attachmentMethod != null)
+ {
+ attachments = (URL[]) ClassUtils.invoke(printer, attachmentMethod, new Object[]
+ { ConsoleConstants.MODE_ZIP });
}
return attachments;
}
@@ -228,7 +274,8 @@
/**
* @see java.lang.Object#toString()
*/
- public String toString() {
+ public String toString()
+ {
return title + " (" + printer.getClass() + ")";
}
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConsoleConstants.java b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConsoleConstants.java
index 274a989..1a33ebd 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConsoleConstants.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConsoleConstants.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -16,8 +16,8 @@
*/
package org.apache.felix.inventory.impl.webconsole;
-
-public class ConsoleConstants {
+public class ConsoleConstants
+{
public static final String INTERFACE_SERVLET = "javax.servlet.Servlet"; //$NON-NLS-1$
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ResourceBundleManager.java b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ResourceBundleManager.java
index 7c4ae42..ad893cf 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ResourceBundleManager.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ResourceBundleManager.java
@@ -1,24 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.felix.inventory.impl.webconsole;
-
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
@@ -34,10 +33,10 @@
import org.osgi.framework.BundleListener;
import org.osgi.framework.Constants;
-
/**
* The ResourceBundleManager manages resource bundle instance per OSGi Bundle.
- * It contains a local cache, for bundles, but when a bundle is being unistalled,
+ * It contains a local cache, for bundles, but when a bundle is being
+ * unistalled,
* its resources stored in the cache are cleaned up.
*/
public class ResourceBundleManager implements BundleListener
@@ -47,129 +46,141 @@
private final Map resourceBundleCaches;
-
/**
* Creates a new object and adds self as a bundle listener
- *
+ *
* @param bundleContext the bundle context of the Web Console.
*/
- public ResourceBundleManager( final BundleContext bundleContext )
+ public ResourceBundleManager(final BundleContext bundleContext)
{
this.bundleContext = bundleContext;
this.resourceBundleCaches = new HashMap();
- bundleContext.addBundleListener( this );
+ bundleContext.addBundleListener(this);
}
-
/**
* Removes the bundle lister.
*/
public void dispose()
{
- bundleContext.removeBundleListener( this );
+ bundleContext.removeBundleListener(this);
}
-
/**
- * This method is used to retrieve a /cached/ instance of the i18n resource associated
+ * This method is used to retrieve a /cached/ instance of the i18n resource
+ * associated
* with a given bundle.
- *
+ *
* @param provider the bundle, provider of the resources
* @param locale the requested locale.
*/
- public ResourceBundle getResourceBundle( final Bundle provider ) {
+ public ResourceBundle getResourceBundle(final Bundle provider)
+ {
ResourceBundle cache;
- final Long key = new Long( provider.getBundleId() );
- synchronized ( resourceBundleCaches ) {
- cache = (ResourceBundle) resourceBundleCaches.get( key );
- if ( cache == null && !resourceBundleCaches.containsKey(key)) {
+ final Long key = new Long(provider.getBundleId());
+ synchronized (resourceBundleCaches)
+ {
+ cache = (ResourceBundle) resourceBundleCaches.get(key);
+ if (cache == null && !resourceBundleCaches.containsKey(key))
+ {
cache = this.loadResourceBundle(provider);
- resourceBundleCaches.put( key, cache );
+ resourceBundleCaches.put(key, cache);
}
}
return cache;
}
-
// ---------- BundleListener
/**
* @see org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent)
*/
- public final void bundleChanged( BundleEvent event )
+ public final void bundleChanged(BundleEvent event)
{
- if ( event.getType() == BundleEvent.STOPPED )
+ if (event.getType() == BundleEvent.STOPPED)
{
- final Long key = new Long( event.getBundle().getBundleId() );
- synchronized ( resourceBundleCaches )
+ final Long key = new Long(event.getBundle().getBundleId());
+ synchronized (resourceBundleCaches)
{
- resourceBundleCaches.remove( key );
+ resourceBundleCaches.remove(key);
}
}
}
private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
- private ResourceBundle loadResourceBundle(final Bundle bundle) {
+ private ResourceBundle loadResourceBundle(final Bundle bundle)
+ {
final String path = "_" + DEFAULT_LOCALE.toString(); //$NON-NLS-1$
- final URL source = ( URL ) getResourceBundleEntries(bundle).get( path );
- if ( source != null ) {
- try {
- return new PropertyResourceBundle( source.openStream() );
- } catch ( final IOException ignore ) {
+ final URL source = (URL) getResourceBundleEntries(bundle).get(path);
+ if (source != null)
+ {
+ try
+ {
+ return new PropertyResourceBundle(source.openStream());
+ }
+ catch (final IOException ignore)
+ {
// ignore
}
}
return null;
}
- // TODO : Instead of getting all property files, we could just get the one for the default locale
+ // TODO : Instead of getting all property files, we could just get the one
+ // for the default locale
private synchronized Map getResourceBundleEntries(final Bundle bundle)
{
- String file = ( String ) bundle.getHeaders().get( Constants.BUNDLE_LOCALIZATION );
- if ( file == null )
+ String file = (String) bundle.getHeaders().get(Constants.BUNDLE_LOCALIZATION);
+ if (file == null)
{
file = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
}
// remove leading slash
- if ( file.startsWith( "/" ) ) //$NON-NLS-1$
+ if (file.startsWith("/")) //$NON-NLS-1$
{
- file = file.substring( 1 );
+ file = file.substring(1);
}
// split path and base name
- int slash = file.lastIndexOf( '/' );
- String fileName = file.substring( slash + 1 );
- String path = ( slash <= 0 ) ? "/" : file.substring( 0, slash ); //$NON-NLS-1$
+ int slash = file.lastIndexOf('/');
+ String fileName = file.substring(slash + 1);
+ String path = (slash <= 0) ? "/" : file.substring(0, slash); //$NON-NLS-1$
HashMap resourceBundleEntries = new HashMap();
- Enumeration locales = bundle.findEntries( path, fileName + "*.properties", false ); //$NON-NLS-1$
- if ( locales != null )
+ Enumeration locales = bundle.findEntries(path, fileName + "*.properties", false); //$NON-NLS-1$
+ if (locales != null)
{
- while ( locales.hasMoreElements() )
+ while (locales.hasMoreElements())
{
- URL entry = ( URL ) locales.nextElement();
+ URL entry = (URL) locales.nextElement();
// calculate the key
String entryPath = entry.getPath();
- final int start = entryPath.lastIndexOf( '/' ) + 1 + fileName.length(); // path, slash and base name
+ final int start = entryPath.lastIndexOf('/') + 1 + fileName.length(); // path,
+ // slash
+ // and
+ // base
+ // name
final int end = entryPath.length() - 11; // .properties suffix
- entryPath = entryPath.substring( start, end );
+ entryPath = entryPath.substring(start, end);
// the default language is "name.properties" thus the entry
// path is empty and must default to "_"+DEFAULT_LOCALE
- if (entryPath.length() == 0) {
+ if (entryPath.length() == 0)
+ {
entryPath = "_" + DEFAULT_LOCALE; //$NON-NLS-1$
}
// only add this entry, if the "language" is not provided
// by the main bundle or an earlier bound fragment
- if (!resourceBundleEntries.containsKey( entryPath )) {
- resourceBundleEntries.put( entryPath, entry );
+ if (!resourceBundleEntries.containsKey(entryPath))
+ {
+ resourceBundleEntries.put(entryPath, entry);
}
}
}
diff --git a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java
index 423ed8a..299c9e7 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * 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
- *
+ * 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.
@@ -16,7 +16,6 @@
*/
package org.apache.felix.inventory.impl.webconsole;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
@@ -43,12 +42,12 @@
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
/**
* The web console adapter registers web console status printers
* as inventory printers.
*/
-public class WebConsoleAdapter implements ServiceTrackerCustomizer {
+public class WebConsoleAdapter implements ServiceTrackerCustomizer
+{
private final BundleContext bundleContext;
@@ -58,49 +57,58 @@
private final ResourceBundleManager rbManager;
- public WebConsoleAdapter(final BundleContext btx) throws InvalidSyntaxException {
+ public WebConsoleAdapter(final BundleContext btx) throws InvalidSyntaxException
+ {
this.bundleContext = btx;
this.rbManager = new ResourceBundleManager(btx);
- this.cfgPrinterTracker = new ServiceTracker( this.bundleContext,
- this.bundleContext.createFilter("(|(" + Constants.OBJECTCLASS + "=" + ConsoleConstants.INTERFACE_CONFIGURATION_PRINTER + ")" +
- "(&(" + ConsoleConstants.PLUGIN_LABEL + "=*)(&("
- + ConsoleConstants.PLUGIN_TITLE + "=*)("
- + ConsoleConstants.CONFIG_PRINTER_MODES + "=*))))"),
- this );
+ this.cfgPrinterTracker = new ServiceTracker(this.bundleContext, this.bundleContext.createFilter("(|("
+ + Constants.OBJECTCLASS + "=" + ConsoleConstants.INTERFACE_CONFIGURATION_PRINTER + ")" + "(&("
+ + ConsoleConstants.PLUGIN_LABEL + "=*)(&(" + ConsoleConstants.PLUGIN_TITLE + "=*)("
+ + ConsoleConstants.CONFIG_PRINTER_MODES + "=*))))"), this);
this.cfgPrinterTracker.open();
}
/**
* Dispose this service
*/
- public void dispose() {
+ public void dispose()
+ {
this.cfgPrinterTracker.close();
final List regs = new ArrayList();
- synchronized ( this.registrations ) {
- regs.addAll( this.registrations.values() );
+ synchronized (this.registrations)
+ {
+ regs.addAll(this.registrations.values());
this.registrations.clear();
}
final Iterator i = regs.iterator();
- while (i.hasNext()) {
+ while (i.hasNext())
+ {
final ServiceRegistration reg = (ServiceRegistration) i.next();
reg.unregister();
}
this.rbManager.dispose();
}
- private void add(final ServiceReference reference, final Object service) {
+ private void add(final ServiceReference reference, final Object service)
+ {
final ConfigurationPrinterAdapter cpa = ConfigurationPrinterAdapter.createAdapter(service, reference);
- if ( cpa != null && cpa.title != null ) {
- if ( cpa.title.startsWith("%") ) {
+ if (cpa != null && cpa.title != null)
+ {
+ if (cpa.title.startsWith("%"))
+ {
final String key = cpa.title.substring(1);
final ResourceBundle rb = this.rbManager.getResourceBundle(reference.getBundle());
- if ( rb == null || !rb.containsKey(key) ) {
+ if (rb == null || !rb.containsKey(key))
+ {
cpa.title = key;
- } else {
+ }
+ else
+ {
cpa.title = rb.getString(key);
}
}
- if ( cpa.label == null ) {
+ if (cpa.label == null)
+ {
cpa.label = cpa.title;
}
final Dictionary props = new Hashtable();
@@ -108,19 +116,24 @@
props.put(InventoryPrinter.CONFIG_TITLE, cpa.title);
props.put(InventoryPrinter.CONFIG_PRINTER_MODES, cpa.getPrinterModes());
- final ServiceRegistration reg = this.bundleContext.registerService(InventoryPrinter.class.getName(), new WebConsolePrinter(cpa), props);
- synchronized ( this.registrations ) {
+ final ServiceRegistration reg = this.bundleContext.registerService(InventoryPrinter.class.getName(),
+ new WebConsolePrinter(cpa), props);
+ synchronized (this.registrations)
+ {
this.registrations.put(reference, reg);
}
}
}
- private final void remove(final ServiceReference reference) {
+ private final void remove(final ServiceReference reference)
+ {
final ServiceRegistration reg;
- synchronized ( this.registrations ) {
+ synchronized (this.registrations)
+ {
reg = (ServiceRegistration) this.registrations.remove(reference);
}
- if ( reg != null ) {
+ if (reg != null)
+ {
reg.unregister();
}
}
@@ -128,87 +141,123 @@
/**
* @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
*/
- public Object addingService(final ServiceReference reference) {
+ public Object addingService(final ServiceReference reference)
+ {
final Object service = this.bundleContext.getService(reference);
- if ( service != null ) {
+ if (service != null)
+ {
this.add(reference, service);
}
return service;
}
+
/**
- * @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference, java.lang.Object)
+ * @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference,
+ * java.lang.Object)
*/
- public void modifiedService(final ServiceReference reference, final Object service) {
+ public void modifiedService(final ServiceReference reference, final Object service)
+ {
this.remove(reference);
this.add(reference, service);
}
/**
- * @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference, java.lang.Object)
+ * @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference,
+ * java.lang.Object)
*/
- public void removedService(final ServiceReference reference, final Object service) {
+ public void removedService(final ServiceReference reference, final Object service)
+ {
this.remove(reference);
this.bundleContext.ungetService(reference);
}
- private static class WebConsolePrinter implements InventoryPrinter, ZipAttachmentProvider {
+ private static class WebConsolePrinter implements InventoryPrinter, ZipAttachmentProvider
+ {
final ConfigurationPrinterAdapter cpa;
- public WebConsolePrinter(final ConfigurationPrinterAdapter cpa) {
+ public WebConsolePrinter(final ConfigurationPrinterAdapter cpa)
+ {
this.cpa = cpa;
}
/**
- * @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)
*/
- public void print(final PrinterMode mode, final PrintWriter printWriter, final boolean isZip ) {
+ public void print(final PrinterMode mode, final PrintWriter printWriter, final boolean isZip)
+ {
final String m;
- if ( !isZip && mode == PrinterMode.HTML_FRAGMENT ) {
+ if (!isZip && mode == PrinterMode.HTML_FRAGMENT)
+ {
m = ConsoleConstants.MODE_WEB;
- } else if ( !isZip && mode == PrinterMode.TEXT ) {
+ }
+ else if (!isZip && mode == PrinterMode.TEXT)
+ {
m = ConsoleConstants.MODE_TXT;
- } else if (isZip && (mode == PrinterMode.TEXT || mode == PrinterMode.HTML_FRAGMENT) ) {
+ }
+ else if (isZip && (mode == PrinterMode.TEXT || mode == PrinterMode.HTML_FRAGMENT))
+ {
m = ConsoleConstants.MODE_ZIP;
- } else {
+ }
+ else
+ {
m = null;
}
- if ( m != null ) {
+ if (m != null)
+ {
cpa.printConfiguration(printWriter, m);
}
}
/**
- * @see org.apache.felix.inventory.ZipAttachmentProvider#addAttachments(java.lang.String, java.util.zip.ZipOutputStream)
+ * @see org.apache.felix.inventory.ZipAttachmentProvider#addAttachments(java.lang.String,
+ * java.util.zip.ZipOutputStream)
*/
- public void addAttachments(final String namePrefix, final ZipOutputStream zos)
- throws IOException {
+ public void addAttachments(final String namePrefix, final ZipOutputStream zos) throws IOException
+ {
final URL[] attachments = cpa.getAttachments();
- if ( attachments != null ) {
- for(int i=0;i<attachments.length;i++) {
+ if (attachments != null)
+ {
+ for (int i = 0; i < attachments.length; i++)
+ {
final URL current = attachments[i];
final String path = current.getPath();
final String name;
- if ( path == null || path.length() == 0 ) {
+ if (path == null || path.length() == 0)
+ {
// sanity code, we should have a path, but if not let's
// just create some random name
- name = "file" + Double.doubleToLongBits( Math.random() );
- } else {
+ name = "file" + Double.doubleToLongBits(Math.random());
+ }
+ else
+ {
final int pos = path.lastIndexOf('/');
name = (pos == -1 ? path : path.substring(pos + 1));
}
final ZipEntry entry = new ZipEntry(namePrefix + name);
zos.putNextEntry(entry);
final InputStream is = current.openStream();
- try {
+ try
+ {
byte[] buffer = new byte[4096];
int n = 0;
- while (-1 != (n = is.read(buffer))) {
+ while (-1 != (n = is.read(buffer)))
+ {
zos.write(buffer, 0, n);
}
- } finally {
- if ( is != null ) {
- try { is.close(); } catch (final IOException ignore) {}
+ }
+ finally
+ {
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (final IOException ignore)
+ {
+ }
}
}
zos.closeEntry();