KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdic > packager > impl > JnlpUtility


1 /*
2  * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
3  * subject to license terms.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the Lesser GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  */

20
21 package org.jdesktop.jdic.packager.impl;
22
23 /**
24  * This utility class provides methods used or shared by other classes.
25  */

26 public class JnlpUtility {
27     /**
28      * Script to check if Java Web Start 1.5 is available on Linux/Solaris.
29      * <p>
30      * For PKG/Solaris, this script is written into checkinstall information
31      * file.
32      * <p>
33      * For RPM/Linux, this script is written into .spec file.
34      * @return String array containg the generated script.
35      */

36     public static String JavaDoc[] javawsCheckScript() {
37         String JavaDoc[] javawscheckscript = {
38             "#!/bin/sh",
39             "# Check the existence of javaws 1.5 or later under $PATH.",
40             "echo_error()",
41             "{",
42             " echo \"Error: incorrect javaws version.\"",
43             " echo \"Please install javaws 1.5 or later and set it as the helper application for the Mime type\"",
44             " echo \"\\\"application/x-java-jnlp-file\\\" in /etc/mailcap file. Then try the installation again.\"",
45             " exit 3",
46             "}",
47             "",
48             "JNLP_ASSOCIATION=`grep '^[^#]*application/x-java-jnlp-file' /etc/mailcap`",
49             "if [ $? -ne 0 ]",
50             "then",
51             " echo \"ERROR: script line 'type javaws 2>&1' returns non-zero value.\"",
52             "else",
53             " JAVAWS_PATH=`echo $JNLP_ASSOCIATION | awk -F\\; '{print $2}' | awk '{print $1}'`",
54             "fi",
55             "",
56             "PARENT_DIR=`echo ${JAVAWS_PATH} | awk -F\\/ '{for (i=2; i<NF; i++) printf \"/%s\", $i}'`",
57             "if [ -h ${JAVAWS_PATH} ]",
58             "then",
59             " LS_RESULT=`ls -l ${JAVAWS_PATH} 2>&1`",
60             " LINK_TARGET=`echo ${LS_RESULT} | awk '{printf \"%s\", $NF}'`",
61             " LINK_TARGET_BEGIN=`echo ${LINK_TARGET} | awk '{printf \"%s\", $1}'`",
62             " if [ ${LINK_TARGET_BEGIN}/ = \"/\" ]",
63             " then",
64             " PARENT_DIR=`echo ${LINK_TARGET} | awk -F\\/ '{for (i=2; i<NF; i++) printf \"/%s\", $i}'`",
65             " JAVA_PATH=${PARENT_DIR}/java",
66             " else",
67             " JAVA_PARENT_DIR=`echo ${PARENT_DIR}/${LINK_TARGET} | awk -F\\/ '{for (i=2; i<NF; i++) printf \"/%s\", $i}'`",
68             " JAVA_PATH=${JAVA_PARENT_DIR}/java",
69             " fi",
70             "else",
71             " JAVA_PATH=${PARENT_DIR}/java",
72             "fi",
73             "",
74             "if [ -f ${JAVA_PATH} ]",
75             "then",
76             " java_ver=`${JAVA_PATH} -version 2>&1 | awk -F\\\" '{print $2}' `",
77             " minor=`echo $java_ver | awk -F\\. '{print $2}'`",
78             " if [ ${minor} -lt 5 ]",
79             " then",
80             " echo_error",
81             " fi",
82             "else",
83             " echo_error",
84             "fi"
85         };
86
87         return javawscheckscript;
88     }
89
90     /**
91      * Evaluate if current platform is the matching platform for the running
92      * package generator.
93      * @param osName The matching platform name.
94      */

95     public static void checkPlatformCompatibility(String JavaDoc osName) {
96         String JavaDoc sysOSName = System.getProperty("os.name").toLowerCase();
97         if (!sysOSName.startsWith(osName)) {
98             System.out.println(
99                 "Error: " + "This tool doesn't support this platform.");
100             System.exit(0);
101             return;
102         }
103     }
104 }
105
Popular Tags