This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch jakarta-servlet-6
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/jakarta-servlet-6 by this push:
new e7afafb755 No need for a separate branch for inventory; we can
continue on the master branch
e7afafb755 is described below
commit e7afafb755d312c24754db985673a6648c918759
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed Aug 16 15:53:01 2023 +0200
No need for a separate branch for inventory; we can continue on the master
branch
---
inventory/changelog.txt | 48 ---
inventory/pom.xml | 123 --------
.../main/appended-resources/META-INF/DEPENDENCIES | 18 --
.../java/org/apache/felix/inventory/Format.java | 99 -------
.../apache/felix/inventory/InventoryPrinter.java | 110 -------
.../felix/inventory/ZipAttachmentProvider.java | 64 ----
.../inventory/impl/AbstractWebConsolePlugin.java | 288 ------------------
.../org/apache/felix/inventory/impl/Activator.java | 126 --------
.../inventory/impl/DefaultWebConsolePlugin.java | 112 -------
.../inventory/impl/InventoryPrinterAdapter.java | 207 -------------
.../impl/InventoryPrinterDescription.java | 175 -----------
.../inventory/impl/InventoryPrinterHandler.java | 46 ---
.../impl/InventoryPrinterManagerImpl.java | 308 --------------------
.../felix/inventory/impl/WebConsolePlugin.java | 46 ---
.../inventory/impl/helper/ConfigurationWriter.java | 55 ----
.../impl/helper/HtmlConfigurationWriter.java | 150 ----------
.../impl/helper/JSONConfigurationWriter.java | 188 ------------
.../impl/helper/PlainTextConfigurationWriter.java | 46 ---
.../felix/inventory/impl/helper/SimpleJson.java | 105 -------
.../impl/helper/ZipConfigurationWriter.java | 218 --------------
.../webconsole/ConfigurationPrinterAdapter.java | 321 ---------------------
.../impl/webconsole/ConsoleConstants.java | 53 ----
.../impl/webconsole/ResourceBundleManager.java | 190 ------------
.../impl/webconsole/WebConsoleAdapter.java | 275 ------------------
.../org/apache/felix/inventory/package-info.java | 28 --
.../org/apache/felix/inventory/FormatTest.java | 67 -----
.../impl/helper/JSONConfigurationWriterTest.java | 43 ---
27 files changed, 3509 deletions(-)
diff --git a/inventory/changelog.txt b/inventory/changelog.txt
deleted file mode 100644
index 191a312418..0000000000
--- a/inventory/changelog.txt
+++ /dev/null
@@ -1,48 +0,0 @@
-Changes in 1.1.0
-----------------
-** Improvement
- * [FELIX-6375] - Require Java 8 as minimum version
-** Bug
- * [FELIX-6371] - JSONConfigurationWriter does not escape backslash and
other chars
-
-
-Changes in 1.0.6
-----------------
-** Bug
- * [FELIX-5755] - Servlet API should be optional
-** Task
- * [FELIX-5756] - Update project to latest parent pom
-
-
-Changes in 1.0.4
-----------------
-** Bug
- * [FELIX-4437] - Zip Writer does not pass the correct isZip status to the
InventoryPrinterHandler
-
-
-Changes in 1.0.2
-----------------
- * [FELIX-4078] - ConfigurationPrinterAdapter.getMethod should not only
consider implementation class
-
-
-Initial Release 1.0.0
----------------------
-
-** Bug
- * [FELIX-3916] - Full ZIP file has wrong file indices
- * [FELIX-3947] - ClassDefNotFoundError in Inventory bundle setup if
Servlet API cannot be wired
- * [FELIX-3963] - Properly handle method resolution through reflection
- * [FELIX-3964] - Wrong signature for non-service InventoryPrinter services
- * [FELIX-4026] - InventoryPrinter must run on Java 1.4 plattforms (for
embedded use)
- * [FELIX-4037] - URL parsing is not compatible with ConfigurationRender
plugin
- * [FELIX-4075] - Cleanup InventoryPrinter generated file names in the ZIP
file
-
-** Improvement
- * [FELIX-3945] - Don't use SLF4j Logging
- * [FELIX-3958] - Allow JSON output for InventoryPrinters not natively
supporting JSON
- * [FELIX-3959] - PrinterMode.valueOf should be case-insensitive
- * [FELIX-4025] - Cleanup InventoryPrinter API
-
-** Task
- * [FELIX-3874] - Create new status printer module
- * [FELIX-3970] - Remove unneeded hashCode and equals methods from
PrinterMode
diff --git a/inventory/pom.xml b/inventory/pom.xml
deleted file mode 100644
index 0466d0f565..0000000000
--- a/inventory/pom.xml
+++ /dev/null
@@ -1,123 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix-parent</artifactId>
- <version>7</version>
- <relativePath>../pom/pom.xml</relativePath>
- </parent>
-
- <artifactId>org.apache.felix.inventory</artifactId>
- <packaging>bundle</packaging>
- <version>2.0.0-SNAPSHOT</version>
-
- <name>Apache Felix Inventory</name>
- <description>Apache Felix Inventory provides some mechanisms to get the
current state of the system and therefore provides an inventory of the
system.</description>
-
- <scm>
-
<connection>scm:git:https://github.com/apache/felix-dev.git</connection>
-
<developerConnection>scm:git:https://github.com/apache/felix-dev.git</developerConnection>
- <url>https://gitbox.apache.org/repos/asf?p=felix-dev.git</url>
- <tag>HEAD</tag>
- </scm>
-
- <properties>
- <felix.java.version>11</felix.java.version>
- </properties>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- <configuration>
- <excludePackageNames>
-
org.apache.felix.inventory.impl:org.apache.felix.inventory.impl.helper:org.apache.felix.inventory.impl.webconsole
- </excludePackageNames>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>5.1.8</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Category>osgi</Bundle-Category>
- <Bundle-SymbolicName>
- ${project.artifactId}
- </Bundle-SymbolicName>
- <Bundle-Activator>
- org.apache.felix.inventory.impl.Activator
- </Bundle-Activator>
- <Import-Package>
- jakarta.servlet;resolution:=optional,
- jakarta.servlet.http;resolution:=optional,
- *
- </Import-Package>
- <DynamicImport-Package>
- jakarta.servlet, jakarta.servlet.http
- </DynamicImport-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.annotation</artifactId>
- <version>8.1.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.core</artifactId>
- <version>8.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.log</artifactId>
- <version>1.5.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>jakarta.servlet</groupId>
- <artifactId>jakarta.servlet-api</artifactId>
- <version>6.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.servlet</artifactId>
- <version>2.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/inventory/src/main/appended-resources/META-INF/DEPENDENCIES
b/inventory/src/main/appended-resources/META-INF/DEPENDENCIES
deleted file mode 100644
index fb8b3190ce..0000000000
--- a/inventory/src/main/appended-resources/META-INF/DEPENDENCIES
+++ /dev/null
@@ -1,18 +0,0 @@
-I. Included Third-Party Software
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
-Licensed under the Apache License 2.0.
-
-
-II. Used Third-Party Software
-
-This product uses software developed at
-The OSGi Alliance (http://www.osgi.org/).
-Copyright (c) OSGi Alliance (2000, 2015).
-Licensed under the Apache License 2.0.
-
-
-III. License Summary
-
-- Apache License 2.0
diff --git a/inventory/src/main/java/org/apache/felix/inventory/Format.java
b/inventory/src/main/java/org/apache/felix/inventory/Format.java
deleted file mode 100644
index 3ef7bd9c38..0000000000
--- a/inventory/src/main/java/org/apache/felix/inventory/Format.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory;
-
-/**
- * Java 1.4 compatible enumeration of formats used for inventory printing.
- * <p>
- * {@link InventoryPrinter} services indicate supported formats listing any of
- * these values in their {@link InventoryPrinter#FORMAT} service
- * properties.
- * <p>
- * Requestors of inventory printing indicate the desired output format by
- * specifying the respective constant when calling the
- * {@link InventoryPrinter#print(java.io.PrintWriter, Format, boolean)} method.
- * <p>
- * Round-tripping is guaranteed between the {@link #toString()} and
- * {@link #valueOf(String)} methods.
- */
-public final class Format
-{
-
- /**
- * Inventory is printed in plain text format.
- */
- public static Format TEXT = new Format("TEXT");
-
- /**
- * Inventory is printed in HTML format.
- * <p>
- * Technically the output is expected to be an HTML fragment which is
- * intended to be inserted into any block element, such as {@code <div>},
- * within a HTML {@code <body>}.
- */
- public static Format HTML = new Format("HTML");
-
- /**
- * Inventory is printed in JSON format.
- * <p>
- * The output is expected to be a valid JSON object. That is, the output
- * must start with an opening curly brace (<code>{</code>) and end with a
- * closing curly brace (<code>}</code>).
- */
- public static Format JSON = new Format("JSON");
-
- private final String format;
-
- private Format(final String format)
- {
- this.format = format;
- }
-
- /**
- * Converts the given {@code format} string into an instance of
- * this class.
- *
- * @param format The string value to be converted into a {@code Format}.
- * @return One of the defined {@code Format} constants or {@code null}.
- */
- public static Format valueOf(final String format)
- {
- if (TEXT.format.equalsIgnoreCase(format))
- {
- return TEXT;
- }
- else if (HTML.format.equalsIgnoreCase(format))
- {
- return HTML;
- }
- else if (JSON.format.equalsIgnoreCase(format))
- {
- return JSON;
- }
- return null;
- }
-
- /**
- * Returns the string value of this format.
- */
- public String toString()
- {
- return format;
- }
-}
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java
b/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java
deleted file mode 100644
index 435c4aa228..0000000000
--- a/inventory/src/main/java/org/apache/felix/inventory/InventoryPrinter.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory;
-
-import java.io.PrintWriter;
-
-import org.osgi.annotation.versioning.ConsumerType;
-
-/**
- * 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.
- * <p>
- * The following service registration properties further declare the
- * {@code InventoryPrinter} service:
- * <ul>
- * <li>{@link #FORMAT} - the supported formats</li>
- * <li>{@link #TITLE} - the printer title</li>
- * <li>{@link #NAME} - the printer name</li>
- * <li>{@link #WEBCONSOLE} - whether to confine the printer to the Web
Console</li>
- * </ul>
- */
-@ConsumerType
-public interface InventoryPrinter
-{
-
- /**
- * The service name under which services of this class must be registered
- * to be picked for inclusion in the configuration report.
- */
- String SERVICE = "org.apache.felix.inventory.InventoryPrinter";
//$NON-NLS-1$
-
- /**
- * The property defining one or more supported formats. The value of this
- * property is either a string, a string array or a Collection<String>
- * containing valid names of the constants defined in the {@link Format}
- * class.
- * <p>
- * Any unknown formats are ignored. If this property is not declared or
does
- * not declare any known formats, the {@link Format#TEXT} format is assumed
- * as the printer's supported format.
- */
- String FORMAT = "felix.inventory.printer.format"; //$NON-NLS-1$
-
- /**
- * The unique name (or label) of the printer.
- * <p>
- * If this property is missing or an empty string, the name is constructed
- * from the string {@code InventoryPrinter} and the service's
- * {@code service.id} property.
- */
- String NAME = "felix.inventory.printer.name"; //$NON-NLS-1$
-
- /**
- * The title displayed by tools when this printer is used. It should be
- * descriptive but short.
- * <p>
- * If this property is missing or an empty string, the {@link #NAME} value
- * is used as the title.
- */
- String TITLE = "felix.inventory.printer.title"; //$NON-NLS-1$
-
- /**
- * The inventory printer feature has first class integration with the
- * Apache Felix Web Console. This service registration property can be used
- * to hide an inventory printer service from the Web Console. The service
- * will still be called to generate the single file or ZIP file output of
- * inventory printers.
- * <p>
- * By default, a printer is displayed in the web console, unless this
- * property is set to {@code false}. The property value can either be a
- * boolean or a string.
- */
- String WEBCONSOLE = "felix.inventory.printer.webconsole"; //$NON-NLS-1$
-
- /**
- * Prints the configuration report to the given <code>printWriter</code>.
- * Implementations are free to print whatever information they deem useful.
- * <p>
- * If a printer is invoked with a format it doesn't support ( {@link
#FORMAT})
- * the printer should just do/print nothing and directly return.
- * <p>
- * 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 printWriter where to write the data. Implementations may flush
the
- * writer but must not close it.
- * @param format The render format.
- * @param isZip whether this is included in a ZIP file or used directly
- */
- void print(PrintWriter printWriter, Format format, boolean isZip);
-}
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/ZipAttachmentProvider.java
b/inventory/src/main/java/org/apache/felix/inventory/ZipAttachmentProvider.java
deleted file mode 100644
index a4b915ea57..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/ZipAttachmentProvider.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory;
-
-import java.io.IOException;
-import java.util.zip.ZipOutputStream;
-
-import org.osgi.annotation.versioning.ConsumerType;
-
-/**
- * This is an optional extension of the {@link InventoryPrinter}.
- * If a inventory printer implements this interface, the printer
- * can add additional attachments to the output of the
- * configuration ZIP.
- * <p>
- * A service implementing this method must register itself as a
- * {@link InventoryPrinter} but not as a {@link ZipAttachmentProvider} service.
- * When writing output to a ZIP file, this method is called if the
- * {@link InventoryPrinter} service implements this interface.
- */
-@ConsumerType
-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.
- * <p>
- * The general pattern is to do for each entry to be added:
- * <ol>
- * <li>Create ZipEntry with a name composed of {@code namePrefix} and a
name
- * unique to the attachement provider, e.g. {@code namePrefix +
"att1.txt"}.
- * </li>
- * <li>Add the ZipEntry to the ZIP file {@code zos}.</li>
- * <li>Write the contents of the entry; for example copying a filesystem
- * file to the ZIP file {@code zos}.</li>
- * <li>Close the ZipEntry.</li>
- * </ol>
- * @param zos The zip output stream.
- * @param namePrefix Name prefix to use for zip entries. Ends with a slash.
- *
- * @throws IOException If an error occurrs writing the ZIP entry. This may
- * also be caused by reading some file system file to be added
- * to the ZIP file.
- */
- void addAttachments(final ZipOutputStream zos, final String namePrefix)
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
deleted file mode 100644
index 2f4b48d2e3..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/AbstractWebConsolePlugin.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.inventory.impl;
-
-import java.io.IOException;
-import java.text.DateFormat;
-import java.util.Date;
-import java.util.Locale;
-
-import org.apache.felix.inventory.Format;
-import org.apache.felix.inventory.impl.helper.ConfigurationWriter;
-import org.apache.felix.inventory.impl.helper.HtmlConfigurationWriter;
-import org.apache.felix.inventory.impl.helper.JSONConfigurationWriter;
-import org.apache.felix.inventory.impl.helper.PlainTextConfigurationWriter;
-import org.apache.felix.inventory.impl.helper.ZipConfigurationWriter;
-
-import jakarta.servlet.http.HttpServlet;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-/**
- * The web console plugin for a inventory printer.
- */
-public abstract class AbstractWebConsolePlugin extends HttpServlet
-{
-
- private static final long serialVersionUID = 1L;
-
- /** The inventory printer manager. */
- protected final InventoryPrinterManagerImpl inventoryPrinterManager;
-
- /**
- * Constructor
- *
- * @param inventoryPrinterManager The manager
- */
- AbstractWebConsolePlugin(final InventoryPrinterManagerImpl
inventoryPrinterManager)
- {
- this.inventoryPrinterManager = inventoryPrinterManager;
- }
-
- protected abstract InventoryPrinterHandler getInventoryPrinterHandler();
-
- private void printConfigurationInventory(final ConfigurationWriter pw,
final Format format,
- final InventoryPrinterHandler handler) throws IOException
- {
- if (handler == null)
- {
- final InventoryPrinterHandler[] adapters =
this.inventoryPrinterManager.getHandlers(format);
- for (int i = 0; i < adapters.length; i++)
- {
- pw.printInventory(format, adapters[i]);
- }
- }
- else
- {
- if (format == null || handler.supports(format))
- {
- pw.printInventory(format, handler);
- }
- }
- }
-
- /**
- * Sets response headers to force the client to not cache the response
- * sent back. This method must be called before the response is committed
- * otherwise it will have no effect.
- * <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)
- {
- 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$
- response.addHeader("Cache-Control", "max-age=0"); //$NON-NLS-1$
//$NON-NLS-2$
- response.setHeader("Expires", "Thu, 01 Jan 1970 01:00:00 GMT");
//$NON-NLS-1$ //$NON-NLS-2$
- response.setHeader("Pragma", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- protected InventoryPrinterHandler getInventoryPrinterHandler(final String
label)
- {
- return null; // all by default
- }
-
- protected void doGet(final HttpServletRequest request, final
HttpServletResponse response) throws IOException
- {
- this.setNoCache(response);
-
- // full request?
- final InventoryPrinterHandler handler;
- final String pathInfo = request.getPathInfo();
- final int lastSlash = pathInfo.lastIndexOf('/');
- if (lastSlash > 0)
- {
- final int lastDot = pathInfo.lastIndexOf('.');
- final String label = (lastDot < lastSlash ?
pathInfo.substring(lastSlash + 1) : pathInfo.substring(lastSlash + 1, lastDot));
- handler = this.getInventoryPrinterHandler(label); // usually all;
- }
- else
- {
- handler = this.getInventoryPrinterHandler();
- 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, Format.TEXT, handler);
- pw.flush();
- }
- 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);
-
- final ZipConfigurationWriter pw =
ZipConfigurationWriter.create(response.getOutputStream());
- printConfigurationInventory(pw, null, handler);
- pw.finish();
- }
- else if (request.getPathInfo().endsWith(".nfo"))
- {
- if (handler == null)
- {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
- 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>");
-
- if (handler.supports(Format.HTML))
- {
- handler.print(pw, Format.HTML, false);
- }
- else if (handler.supports(Format.TEXT))
- {
- pw.enableFilter(true);
- handler.print(pw, Format.TEXT, false);
- pw.enableFilter(false);
- }
- else
- {
- pw.enableFilter(true);
- handler.print(pw, Format.JSON, 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);
- return;
- }
- response.setContentType("application/json"); //$NON-NLS-1$
- response.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
-
- final JSONConfigurationWriter jcw = new
JSONConfigurationWriter(response.getWriter());
- final Format format;
- if (handler.supports(Format.JSON))
- {
- format = Format.JSON;
- }
- else
- {
- format = Format.TEXT;
- jcw.startJSONWrapper();
- }
- printConfigurationInventory(jcw, format, handler);
- jcw.endJSONWrapper();
- jcw.flush();
- }
- else
- {
- if (handler == null)
- {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
- final HtmlConfigurationWriter pw = new
HtmlConfigurationWriter(response.getWriter());
- pw.println("<script type=\"text/javascript\">");
- pw.println("// <![CDATA[");
- pw.println("function pad(value) { if ( value < 10 ) { return '0' +
value;} return '' + value;}");
- pw.println("function downloadDump(ext, full) {");
- pw.println(" if (full) {");
- pw.println(" var now = new Date();");
- pw.println(" var name = \"configuration-status-\" +
now.getUTCFullYear() + pad(now.getUTCMonth() + 1) + pad(now.getUTCDate()) +
\"-\" + pad(now.getUTCHours()) + pad(now.getUTCMinutes()) +
pad(now.getUTCSeconds()) + \".\";");
- pw.println(" location.href = location.href + \"/\" + name +
ext;");
- pw.println(" } else {");
- pw.println(" location.href = location.href + '.' + ext;");
- pw.println(" }");
- pw.println("}");
-
- pw.println("$(document).ready(function() {");
- pw.println(" $('.downloadTxt').click(function() {
downloadDump('txt', false)});");
- pw.println(" $('.downloadJson').click(function() {
downloadDump('json', false)});");
- pw.println(" $('.downloadZip').click(function() {
downloadDump('zip', false)});");
- pw.println(" $('.downloadFullZip').click(function() {
downloadDump('zip', true)});");
- pw.println(" $('.downloadFullTxt').click(function() {
downloadDump('txt', true)});");
- pw.println("});");
- pw.println("// ]]>");
- pw.println("</script>");
- pw.println("<br/><p class=\"statline\">");
-
- pw.print("Date: ");
- pw.println(DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.LONG, Locale.US).format(new Date()));
-
- 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(Format.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(Format.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>");
-
- final boolean filter;
- final Format format;
- if (handler.supports(Format.HTML))
- {
- filter = false;
- format = Format.HTML;
- }
- else if (handler.supports(Format.TEXT))
- {
- // prefer TEXT of JSON if available
- filter = true;
- format = Format.TEXT;
- }
- else if (handler.supports(Format.JSON))
- {
- filter = true;
- format = Format.JSON;
- }
- else
- {
- // fallback to TEXT (if unknown format)
- filter = true;
- format = Format.TEXT;
- }
-
- pw.enableFilter(filter);
- handler.print(pw, format, false);
- pw.enableFilter(false);
-
- pw.print("</div>");
- }
- }
-
-}
\ No newline at end of file
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
deleted file mode 100644
index c3498485ee..0000000000
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.inventory.impl;
-
-import org.apache.felix.inventory.impl.webconsole.WebConsoleAdapter;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Activate bridges and internal manager.
- */
-public class Activator implements BundleActivator
-{
-
- private static Object logService;
-
- private ServiceTracker logServiceTracker;
-
- private InventoryPrinterManagerImpl printerManager;
-
- private WebConsoleAdapter webAdapter;
-
- /**
- * @see
org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- public void start(final BundleContext context) throws Exception
- {
- this.logServiceTracker = new ServiceTracker(context,
"org.osgi.service.log.LogService", null)
- {
- @Override
- public Object addingService(ServiceReference reference)
- {
- Activator.logService = super.addingService(reference);
- return Activator.logService;
- }
-
- @Override
- public void removedService(ServiceReference reference, Object
service)
- {
- Activator.logService = null;
- super.removedService(reference, service);
- }
- };
- this.logServiceTracker.open();
-
- 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)
- {
- this.printerManager.dispose();
- this.printerManager = null;
- }
- if (this.webAdapter != null)
- {
- this.webAdapter.dispose();
- this.webAdapter = null;
- }
- Activator.logService = null;
- if (this.logServiceTracker != null)
- {
- this.logServiceTracker.close();
- this.logServiceTracker = null;
- }
- }
-
- public static void log(final ServiceReference sr, final int level, final
String message, final Throwable exception)
- {
- Object logService = Activator.logService;
- if (logService != null)
- {
- ((LogService) logService).log(sr, level, message, exception);
- }
- else
- {
- final String code;
- switch (level)
- {
- case LogService.LOG_INFO:
- code = "*INFO *";
- break;
-
- case LogService.LOG_WARNING:
- code = "*WARN *";
- break;
-
- case LogService.LOG_ERROR:
- code = "*ERROR*";
- break;
-
- case LogService.LOG_DEBUG:
- default:
- code = "*DEBUG*";
- }
-
- System.out.println(code + " " + message);
- if (exception != null)
- {
- exception.printStackTrace(System.out);
- }
- }
- }
-}
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
deleted file mode 100644
index 5ca6d0a410..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/DefaultWebConsolePlugin.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.inventory.impl;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.zip.ZipOutputStream;
-
-import org.apache.felix.inventory.Format;
-import org.apache.felix.inventory.impl.webconsole.ConsoleConstants;
-
-/**
- * The web console plugin for a inventory printer.
- */
-public class DefaultWebConsolePlugin extends AbstractWebConsolePlugin
implements InventoryPrinterHandler
-{
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor
- *
- * @param inventoryPrinterAdapter The adapter
- */
- DefaultWebConsolePlugin(final InventoryPrinterManagerImpl
inventoryPrinterManager)
- {
- super(inventoryPrinterManager);
- }
-
- protected InventoryPrinterHandler getInventoryPrinterHandler()
- {
- return this;
- }
-
- protected InventoryPrinterHandler getInventoryPrinterHandler(final String
label)
- {
- return this.inventoryPrinterManager.getHandler(label);
- }
-
- /**
- * @see org.apache.felix.inventory.impl.InventoryPrinterHandler#getTitle()
- */
- public String getTitle()
- {
- return ConsoleConstants.TITLE;
- }
-
- /**
- * @see org.apache.felix.inventory.impl.InventoryPrinterHandler#getName()
- */
- public String getName()
- {
- return ConsoleConstants.NAME;
- }
-
- /**
- * @see
org.apache.felix.inventory..implInventoryPrinterHandler#getformats()
- */
- public Format[] getFormats()
- {
- return new Format[]
- { Format.TEXT };
- }
-
- /**
- * @see
org.apache.felix.inventory.impl.InventoryPrinterHandler#supports(org.apache.felix.inventory.Format)
- */
- public boolean supports(final Format format)
- {
- return format == Format.TEXT;
- }
-
- /**
- * @see
org.apache.felix.inventory.InventoryPrinter#print(java.io.PrintWriter,
- * org.apache.felix.inventory.Format, boolean)
- */
- public void print(final PrintWriter printWriter, final Format format,
final boolean isZip)
- {
- final InventoryPrinterHandler[] handlers =
this.inventoryPrinterManager.getHandlers(null);
- printWriter.print("Currently registered ");
- printWriter.print(String.valueOf(handlers.length));
- printWriter.println(" printer(s).");
- printWriter.println();
- for (int i = 0; i < handlers.length; i++)
- {
- printWriter.println(handlers[i].getTitle());
- }
- }
-
- /**
- * @see
org.apache.felix.inventory.ZipAttachmentProvider#addAttachments(java.util.zip.ZipOutputStream,
- * java.lang.String)
- */
- public void addAttachments(ZipOutputStream zos, String namePrefix) throws
IOException
- {
- // no attachments support
- }
-}
\ No newline at end of file
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
deleted file mode 100644
index 9d20002f59..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterAdapter.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.inventory.impl;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Comparator;
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.zip.ZipOutputStream;
-
-import org.apache.felix.inventory.Format;
-import org.apache.felix.inventory.InventoryPrinter;
-import org.apache.felix.inventory.ZipAttachmentProvider;
-import org.apache.felix.inventory.impl.webconsole.ConsoleConstants;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-
-/**
- * Helper class for a inventory printer.
- *
- * The adapter simplifies accessing and working with the inventory printer.
- */
-public class InventoryPrinterAdapter implements InventoryPrinterHandler,
Comparable<InventoryPrinterAdapter>
-{
-
- /**
- * Comparator for adapters based on the service ranking.
- */
- public static final Comparator<InventoryPrinterAdapter> RANKING_COMPARATOR
= new Comparator<InventoryPrinterAdapter>()
- {
-
- @Override
- public int compare(final InventoryPrinterAdapter o1, final
InventoryPrinterAdapter o2)
- {
- return o1.description.compareTo(o2.description);
- }
- };
-
- /** The Inventory printer service. */
- private final InventoryPrinter printer;
-
- /** The printer description. */
- private final InventoryPrinterDescription description;
-
- /** Service registration for the web console. */
- private ServiceRegistration registration;
-
- /**
- * Constructor.
- */
- public InventoryPrinterAdapter(final InventoryPrinterDescription
description, final InventoryPrinter printer)
- {
- this.description = description;
- this.printer = printer;
- }
-
- public void registerConsole(final BundleContext context, final
InventoryPrinterManagerImpl manager)
- {
- if (this.registration == null)
- {
- final Object value =
this.description.getServiceReference().getProperty(InventoryPrinter.WEBCONSOLE);
- if (value == null || !"false".equalsIgnoreCase(value.toString()))
- {
- final Dictionary<String, Object> props = new Hashtable<>();
-
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, getLabel());
-
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
- "(" +
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "="
- + ConsoleConstants.DEFAULT_CONTEXT_NAME + ")");
- props.put(ConsoleConstants.PLUGIN_LABEL, getLabel());
- props.put(ConsoleConstants.PLUGIN_TITLE,
this.description.getTitle());
- props.put(ConsoleConstants.PLUGIN_CATEGORY,
ConsoleConstants.WEB_CONSOLE_CATEGORY);
- this.registration =
context.registerService(ConsoleConstants.INTERFACE_SERVLET, new
WebConsolePlugin(manager, description.getName()), props);
- }
- }
- }
-
- public void unregisterConsole()
- {
- if (this.registration != null)
- {
- this.registration.unregister();
- this.registration = null;
- }
- }
-
- /**
- * The human readable title for the inventory printer.
- */
- @Override
- public String getTitle()
- {
- return this.description.getTitle();
- }
-
- /**
- * The unique name of the printer.
- */
- @Override
- public String getName()
- {
- return this.description.getName();
- }
-
- /**
- * All supported formats.
- */
- @Override
- public Format[] getFormats()
- {
- return this.description.getFormats();
- }
-
- /**
- * @see
org.apache.felix.inventory.ZipAttachmentProvider#addAttachments(java.util.zip.ZipOutputStream,
- * java.lang.String)
- */
- @Override
- public void addAttachments(final ZipOutputStream zos, final String
namePrefix) throws IOException
- {
- if (printer instanceof ZipAttachmentProvider)
- {
- ((ZipAttachmentProvider) printer).addAttachments(zos, namePrefix);
- }
- }
-
- /**
- * Whether the printer supports this format.
- */
- @Override
- public boolean supports(final Format format)
- {
- for (int i = 0; i < this.description.getFormats().length; i++)
- {
- if (this.description.getFormats()[i] == format)
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * @see
org.apache.felix.inventory.InventoryPrinter#print(org.apache.felix.inventory.Format,
- * java.io.PrintWriter)
- */
- @Override
- public void print(final PrintWriter printWriter, final Format format,
final boolean isZip)
- {
- if (this.supports(format))
- {
- this.printer.print(printWriter, format, isZip);
- }
- }
-
- public InventoryPrinterDescription getDescription()
- {
- return this.description;
- }
-
- private final String getLabel()
- {
- return ("status-" + this.description.getName());
- }
-
- @Override
- public int compareTo(final InventoryPrinterAdapter spa)
- {
- return
this.description.getSortKey().compareTo(spa.description.getSortKey());
- }
-
- @Override
- public int hashCode()
- {
- return this.description.getSortKey().hashCode();
- }
-
- @Override
- public boolean equals(final Object spa)
- {
- if ( !(spa instanceof InventoryPrinterAdapter)) {
- return false;
- }
- return this.description.getSortKey().equals(((InventoryPrinterAdapter)
spa).description.getSortKey());
- }
-
- @Override
- public String toString()
- {
- return printer.getClass() + "(" + super.toString() + ")";
- }
-}
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
deleted file mode 100644
index fc2e4bf7b1..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterDescription.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.inventory.impl;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.felix.inventory.Format;
-import org.apache.felix.inventory.InventoryPrinter;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Helper class for a configuration printer.
- */
-public class InventoryPrinterDescription implements
Comparable<InventoryPrinterDescription>
-{
-
- private final ServiceReference reference;
-
- private final Format[] formats;
-
- private final String name;
-
- private final String title;
-
- private final String sortKey;
-
- public InventoryPrinterDescription(final ServiceReference ref)
- {
- this.reference = ref;
-
- // check formats
- Format[] formats = null;
- final Object formatsCfg = ref.getProperty(InventoryPrinter.FORMAT);
- if (formatsCfg instanceof String)
- {
- final Format format = Format.valueOf((String) formatsCfg);
- if (format != null)
- {
- formats = new Format[]
- { format };
- }
- }
- else if (formatsCfg instanceof String[])
- {
- final String[] formatsCfgArray = (String[]) formatsCfg;
- final List<Format> formatList = new ArrayList<>();
- for (int i = 0; i < formatsCfgArray.length; i++)
- {
- final Format format = Format.valueOf(formatsCfgArray[i]);
- if (format != null)
- {
- formatList.add(format);
- }
- }
- if (!formatList.isEmpty())
- {
- formats = formatList.toArray(new Format[formatList.size()]);
- }
- }
-
- // check name
- final String name;
- if (ref.getProperty(InventoryPrinter.NAME) != null)
- {
- name = ref.getProperty(InventoryPrinter.NAME).toString();
- }
- else
- {
- name = "InventoryPrinter." + ref.getProperty(Constants.SERVICE_ID);
- }
-
- // check title
- final String title;
- String sortKey = null;
- if (ref.getProperty(InventoryPrinter.TITLE) != null)
- {
- title = ref.getProperty(InventoryPrinter.TITLE).toString();
- if (title.startsWith("%"))
- {
- sortKey = title.substring(1);
- }
- }
- else
- {
- title = name;
- }
-
- // cleanup
- if (formats == null)
- {
- formats = new Format[]
- { Format.TEXT };
- }
- if (sortKey == null)
- {
- sortKey = title;
- }
-
- // set fields
- this.formats = formats;
- this.name = name;
- this.title = title;
- this.sortKey = sortKey;
- }
-
- public String getTitle()
- {
- return this.title;
- }
-
- public String getSortKey()
- {
- return this.sortKey;
- }
-
- public String getName()
- {
- return this.name;
- }
-
- public Format[] getFormats()
- {
- return this.formats;
- }
-
- public ServiceReference getServiceReference()
- {
- return this.reference;
- }
-
- /**
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- @Override
- public int compareTo(final InventoryPrinterDescription spa)
- {
- return this.reference.compareTo(spa.reference);
- }
-
- @Override
- public boolean equals(final Object obj)
- {
- return this.reference.equals(obj);
- }
-
- @Override
- public int hashCode()
- {
- return this.reference.hashCode();
- }
-
- @Override
- public String toString()
- {
- return "InventoryPrinterDescription [title=" + title + ", name=" +
name + ", formats=" + Arrays.asList(formats)
- + ", 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
deleted file mode 100644
index 6ddb19a077..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterHandler.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory.impl;
-
-import org.apache.felix.inventory.InventoryPrinter;
-import org.apache.felix.inventory.Format;
-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
-{
-
- /** The unique name of the printer. */
- String getName();
-
- /** The human readable title for the inventory printer. */
- String getTitle();
-
- /** All supported formats. */
- Format[] getFormats();
-
- /** Whether the printer supports this format. */
- boolean supports(final Format format);
-}
\ 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
deleted file mode 100644
index 1db2dda626..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.inventory.impl;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.apache.felix.inventory.Format;
-import org.apache.felix.inventory.InventoryPrinter;
-import org.apache.felix.inventory.impl.webconsole.ConsoleConstants;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
-/**
- * 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<InventoryPrinter, InventoryPrinter>
-{
-
- /** Bundle Context . */
- private final BundleContext bundleContext;
-
- /** Service tracker for Inventory printers. */
- private final ServiceTracker<InventoryPrinter, InventoryPrinter>
cfgPrinterTracker;
-
- /**
- * All adapters mapped by their name.
- */
- private final Map<String, List<InventoryPrinterAdapter>> allAdapters = new
HashMap<>();
-
- /** Used adapters. */
- private final Set<InventoryPrinterAdapter> usedAdapters = new TreeSet<>();
-
- /** Registration for the web console. */
- private final ServiceRegistration pluginRegistration;
-
- /**
- * Create the inventory printer manager
- *
- * @param btx Bundle Context
- * @throws InvalidSyntaxException Should only happen if we have an error in
- * the code
- */
- public InventoryPrinterManagerImpl(final BundleContext btx) throws
InvalidSyntaxException
- {
- this.bundleContext = btx;
- this.cfgPrinterTracker = new ServiceTracker<>(this.bundleContext,
InventoryPrinter.class, this);
- this.cfgPrinterTracker.open();
-
- final Dictionary<String, Object> props = new Hashtable<>();
- props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME,
ConsoleConstants.NAME);
- props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
- "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME +
"=" + ConsoleConstants.DEFAULT_CONTEXT_NAME
- + ")");
- props.put(ConsoleConstants.PLUGIN_LABEL, ConsoleConstants.NAME);
- props.put(ConsoleConstants.PLUGIN_TITLE, ConsoleConstants.TITLE);
- props.put(ConsoleConstants.PLUGIN_CATEGORY,
ConsoleConstants.WEB_CONSOLE_CATEGORY);
- this.pluginRegistration =
btx.registerService(ConsoleConstants.INTERFACE_SERVLET, new
DefaultWebConsolePlugin(InventoryPrinterManagerImpl.this), props);
- }
-
- /**
- * Dispose this service
- */
- public void dispose()
- {
- if (this.pluginRegistration != null)
- {
- this.pluginRegistration.unregister();
- }
- this.cfgPrinterTracker.close();
- synchronized (this.allAdapters)
- {
- this.allAdapters.clear();
- }
- synchronized (this.usedAdapters)
- {
- this.usedAdapters.clear();
- }
- }
-
- /**
- * @see
org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
- */
- @Override
- public InventoryPrinter addingService(final
ServiceReference<InventoryPrinter> reference)
- {
- final InventoryPrinter obj = this.bundleContext.getService(reference);
- if (obj != null)
- {
- this.addService(reference, obj);
- }
-
- return obj;
- }
-
- /**
- * @see
org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference,
- * java.lang.Object)
- */
- @Override
- public void modifiedService(final ServiceReference<InventoryPrinter>
reference, final InventoryPrinter service)
- {
- this.removeService(reference);
- this.addService(reference, service);
- }
-
- /**
- * @see
org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference,
- * java.lang.Object)
- */
- @Override
- public void removedService(final ServiceReference<InventoryPrinter>
reference, final InventoryPrinter service)
- {
- this.removeService(reference);
- this.bundleContext.ungetService(reference);
- }
-
- private void addService(final ServiceReference<InventoryPrinter>
reference, final InventoryPrinter obj)
- {
- final InventoryPrinterDescription desc = new
InventoryPrinterDescription(reference);
- final InventoryPrinterAdapter adapter = new
InventoryPrinterAdapter(desc, obj);
-
- InventoryPrinterAdapter removeAdapter = null;
- InventoryPrinterAdapter addAdapter = null;
-
- final String key = adapter.getName();
- synchronized (this.allAdapters)
- {
- List<InventoryPrinterAdapter> list = this.allAdapters.get(key);
- final InventoryPrinterAdapter first;
- if (list == null)
- {
- list = new LinkedList<>();
- this.allAdapters.put(key, list);
- first = null;
- }
- else
- {
- first = list.get(0);
- }
- list.add(adapter);
- Collections.sort(list, InventoryPrinterAdapter.RANKING_COMPARATOR);
- if (first != null)
- {
- if (first != list.get(0))
- {
- // update
- removeAdapter = first;
- addAdapter = adapter;
- }
- }
- else
- {
- // add
- addAdapter = adapter;
- }
- }
- if (removeAdapter != null)
- {
- removeAdapter.unregisterConsole();
- synchronized (this.usedAdapters)
- {
- this.usedAdapters.remove(removeAdapter);
- }
- }
- if (addAdapter != null)
- {
- synchronized (this.usedAdapters)
- {
- this.usedAdapters.add(addAdapter);
- }
-
addAdapter.registerConsole(reference.getBundle().getBundleContext(), this);
- }
- }
-
- private void removeService(final ServiceReference<InventoryPrinter>
reference)
- {
- synchronized (this.allAdapters)
- {
- final Iterator<Map.Entry<String, List<InventoryPrinterAdapter>>> i
= this.allAdapters.entrySet().iterator();
- while (i.hasNext())
- {
- final Map.Entry<String, List<InventoryPrinterAdapter>> entry =
i.next();
- final Iterator<InventoryPrinterAdapter> iter =
entry.getValue().iterator();
- boolean removed = false;
- while (iter.hasNext())
- {
- final InventoryPrinterAdapter adapter = iter.next();
- if
(adapter.getDescription().getServiceReference().equals(reference))
- {
- iter.remove();
- removed = true;
- break;
- }
- }
- if (removed)
- {
- if (entry.getValue().size() == 0)
- {
- i.remove();
- }
- break;
- }
- }
- }
-
- InventoryPrinterAdapter adapterToUnregister = null;
- synchronized (this.usedAdapters)
- {
- final Iterator<InventoryPrinterAdapter> iter =
this.usedAdapters.iterator();
- while (iter.hasNext())
- {
- final InventoryPrinterAdapter adapter = iter.next();
- if
(adapter.getDescription().getServiceReference().equals(reference))
- {
- iter.remove();
- adapterToUnregister = adapter;
- break;
- }
- }
- }
- if (adapterToUnregister != null)
- {
- adapterToUnregister.unregisterConsole();
- }
- }
-
- /**
- * Get all handlers supporting the format or all handlers if {@code format}
- * is {@code null}.
- *
- * @param format The {@link Format} the returned handlers are expected to
- * support. If this parameter is {@code null} all handlers are
- * returned regardless of {@link Format} supported by the
- * handlers.
- *
- * @return A list of handlers - might be empty.
- */
- public InventoryPrinterHandler[] getHandlers(final Format format)
- {
- final List<InventoryPrinterAdapter> result = new ArrayList<>();
- synchronized (this.usedAdapters)
- {
- final Iterator<InventoryPrinterAdapter> i =
this.usedAdapters.iterator();
- while (i.hasNext())
- {
- final InventoryPrinterAdapter printer = i.next();
- if (format == null || printer.supports(format))
- {
- result.add(printer);
- }
- }
- }
- return result.toArray(new InventoryPrinterHandler[result.size()]);
- }
-
- /**
- * Return a handler for the unique name.
- *
- * @return The corresponding handler or <code>null</code>.
- */
- public InventoryPrinterHandler getHandler(final String name)
- {
- synchronized (this.usedAdapters)
- {
- final Iterator<InventoryPrinterAdapter> i =
this.usedAdapters.iterator();
- while (i.hasNext())
- {
- final InventoryPrinterAdapter printer = i.next();
- if (name.equals(printer.getName()))
- {
- return printer;
- }
- }
- }
- return null;
- }
-}
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
deleted file mode 100644
index b5ace29b4a..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/WebConsolePlugin.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.inventory.impl;
-
-/**
- * The web console plugin for a inventory printer.
- */
-public class WebConsolePlugin extends AbstractWebConsolePlugin
-{
-
- private static final long serialVersionUID = 1L;
-
- /** Printer name. */
- private final String printerName;
-
- /**
- * 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)
- {
- super(inventoryPrinterManager);
- this.printerName = printerName;
- }
-
- protected InventoryPrinterHandler getInventoryPrinterHandler()
- {
- return this.inventoryPrinterManager.getHandler(this.printerName);
- }
-}
\ No newline at end of file
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/ConfigurationWriter.java
b/inventory/src/main/java/org/apache/felix/inventory/impl/helper/ConfigurationWriter.java
deleted file mode 100644
index e3da75106c..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/ConfigurationWriter.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory.impl.helper;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.Writer;
-
-import org.apache.felix.inventory.Format;
-import org.apache.felix.inventory.impl.InventoryPrinterHandler;
-
-/**
- * Base class for all configuration writers.
- */
-public abstract class ConfigurationWriter extends PrintWriter
-{
-
- ConfigurationWriter(final Writer delegatee)
- {
- super(delegatee);
- }
-
- protected void title(final String title) throws IOException
- {
- // dummy implementation
- }
-
- protected void end() throws IOException
- {
- // dummy implementation
- }
-
- public void printInventory(final Format format, final
InventoryPrinterHandler handler) throws IOException
- {
- this.title(handler.getTitle());
- handler.print(this, format, false);
- this.end();
- }
-}
\ No newline at end of file
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/HtmlConfigurationWriter.java
b/inventory/src/main/java/org/apache/felix/inventory/impl/helper/HtmlConfigurationWriter.java
deleted file mode 100644
index 76fef8422b..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/HtmlConfigurationWriter.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory.impl.helper;
-
-import java.io.Writer;
-
-
-/**
- * The HTML configuration writer outputs the status as an HTML snippet.
- */
-public class HtmlConfigurationWriter extends ConfigurationWriter
-{
-
- // whether or not to filter "<" signs in the output
- private boolean doFilter;
-
- public HtmlConfigurationWriter(final Writer delegatee)
- {
- super(delegatee);
- }
-
- public void enableFilter(final boolean doFilter)
- {
- this.doFilter = doFilter;
- if (doFilter) {
- // start filtering
- super.write("<pre>", 0, 5);
- } else {
- // end filtering
- super.write("</pre>", 0, 6);
- }
- super.println();
- }
-
- // 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)
- {
- this.write('\n'); // write <br/>
- }
- 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
- // sure, that everything is escaped correctly
- 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)
- {
- oneChar[0] = (char) character;
- write(oneChar, 0, 1);
- }
- }
-
- // 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)
- {
- chars = this.escapeHtml(new String(chars, off, len)).toCharArray();
- off = 0;
- len = chars.length;
- }
- super.write(chars, off, len);
- }
-
- // 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)
- {
- 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)
- {
- final StringBuffer sb = new StringBuffer(text.length() * 4 / 3);
- char ch, oldch = '_';
- for (int i = 0; i < text.length(); i++)
- {
- switch (ch = text.charAt(i))
- {
- case '<':
- sb.append("<"); //$NON-NLS-1$
- break;
- case '>':
- sb.append(">"); //$NON-NLS-1$
- break;
- case '&':
- sb.append("&"); //$NON-NLS-1$
- break;
- case ' ':
- sb.append(" "); //$NON-NLS-1$
- break;
- case '\r':
- case '\n':
- if (oldch != '\r' && oldch != '\n')
- sb.append("\n"); //$NON-NLS-1$
- break;
- default:
- sb.append(ch);
- }
- oldch = ch;
- }
-
- return sb.toString();
- }
-}
\ No newline at end of file
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/JSONConfigurationWriter.java
b/inventory/src/main/java/org/apache/felix/inventory/impl/helper/JSONConfigurationWriter.java
deleted file mode 100644
index 5900f0d2be..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/JSONConfigurationWriter.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory.impl.helper;
-
-import java.io.Writer;
-import java.util.StringTokenizer;
-
-
-/**
- * The JSON configuration writer
- */
-public class JSONConfigurationWriter extends ConfigurationWriter
-{
- private boolean wrapJSON;
-
- private boolean startLine;
-
- private boolean needComma;
-
- public JSONConfigurationWriter(final Writer delegatee)
- {
- super(delegatee);
- this.wrapJSON = false;
- }
-
- public void startJSONWrapper()
- {
-// println("{");
-// println(" \"value\": [");
- println("[");
-
- this.wrapJSON = true;
- this.startLine = true;
- this.needComma = false;
- }
-
- public void endJSONWrapper()
- {
- if (this.wrapJSON)
- {
- // properly terminate the current line
- this.println();
-
- this.wrapJSON = false;
- this.startLine = false;
-
-// super.println();
-// super.println(" ]");
-// super.println("}");
- super.println("]");
- }
- }
-
- // 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.
- @Override
- public void println()
- {
- if (wrapJSON)
- {
- if (!this.startLine)
- {
- super.write('"');
- this.startLine = true;
- this.needComma = true;
- }
- }
- 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
- // sure, that everything is escaped correctly
- @Override
- 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
- @Override
- public void write(final int character)
- {
- synchronized (oneChar)
- {
- oneChar[0] = (char) character;
- write(oneChar, 0, 1);
- }
- }
-
- // write the characters unmodified unless filtering is enabled
- @Override
- public void write(char[] chars, int off, int len)
- {
- if (this.wrapJSON)
- {
- if (this.startLine)
- {
- this.startLine();
- this.startLine = false;
- }
-
- String v = new String(chars, off, len);
- StringTokenizer st = new StringTokenizer(v, "\r\n\"\\\t\b\f",
true);
- while (st.hasMoreTokens())
- {
- String t = st.nextToken();
- if (t.length() == 1)
- {
- char c = t.charAt(0);
- if (c == '\r' || c == '\f' || c == '\t' || c == '\b')
- {
- // ignore
- }
- else if (c == '\n')
- {
- this.println();
- this.startLine();
- }
- else if (c == '"' || c == '\\')
- {
- super.write('\\');
- super.write(c);
- }
- else
- {
- super.write(c);
- }
- }
- else
- {
- super.write(t.toCharArray(), 0, t.length());
- }
- }
- }
- else
- {
- super.write(chars, off, len);
- }
- }
-
- // write the string unmodified unless filtering is enabled in
- // which case the writeFiltered(String) method is called for filtering
- @Override
- public void write(final String string, final int off, final int len)
- {
- write(string.toCharArray(), off, len);
- }
-
- private void startLine()
- {
- if (this.needComma)
- {
- super.write(',');
- super.println();
- this.needComma = false;
- }
-
- super.write(" \"".toCharArray(), 0, 5);
- this.startLine = false;
- }
-}
\ No newline at end of file
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/PlainTextConfigurationWriter.java
b/inventory/src/main/java/org/apache/felix/inventory/impl/helper/PlainTextConfigurationWriter.java
deleted file mode 100644
index 7e6b5db717..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/PlainTextConfigurationWriter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory.impl.helper;
-
-import java.io.Writer;
-
-
-/**
- * The plain text configuration writer outputs the status as plain text.
- */
-public class PlainTextConfigurationWriter extends ConfigurationWriter
-{
-
- public PlainTextConfigurationWriter(final Writer delegatee)
- {
- super(delegatee);
- }
-
- protected void title(final String title)
- {
- print("*** ");
- print(title);
- println(":");
- }
-
- protected void end()
- {
- println();
- }
-}
\ No newline at end of file
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/SimpleJson.java
b/inventory/src/main/java/org/apache/felix/inventory/impl/helper/SimpleJson.java
deleted file mode 100644
index 6813338c56..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/SimpleJson.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory.impl.helper;
-
-/**
- * The <code>SimpleJson</code> is an extremely simple and very limited
- * helper class to create JSON formatted output. The limits are as follows:
- * <ol>
- * <li>There is no error checking</li>
- * <li>Arrays are always expected to be inside an object</li>
- * <li>At most one level of object nesting is supported</li>
- * <li>Strings are not escaped</li>
- * <li>Only string values are supported</li>
- * </ol>
- */
-class SimpleJson
-{
-
- private StringBuffer index = new StringBuffer();
-
- /*
- * "o" - object; require ";" separator
- * "f" - object; no separator; next "o"
- * "a" - array; require "," separator
- * "i" - array; no separator; next "a"
- */
- private char mode = 0;
-
- SimpleJson object()
- {
- this.index.append('{');
- this.mode = 'f';
- return this;
- }
-
- SimpleJson endObject()
- {
- this.index.append('}');
- this.mode = 'o';
- return this;
- }
-
- SimpleJson array()
- {
- this.index.append('[');
- this.mode = 'i';
- return this;
- }
-
- SimpleJson endArray()
- {
- this.index.append(']');
- this.mode = 'o';
- return this;
- }
-
- SimpleJson key(final String key)
- {
- if (this.mode == 'f')
- {
- this.mode = 'o';
- }
- else if (mode == 'o')
- {
- this.index.append(',');
- }
- this.index.append('"').append(key).append("\":");
- return this;
- }
-
- SimpleJson value(final String value)
- {
- if (this.mode == 'i')
- {
- this.mode = 'a';
- }
- else if (mode == 'a')
- {
- this.index.append(',');
- }
- this.index.append('"').append(value).append('"');
- return this;
- }
-
- public String toString()
- {
- return this.index.toString();
- }
-}
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/ZipConfigurationWriter.java
b/inventory/src/main/java/org/apache/felix/inventory/impl/helper/ZipConfigurationWriter.java
deleted file mode 100644
index c7c15a6f62..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/helper/ZipConfigurationWriter.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory.impl.helper;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.text.DateFormat;
-import java.text.MessageFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.zip.Deflater;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import org.apache.felix.inventory.Format;
-import org.apache.felix.inventory.impl.InventoryPrinterHandler;
-
-/**
- * The ZIP configuration writer creates a zip with
- * - txt output of a inventory printers (if supported)
- * - json output of a inventory printers (if supported)
- * - attachments from a inventory printer (if supported)
- */
-public class ZipConfigurationWriter extends ConfigurationWriter
-{
-
- private final ZipConfigurationWriter.ConfigZipOutputStream zip;
-
- private int entryCounter;
-
- public static ZipConfigurationWriter create(final OutputStream out) throws
IOException
- {
- final ZipConfigurationWriter.ConfigZipOutputStream zip = new
ConfigZipOutputStream(out)
- {
- };
- zip.setLevel(Deflater.BEST_SPEED);
- zip.setMethod(ZipOutputStream.DEFLATED);
-
- return new ZipConfigurationWriter(zip);
- }
-
- private ZipConfigurationWriter(final
ZipConfigurationWriter.ConfigZipOutputStream zip) throws IOException
- {
- super(new OutputStreamWriter(zip, "UTF-8"));
-
- this.zip = zip;
- this.entryCounter = -1;
- }
-
- public void finish() throws IOException
- {
- this.zip.finish();
- }
-
- /**
- * Overwrites the
- * {@link ConfigurationWriter#printInventory(Format,
InventoryPrinterHandler)}
- * method writing the plain text output, the JSON output and any
- * attachements to the ZIP file. The {@code format} argument is ignored.
- *
- * @param formatIgnored Ignored, may be {@code null}.
- * @param handler The handler to be called to generate the output
- *
- * @throws IOException if an error occurrs writing to the ZIP file.
- */
- public void printInventory(final Format formatIgnored, final
InventoryPrinterHandler handler)
- throws IOException
- {
- final String baseName = getBaseName(handler);
-
- this.zip.handler(handler);
-
- // print the plain text output
- if (handler.supports(Format.TEXT))
- {
- final ZipEntry entry = new ZipEntry(baseName.concat(".txt"));
- entry.setTime(System.currentTimeMillis());
- this.zip.putNextEntry(entry, Format.TEXT);
- handler.print(this, Format.TEXT, true);
- this.flush();
- this.zip.closeEntry();
- }
-
- // print the JSON format output
- if (handler.supports(Format.JSON))
- {
- final ZipEntry entry = new ZipEntry("json/" + baseName + ".json");
- entry.setTime(System.currentTimeMillis());
- this.zip.putNextEntry(entry, Format.JSON);
- handler.print(this, Format.JSON, true);
- this.flush();
- this.zip.closeEntry();
- }
-
- // any attachements from the handler
- this.zip.attachements();
- handler.addAttachments(this.zip, baseName.concat("/"));
- this.zip.endAttachements();
-
- this.zip.endHandler();
- }
-
- private String getBaseName(final InventoryPrinterHandler handler)
- {
- final String title = handler.getTitle();
- final StringBuffer name = new StringBuffer(title.length());
- for (int i = 0; i < title.length(); i++)
- {
- char c = title.charAt(i);
- if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A'
&& c <= 'Z'))
- {
- name.append(c);
- }
- else
- {
- name.append('_');
- }
- }
-
- this.entryCounter++;
- return MessageFormat.format("{0,number,000}_{1}", new Object[]
- { new Integer(this.entryCounter), name });
- }
-
- private static class ConfigZipOutputStream extends ZipOutputStream
- {
-
- private final SimpleJson json;
-
- ConfigZipOutputStream(final OutputStream out)
- {
- super(out);
-
- this.json = new SimpleJson();
- this.json.object();
-
- // timestamp in the "created" object
- final Date now = new Date();
- final String nowFormatted =
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.US)
- .format(now);
- this.json.key("created");
- this.json.object();
- this.json.key("date").value(nowFormatted);
- this.json.key("stamp").value(String.valueOf(now.getTime()));
- this.json.endObject();
-
- // output from the printers in the "files" object
- this.json.key("files").object();
- }
-
- void handler(final InventoryPrinterHandler handler)
- {
- this.json.key(handler.getName());
- this.json.object();
- this.json.key("title").value(handler.getTitle());
- }
-
- void endHandler()
- {
- this.json.endObject();
- }
-
- void attachements()
- {
- this.json.key("attachements");
- this.json.array();
- }
-
- void endAttachements()
- {
- this.json.endArray();
- }
-
- void putNextEntry(ZipEntry e, Format format) throws IOException
- {
- this.json.key(format.toString().toLowerCase());
- this.putNextEntry(e);
- }
-
- public void putNextEntry(ZipEntry e) throws IOException
- {
- this.json.value(e.getName());
- super.putNextEntry(e);
- }
-
- public void finish() throws IOException
- {
- // end "files" and root objects
- this.json.endObject().endObject();
-
- final ZipEntry entry = new ZipEntry("index.json");
- entry.setTime(System.currentTimeMillis());
- super.putNextEntry(entry); // don't write the index to the JSON
- this.write(this.json.toString().getBytes("UTF-8"));
- this.flush();
- this.closeEntry();
-
- super.finish();
- }
- }
-}
\ No newline at end of file
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
deleted file mode 100644
index 1ada58e3d6..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.inventory.impl.webconsole;
-
-import java.io.PrintWriter;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.felix.inventory.Format;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Helper class for a configuration printer.
- */
-public class ConfigurationPrinterAdapter
-{
-
- private final Object printer;
- public String title;
- public String label;
- private final String[] modes;
- private final boolean escapeHtml;
- private final Method printMethod;
- 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);
- }
-
- /**
- * Check whether the class implements the configuration printer.
- * This is done manually to avoid having the configuration printer class
- * available.
- */
- 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))
- {
- return true;
- }
- }
- if (clazz.getSuperclass() != null)
- {
- return isConfigurationPrinter(clazz.getSuperclass());
- }
- return false;
- }
-
- /**
- * Try to create a new configuration printer adapter.
- */
- public static ConfigurationPrinterAdapter createAdapter(final Object
service, final ServiceReference ref)
- {
- String title;
- Object modes = null;
- if (isConfigurationPrinter(service.getClass()))
- {
- modes = ref.getProperty(ConsoleConstants.CONFIG_PRINTER_MODES);
- if (modes == null)
- {
- modes = ref.getProperty(ConsoleConstants.PROPERTY_MODES);
- }
- final Method titleMethod = getMethod(service.getClass(),
"getTitle", null, false);
- if (titleMethod == null)
- {
- return null;
- }
- title = (String) 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 = getMethod(service.getClass(),
"printConfiguration", new Class[]
- { PrintWriter.class, String.class }, true);
- if (method2Params != null)
- {
- cfgPrinter = service;
- printMethod = method2Params;
- }
-
- if (cfgPrinter == null)
- {
- // second: printConfiguration(PrintWriter)
- final Method method1Params = getMethod(service.getClass(),
"printConfiguration", new Class[]
- { PrintWriter.class }, true);
- if (method1Params != null)
- {
- cfgPrinter = service;
- printMethod = method1Params;
- }
- }
-
- 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
- {
- webUnescaped = false;
- }
-
- final String[] modesArray;
- // check modes
- 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
- {
- modesArray = null;
- }
- }
- 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]))
- {
- valid = false;
- break;
- }
- }
- if (valid)
- {
- modesArray = values;
- }
- else
- {
- modesArray = null;
- }
- }
- }
-
- return new ConfigurationPrinterAdapter(cfgPrinter, printMethod,
getMethod(cfgPrinter.getClass(),
- "getAttachments", new Class[]
- { String.class }, true), 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)
- {
- this.printer = printer;
- this.title = title;
- this.label = label;
- this.escapeHtml = escapeHtml;
- this.printMethod = printMethod;
- this.attachmentMethod = attachmentMethod;
- this.modes = modesArray;
- }
-
- /**
- * Map the modes to inventory printer modes
- */
- public String[] getPrinterModes()
- {
- final Set list = new HashSet();
- if (this.match(ConsoleConstants.MODE_TXT) ||
this.match(ConsoleConstants.MODE_ZIP))
- {
- list.add(Format.TEXT.toString());
- }
- if (this.match(ConsoleConstants.MODE_WEB))
- {
- if (!escapeHtml)
- {
- list.add(Format.HTML.toString());
- }
- else
- {
- list.add(Format.TEXT.toString());
- }
- }
- return (String[]) list.toArray(new String[list.size()]);
- }
-
- 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))
- {
- return true;
- }
- }
- return false;
- }
-
- public final void printConfiguration(final PrintWriter pw, final String
mode)
- {
- if (printMethod.getParameterTypes().length > 1)
- {
- invoke(this.printer, this.printMethod, new Object[]
- { pw, mode });
- }
- else
- {
- invoke(this.printer, this.printMethod, new Object[]
- { pw });
- }
- }
-
- public URL[] getAttachments()
- {
- // check if printer implements binary configuration printer
- URL[] attachments = null;
- if (attachmentMethod != null)
- {
- attachments = (URL[]) invoke(printer, attachmentMethod, new
Object[]
- { ConsoleConstants.MODE_ZIP });
- }
- return attachments;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- public String toString()
- {
- return title + " (" + printer.getClass() + ")";
- }
-
- private static Method getMethod(final Class clazz, final String mName,
final Class[] params, final boolean declaredByClass)
- {
- try
- {
- if (declaredByClass)
- {
- final Method m = clazz.getDeclaredMethod(mName, params);
- if (Modifier.isPublic(m.getModifiers()))
- {
- return m;
- }
- }
-
- return clazz.getMethod(mName, params);
- }
- catch (Throwable nsme)
- {
- // ignore, we catch Throwable above to not only catch
- // NoSuchMethodException
- // but also other ones like ClassDefNotFoundError etc.
- }
- return null;
- }
-
- /**
- * Invoke the method on the printer with the arguments.
- */
- private static Object invoke(final Object obj, final Method m, final
Object[] args)
- {
- try
- {
- return m.invoke(obj, args);
- }
- catch (final Throwable e)
- {
- // ignore
- }
- return null;
- }
-}
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
deleted file mode 100644
index 452ff08946..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConsoleConstants.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.inventory.impl.webconsole;
-
-public class ConsoleConstants
-{
-
- public static final String DEFAULT_CONTEXT_NAME =
"OsgiManagerDefaultHttpContext"; //$NON-NLS-1$
-
- public static final String INTERFACE_SERVLET = "jakarta.servlet.Servlet";
//$NON-NLS-1$
-
- public static final String INTERFACE_CONFIGURATION_PRINTER =
"org.apache.felix.webconsole.ConfigurationPrinter"; //$NON-NLS-1$
-
- public static final String PLUGIN_LABEL = "felix.webconsole.label";
//$NON-NLS-1$
-
- public static final String PLUGIN_TITLE = "felix.webconsole.title";
//$NON-NLS-1$
-
- public static final String PLUGIN_CATEGORY = "felix.webconsole.category";
//$NON-NLS-1$
-
- public static final String CONFIG_PRINTER_MODES =
"felix.webconsole.configprinter.modes"; //$NON-NLS-1$
-
- public static final String CONFIG_PRINTER_WEB_UNESCAPED =
"felix.webconsole.configprinter.web.unescaped"; //$NON-NLS-1$
-
- public static final String MODE_ALWAYS = "always"; //$NON-NLS-1$
-
- public static final String MODE_WEB = "web"; //$NON-NLS-1$
-
- public static final String MODE_ZIP = "zip"; //$NON-NLS-1$
-
- public static final String MODE_TXT = "txt"; //$NON-NLS-1$
-
- public static final String PROPERTY_MODES = "modes"; //$NON-NLS-1$
-
- public static final String WEB_CONSOLE_CATEGORY = "Status"; //$NON-NLS-1$
-
- public static final String NAME = "config"; //$NON-NLS-1$
-
- public static final String TITLE = "Overview"; //$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
deleted file mode 100644
index ad893cf829..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ResourceBundleManager.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory.impl.webconsole;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.PropertyResourceBundle;
-import java.util.ResourceBundle;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-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,
- * its resources stored in the cache are cleaned up.
- */
-public class ResourceBundleManager implements BundleListener
-{
-
- private final BundleContext bundleContext;
-
- 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)
- {
- this.bundleContext = bundleContext;
- this.resourceBundleCaches = new HashMap();
-
- bundleContext.addBundleListener(this);
- }
-
- /**
- * Removes the bundle lister.
- */
- public void dispose()
- {
- bundleContext.removeBundleListener(this);
- }
-
- /**
- * 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)
- {
- ResourceBundle cache;
- 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);
- }
- }
-
- return cache;
- }
-
- // ---------- BundleListener
-
- /**
- * @see
org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent)
- */
- public final void bundleChanged(BundleEvent event)
- {
- if (event.getType() == BundleEvent.STOPPED)
- {
- final Long key = new Long(event.getBundle().getBundleId());
- synchronized (resourceBundleCaches)
- {
- resourceBundleCaches.remove(key);
- }
- }
- }
-
- private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
-
- 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)
- {
- // ignore
- }
- }
- return null;
- }
-
- // 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)
- {
- file = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
- }
-
- // remove leading slash
- if (file.startsWith("/")) //$NON-NLS-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$
-
- HashMap resourceBundleEntries = new HashMap();
-
- Enumeration locales = bundle.findEntries(path, fileName +
"*.properties", false); //$NON-NLS-1$
- if (locales != null)
- {
- while (locales.hasMoreElements())
- {
- 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 end = entryPath.length() - 11; // .properties suffix
- 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)
- {
- 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);
- }
- }
- }
-
- return resourceBundleEntries;
- }
-}
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
deleted file mode 100644
index 1c35a4a64d..0000000000
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/WebConsoleAdapter.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.inventory.impl.webconsole;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import org.apache.felix.inventory.InventoryPrinter;
-import org.apache.felix.inventory.Format;
-import org.apache.felix.inventory.ZipAttachmentProvider;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-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
-{
-
- private final BundleContext bundleContext;
-
- private final ServiceTracker cfgPrinterTracker;
-
- private final Map registrations = new HashMap();
-
- private final ResourceBundleManager rbManager;
-
- 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.open();
- }
-
- /**
- * Dispose this service
- */
- public void dispose()
- {
- this.cfgPrinterTracker.close();
- final List regs = new ArrayList();
- synchronized (this.registrations)
- {
- regs.addAll(this.registrations.values());
- this.registrations.clear();
- }
- final Iterator i = regs.iterator();
- while (i.hasNext())
- {
- final ServiceRegistration reg = (ServiceRegistration) i.next();
- reg.unregister();
- }
- this.rbManager.dispose();
- }
-
- 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("%"))
- {
- String title = cpa.title.substring(1);
-
- final ResourceBundle rb =
this.rbManager.getResourceBundle(reference.getBundle());
- if (rb != null)
- {
- try
- {
- title = rb.getString(title);
- }
- catch (Exception e)
- {
- // ClassCastException, MissingResourceException
- // ignore
- }
- }
- cpa.title = title;
- }
- if (cpa.label == null)
- {
- cpa.label = cpa.title;
- }
- final Dictionary props = new Hashtable();
- props.put(InventoryPrinter.NAME, cpa.label);
- props.put(InventoryPrinter.TITLE, cpa.title);
- props.put(InventoryPrinter.FORMAT, cpa.getPrinterModes());
-
- 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)
- {
- final ServiceRegistration reg;
- synchronized (this.registrations)
- {
- reg = (ServiceRegistration) this.registrations.remove(reference);
- }
- if (reg != null)
- {
- reg.unregister();
- }
- }
-
- /**
- * @see
org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
- */
- public Object addingService(final ServiceReference reference)
- {
- final Object service = this.bundleContext.getService(reference);
- if (service != null)
- {
- this.add(reference, service);
- }
- return service;
- }
-
- /**
- * @see
org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference,
- * java.lang.Object)
- */
- 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)
- */
- public void removedService(final ServiceReference reference, final Object
service)
- {
- this.remove(reference);
- this.bundleContext.ungetService(reference);
- }
-
- private static class WebConsolePrinter implements InventoryPrinter,
ZipAttachmentProvider
- {
-
- final ConfigurationPrinterAdapter cpa;
-
- public WebConsolePrinter(final ConfigurationPrinterAdapter cpa)
- {
- this.cpa = cpa;
- }
-
- /**
- * @see
org.apache.felix.inventory.InventoryPrinter#print(org.apache.felix.inventory.Format,
- * java.io.PrintWriter)
- */
- public void print(final PrintWriter printWriter, final Format format,
final boolean isZip)
- {
- final String m;
- if (!isZip && format == Format.HTML)
- {
- m = ConsoleConstants.MODE_WEB;
- }
- else if (!isZip && format == Format.TEXT)
- {
- m = ConsoleConstants.MODE_TXT;
- }
- else if (isZip && (format == Format.TEXT || format == Format.HTML))
- {
- m = ConsoleConstants.MODE_ZIP;
- }
- else
- {
- m = null;
- }
- if (m != null)
- {
- cpa.printConfiguration(printWriter, m);
- }
- }
-
- /**
- * @see
org.apache.felix.inventory.ZipAttachmentProvider#addAttachments(java.util.zip.ZipOutputStream,
- * java.lang.String)
- */
- public void addAttachments(final ZipOutputStream zos, final String
namePrefix) throws IOException
- {
- final URL[] attachments = cpa.getAttachments();
- 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)
- {
- // sanity code, we should have a path, but if not let's
- // just create some random name
- 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
- {
- byte[] buffer = new byte[4096];
- int n = 0;
- while (-1 != (n = is.read(buffer)))
- {
- zos.write(buffer, 0, n);
- }
- }
- finally
- {
- if (is != null)
- {
- try
- {
- is.close();
- }
- catch (final IOException ignore)
- {
- }
- }
- }
- zos.closeEntry();
- }
- }
- }
-
- }
-}
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/package-info.java
b/inventory/src/main/java/org/apache/felix/inventory/package-info.java
deleted file mode 100644
index e4f3f93369..0000000000
--- a/inventory/src/main/java/org/apache/felix/inventory/package-info.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * The {@code org.apache.felix.inventory} package exposes the API for
- * the Apache Felix Inventory Printer Framework.
- *
- * @see <a
href="http://felix.apache.org/documentation/subprojects/apache-felix-inventory.html">Apache
Felix Inventory</a>
- * @version 1.0
- */
[email protected]("1.0")
-package org.apache.felix.inventory;
\ No newline at end of file
diff --git a/inventory/src/test/java/org/apache/felix/inventory/FormatTest.java
b/inventory/src/test/java/org/apache/felix/inventory/FormatTest.java
deleted file mode 100644
index 54a00ef95c..0000000000
--- a/inventory/src/test/java/org/apache/felix/inventory/FormatTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory;
-
-import org.junit.Test;
-
-import junit.framework.TestCase;
-
-public class FormatTest
-{
-
- @Test public void test_valueOf()
- {
- TestCase.assertSame(Format.TEXT, Format.valueOf("TEXT"));
- TestCase.assertSame(Format.JSON, Format.valueOf("JSON"));
- TestCase.assertSame(Format.HTML, Format.valueOf("HTML"));
-
- TestCase.assertSame(Format.TEXT, Format.valueOf("text"));
- TestCase.assertSame(Format.JSON, Format.valueOf("json"));
- TestCase.assertSame(Format.HTML, Format.valueOf("html"));
-
- TestCase.assertSame(Format.TEXT, Format.valueOf("Text"));
- TestCase.assertSame(Format.JSON, Format.valueOf("Json"));
- TestCase.assertSame(Format.HTML, Format.valueOf("HtMl"));
-
- TestCase.assertNull(Format.valueOf("unsupported_name"));
- }
-
- @Test public void test_toString()
- {
- TestCase.assertEquals("TEXT", Format.TEXT.toString());
- TestCase.assertEquals("JSON", Format.JSON.toString());
- TestCase.assertEquals("HTML", Format.HTML.toString());
- }
-
- @Test public void test_equals()
- {
- TestCase.assertTrue(Format.TEXT.equals(Format.TEXT));
- TestCase.assertFalse(Format.TEXT.equals(Format.JSON));
- TestCase.assertFalse(Format.TEXT.equals(Format.HTML));
-
- TestCase.assertFalse(Format.JSON.equals(Format.TEXT));
- TestCase.assertTrue(Format.JSON.equals(Format.JSON));
- TestCase.assertFalse(Format.JSON.equals(Format.HTML));
-
- TestCase.assertFalse(Format.HTML.equals(Format.TEXT));
- TestCase.assertFalse(Format.HTML.equals(Format.JSON));
- TestCase.assertTrue(Format.HTML.equals(Format.HTML));
- }
-
-}
diff --git
a/inventory/src/test/java/org/apache/felix/inventory/impl/helper/JSONConfigurationWriterTest.java
b/inventory/src/test/java/org/apache/felix/inventory/impl/helper/JSONConfigurationWriterTest.java
deleted file mode 100644
index 8754b2a99d..0000000000
---
a/inventory/src/test/java/org/apache/felix/inventory/impl/helper/JSONConfigurationWriterTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.inventory.impl.helper;
-
-import java.io.StringWriter;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class JSONConfigurationWriterTest {
-
- @Test public void test_escaping() {
- final StringWriter out = new StringWriter();
- final JSONConfigurationWriter w = new JSONConfigurationWriter(out);
- w.startJSONWrapper();
- w.write("abcd\\\n1\t2\f3\b4\"5end");
- w.endJSONWrapper();
- w.close();
-
- final String expected = "[" + System.lineSeparator()
- + " \"abcd\\\\\"," + System.lineSeparator()
- + " \"1234\\\"5end\"]" + System.lineSeparator();
-
- Assert.assertEquals("Escaped JSON", expected, out.toString());
-
- }
-}