ProductInfoConsolePlugin.java 5.78 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.servlet.Servlet
 *  javax.servlet.http.HttpServletRequest
 *  javax.servlet.http.HttpServletResponse
 *  org.apache.commons.lang3.StringEscapeUtils
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.ConfigurationPolicy
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.felix.webconsole.BrandingPlugin
 *  org.apache.felix.webconsole.ConfigurationPrinter
 *  org.apache.felix.webconsole.SimpleWebConsolePlugin
 *  org.osgi.framework.Version
 */
package com.adobe.granite.license.impl;

import com.adobe.granite.license.License;
import com.adobe.granite.license.ProductInfo;
import com.adobe.granite.license.ProductInfoService;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.webconsole.BrandingPlugin;
import org.apache.felix.webconsole.ConfigurationPrinter;
import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.osgi.framework.Version;

@Component(policy=ConfigurationPolicy.IGNORE)
@Service(value={Servlet.class, BrandingPlugin.class, ConfigurationPrinter.class})
public class ProductInfoConsolePlugin
extends SimpleWebConsolePlugin
implements BrandingPlugin,
ConfigurationPrinter {
    @Property(name="felix.webconsole.label")
    private static final String LABEL = "productinfo";
    @Property(name="felix.webconsole.title")
    private static final String TITLE = "Product Information";
    @Reference
    private ProductInfoService productInfo;

    public ProductInfoConsolePlugin() {
        super("productinfo", "Product Information", null);
    }

    protected void renderContent(HttpServletRequest req, HttpServletResponse res) throws IOException {
        License license = this.productInfo.getLicense();
        ProductInfo[] infos = this.productInfo.getInfos();
        PrintWriter pw = res.getWriter();
        Object[] arrobject = new Object[1];
        arrobject[0] = infos == null || infos.length == 0 ? "None" : Integer.valueOf(infos.length);
        pw.printf("<p class='statline ui-state-highlight'>Installed Products: %s</p>%n", arrobject);
        pw.println("<table class='nicetable ui-widget'>");
        pw.printf("<tr><th colspan='2' class='ui-widget-header'>License</th></tr>", new Object[0]);
        if (license != null) {
            pw.printf("<tr><td>Customer</td><td>%s</td></tr>", StringEscapeUtils.escapeHtml4((String)license.getCustomerName()));
            pw.printf("<tr><td>Download ID</td><td>%s</td></tr>", license.getDownloadId());
            pw.printf("<tr><td>Product</td><td>%s (%s)</td></tr>", license.getProductName(), license.getProductVersion());
        } else {
            pw.printf("<tr><td colspan='2'>No License configured !</td></tr>", new Object[0]);
        }
        pw.println("</table>");
        pw.println("<p>&nbsp;</p>");
        pw.println("<table class='nicetable ui-widget'>");
        pw.printf("<tr><th class='ui-widget-header'>Installed Products</th></tr>", new Object[0]);
        if (infos == null) {
            pw.printf("<tr><td>None</td></tr>", new Object[0]);
        } else {
            for (ProductInfo info : infos) {
                pw.printf("<tr><td>%s (%s)</td></tr>", new Object[]{info.getName(), info.getVersion()});
            }
        }
        pw.println("</table>");
    }

    public void printConfiguration(PrintWriter pw) {
        License license = this.productInfo.getLicense();
        pw.println("License");
        pw.printf("  Customer: %s%n", license.getCustomerName());
        pw.printf("  Download ID: %s%n", license.getDownloadId());
        pw.printf("  Product : %s (%s)%n", license.getProductName(), license.getProductVersion());
        pw.println();
        pw.println("Installed Products");
        ProductInfo[] infos = this.productInfo.getInfos();
        if (infos == null) {
            pw.printf("None%n", new Object[0]);
        } else {
            for (ProductInfo info : infos) {
                pw.printf("  %s (%s)%n", new Object[]{info.getName(), info.getVersion()});
            }
        }
    }

    public String getBrandName() {
        ProductInfo[] infos = this.productInfo.getInfos();
        return infos != null && infos.length > 0 ? infos[0].getName() + " Web Console" : "Web Console";
    }

    public String getProductName() {
        return this.getBrandName();
    }

    public String getProductURL() {
        return "http://www.adobe.com";
    }

    public String getProductImage() {
        return "/" + this.getLabel() + "/res/granite/logo.gif";
    }

    public String getVendorName() {
        return "Adobe Systems";
    }

    public String getVendorURL() {
        return "http://www.adobe.com";
    }

    public String getVendorImage() {
        return "/" + this.getLabel() + "/res/granite/logo.gif";
    }

    public String getFavIcon() {
        return "/" + this.getLabel() + "/res/granite/favicon.ico";
    }

    public String getMainStyleSheet() {
        return "/" + this.getLabel() + "/res/granite/webconsole.css";
    }

    protected void bindProductInfo(ProductInfoService productInfoService) {
        this.productInfo = productInfoService;
    }

    protected void unbindProductInfo(ProductInfoService productInfoService) {
        if (this.productInfo == productInfoService) {
            this.productInfo = null;
        }
    }
}