|
Glassfish example source code file (UpdateCenterHandlers.java)
The Glassfish UpdateCenterHandlers.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.glassfish.uc.admingui; import java.io.File; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.SocketAddress; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.logging.Level; import java.util.Map; import java.util.Properties; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import com.sun.jsftemplating.annotation.Handler; import com.sun.jsftemplating.annotation.HandlerOutput; import com.sun.jsftemplating.annotation.HandlerInput; import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext; import com.sun.pkg.client.Image; import com.sun.pkg.client.Fmri; import com.sun.pkg.client.LicenseAction; import com.sun.pkg.client.Manifest; import com.sun.pkg.client.SystemInfo; import com.sun.pkg.client.SystemInfo.UpdateCheckFrequency; import com.sun.pkg.client.Version; import javax.servlet.http.HttpSession; import org.glassfish.admingui.common.util.GuiUtil; /** * * @author anilam */ public class UpdateCenterHandlers { @Handler(id="checkConnectionInfo", output={ @HandlerOutput(name="connectionInfo", type=String.class), @HandlerOutput(name="noConnection", type=String.class)}) public static void checkConnectionInfo(HandlerContext handlerCtx) { if (Boolean.TRUE.equals(GuiUtil.getSessionValue("_noNetwork"))){ handlerCtx.setOutputValue("connectionInfo", GuiUtil.getMessage(BUNDLE, "noNetworkDetected")); handlerCtx.setOutputValue("noConnection", "true"); } /* else if ("true".equals(GuiUtil.getSessionValue("_doNotPing"))){ handlerCtx.setOutputValue("connectionInfo", GuiUtil.getMessage(BUNDLE, "noCheckPerformed")); handlerCtx.setOutputValue("noConnection", "true"); } */ else{ handlerCtx.setOutputValue("noConnection", "false"); } } @Handler(id="getInstalledPath", output={ @HandlerOutput(name="result", type=String.class)}) public static void getInstalledPath(HandlerContext handlerCtx) { Image image = getUpdateCenterImage(); handlerCtx.setOutputValue("result", (image == null) ? GuiUtil.getMessage(BUNDLE, "updateCenter.NoImageDirectory") : image.getRootDirectory()); } @Handler(id="getAuthority", output={ @HandlerOutput(name="result", type=String.class)}) public static void getAuthority(HandlerContext handlerCtx) { Image image = getUpdateCenterImage(); handlerCtx.setOutputValue("result", (image == null) ? "" : image.getPreferredAuthorityName()); } @Handler(id="getPkgDetailsInfo", input={ @HandlerInput(name="fmriStr", type=String.class, required=true ), @HandlerInput(name="auth", type=String.class, required=true )}, output={ @HandlerOutput(name="details", type=java.util.Map.class)}) public static void getPkgDetailsInfo(HandlerContext handlerCtx) { String fmriStr = (String)handlerCtx.getInputValue("fmriStr"); //Called by the intiPage and don't need to process. When we can use beforeCreate to do this, we can remove this check. if (fmriStr == null){ handlerCtx.setOutputValue("details", new HashMap()); return; } Fmri fmri = new Fmri(fmriStr); Map details = new HashMap(); Image img = getUpdateCenterImage(); try{ details.put("pkgName", fmri.getName()); details.put("uid", fmri.toString()); details.put("version", getPkgVersion(fmri.getVersion())); details.put("date", fmri.getVersion().getPublishDate()); details.put("auth", (String) handlerCtx.getInputValue("auth")); details.put("url", fmri.getURLPath()); if (img != null){ Manifest manifest = img.getManifest(fmri); details.put("category", getCategory(manifest)); details.put("bytes", "" + manifest.getPackageSize() ); details.put("pkgSize", getPkgSize(manifest)); // look for description in the following order: // pkg.description, description_long, pkg.summary, description // since description_long and description has been deprecated. String desc = manifest.getAttribute(PKG_DESC); if (GuiUtil.isEmpty(desc)){ desc = manifest.getAttribute(DESC_LONG); if (GuiUtil.isEmpty(desc)){ desc = manifest.getAttribute(PKG_SUMMARY); if (GuiUtil.isEmpty(desc)) desc = manifest.getAttribute(DESC); } } details.put("desc", desc); } }catch(Exception ex){ ex.printStackTrace(); } handlerCtx.setOutputValue("details", details); } private static String getCategory(Manifest manifest){ String attr = manifest.getAttribute(CATEGORY); //attr is of the form scheme:catgory refer to issue# 8494. int index = attr.indexOf(":"); return (index==-1) ? attr : attr.substring(index+1); } @Handler(id="getUcList", input={ @HandlerInput(name="state", type=String.class, required=true )}, output={ @HandlerOutput(name="result", type=java.util.List.class)}) public static void getUcList(HandlerContext handlerCtx) { List result = new ArrayList(); if (Boolean.TRUE.equals(GuiUtil.getSessionValue("_noNetwork"))){ handlerCtx.setOutputValue("result", result); return; } try { Image img = getUpdateCenterImage(); if (img == null){ handlerCtx.setOutputValue("result", result); return; } String state= (String)handlerCtx.getInputValue("state"); if (state.equals("update")){ handlerCtx.setOutputValue("result", getUpdateDisplayList(img, false)); return; } List<Fmri> displayList = null; if (state.equals("installed")) displayList = getInstalledList(img); else if (state.equals("addOn")) displayList = getAddOnList(img); for (Fmri fmri : displayList){ Map oneRow = new HashMap(); try{ Manifest manifest = img.getManifest(fmri); oneRow.put("selected", false); oneRow.put("fmri", fmri); oneRow.put("fmriStr", fmri.toString()); putInfo(oneRow, "pkgName", fmri.getName()); putInfo(oneRow, "version", getPkgVersion(fmri.getVersion())); putInfo(oneRow, "newVersion", ""); putInfo(oneRow, "category", getCategory(manifest)); putInfo(oneRow, "pkgSize", getPkgSize(manifest)); oneRow.put( "size", Integer.valueOf(manifest.getPackageSize())); putInfo(oneRow, "auth", fmri.getAuthority()); String tooltip = manifest.getAttribute(PKG_SUMMARY); if (GuiUtil.isEmpty(tooltip)) tooltip = manifest.getAttribute(DESC); putInfo(oneRow, "tooltip", tooltip); result.add(oneRow); }catch(Exception ex){ GuiUtil.getLogger().info("getUcList(): " + ex.getLocalizedMessage()); if (GuiUtil.getLogger().isLoggable(Level.FINE)){ ex.printStackTrace(); } } } }catch(Exception ex1){ GuiUtil.getLogger().info("getUcList(): " + ex1.getLocalizedMessage()); if (GuiUtil.getLogger().isLoggable(Level.FINE)){ ex1.printStackTrace(); } } handlerCtx.setOutputValue("result", result); } @Handler(id="getAuthList", output={ @HandlerOutput(name="result", type=java.util.List.class)}) public static void getAuthList(HandlerContext handlerCtx) { List result = new ArrayList(); try { Image image = getUpdateCenterImage(); if (image == null){ handlerCtx.setOutputValue("result", result); return; } String[] auths = image.getAuthorityNames(); for(int i=0; i< auths.length; i++){ Map oneRow = new HashMap(); oneRow.put("authName", auths[i]); result.add(oneRow); } }catch(Exception ex1){ ex1.printStackTrace(); } handlerCtx.setOutputValue("result", result); } @Handler(id="getProxyInfo", output={ @HandlerOutput(name="connection", type=String.class), @HandlerOutput(name="host", type=String.class), @HandlerOutput(name="port", type=String.class)} ) public static void getProxyInfo(HandlerContext handlerCtx) { Proxy proxy = SystemInfo.getProxy(); if (proxy != null){ InetSocketAddress address = (InetSocketAddress) proxy.address(); if (address != null){ handlerCtx.setOutputValue("connection", "useProxy"); handlerCtx.setOutputValue("host", address.getHostName()); handlerCtx.setOutputValue("port", address.getPort()); return; } } handlerCtx.setOutputValue("connection", "direct"); handlerCtx.setOutputValue("host", ""); handlerCtx.setOutputValue("port", ""); } @Handler(id="setProxyInfo", input={ @HandlerInput(name="connection", type=String.class), @HandlerInput(name="host", type=String.class), @HandlerInput(name="port", type=String.class)} ) public static void setProxyInfo(HandlerContext handlerCtx) { String connection = (String)handlerCtx.getInputValue("connection"); String host = (String)handlerCtx.getInputValue("host"); String port = (String)handlerCtx.getInputValue("port"); try{ Image image = getUpdateCenterImage(); if (connection.equals("useProxy")){ int portNo = Integer.parseInt(port); SocketAddress address = new InetSocketAddress(host, portNo); image.setProxy(new Proxy(Proxy.Type.HTTP, address)); String url="http://"+host+":"+portNo; Properties prop = new Properties(); prop.setProperty("proxy.URL", url); SystemInfo.initUpdateToolProps(prop); }else{ image.setProxy(null); Properties prop = new Properties(); prop.setProperty("proxy.URL", ""); SystemInfo.initUpdateToolProps(prop); } }catch (Exception ex){ GuiUtil.handleException(handlerCtx, ex); } } private static void putInfo( Map oneRow, String key, String value){ oneRow.put( key, GuiUtil.isEmpty(value) ? "" : value); } private static List<Fmri> getInstalledList(Image image){ List<Image.FmriState> fList = image.getInventory(null, false); ArrayList<Fmri> result = new ArrayList(); for(Image.FmriState fs: fList){ result.add(fs.fmri); } return result; } private static List<Fmri> getAddOnList(Image image){ List<String> installed = new ArrayList Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish UpdateCenterHandlers.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.