[izpack-changes] r185 - in izpack-frontend/trunk/src: izpack/frontend/view/stages/configure/panels utils

gumbo at BerliOS gumbo at berlios.de
Wed Jan 25 02:55:57 CET 2006


Author: gumbo
Date: 2006-01-25 02:55:39 +0100 (Wed, 25 Jan 2006)
New Revision: 185

Added:
   izpack-frontend/trunk/src/izpack/frontend/view/stages/configure/panels/JDKPath.java
Modified:
   izpack-frontend/trunk/src/utils/XML.java
Log:
Added JDKPathPanel editor

Added: izpack-frontend/trunk/src/izpack/frontend/view/stages/configure/panels/JDKPath.java
===================================================================
--- izpack-frontend/trunk/src/izpack/frontend/view/stages/configure/panels/JDKPath.java	2006-01-17 20:02:47 UTC (rev 184)
+++ izpack-frontend/trunk/src/izpack/frontend/view/stages/configure/panels/JDKPath.java	2006-01-25 01:55:39 UTC (rev 185)
@@ -0,0 +1,129 @@
+/*
+ * Created on Jan 24, 2006
+ * 
+ * $Id: JDKPath.java Feb 8, 2004 izpack-frontend
+ * Copyright (C) 2005 Andy Gombos
+ * 
+ * File : JDKPath.java 
+ * Description : TODO Add description
+ * Author's email : gumbo at users.berlios.de
+ * 
+ * Licensed 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 izpack.frontend.view.stages.configure.panels;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JTextField;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import utils.XML;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+
+/**
+ * Simple panel for JDK finding - set the minimum versions and stuff
+ * @author Andy Gombos
+ */
+public class JDKPath extends JPanel implements ConfigurePanel
+{
+    public JDKPath()
+    {
+        FormLayout layout = new FormLayout("pref, 5dlu, pref, 5dlu, pref", "pref, 5dlu, pref, 10dlu, pref");
+        DefaultFormBuilder builder = new DefaultFormBuilder(layout, this);
+        
+        CellConstraints cc = new CellConstraints();
+        
+        builder.add(new JLabel("Minimum JDK Version:"), cc.xy(1, 1));
+        builder.add(minVer = new JTextField(6),         cc.xyw(3, 1, 3));        
+        
+        builder.add(new JLabel("Maximum JDK Version:"), cc.xy(1, 3));
+        builder.add(maxVer = new JTextField(6),         cc.xyw(3, 3, 3));                
+        
+        builder.add(new JLabel("Display panel if a JDK exists"), cc.xy(1, 5));
+        builder.add(yes = new JRadioButton("Yes"),               cc.xy(3, 5));
+        builder.add(no = new JRadioButton("No"),                 cc.xy(5, 5));
+        builder.nextLine();
+        
+        ButtonGroup bg = new ButtonGroup();
+        bg.add(yes);
+        bg.add(no);
+    }
+    
+    public Element createXML(Document doc)
+    {
+        Element root = XML.createElement("variables", doc);
+        
+        //Skip if JDK valid
+        Element skipIfValid = XML.createElement("variable", doc);
+        skipIfValid.setAttribute("name", "JDKPathPanel.skipIfValid");
+        if (yes.isSelected())
+            skipIfValid.setAttribute("value", "yes");
+        else
+            skipIfValid.setAttribute("value", "no");
+        
+        root.appendChild(skipIfValid);
+        
+        //Min version
+        Element minVerElem = XML.createElement("variable", doc);
+        minVerElem.setAttribute("name", "JDKPathPanel.minVersion");
+        minVerElem.setAttribute("value", minVer.getText());
+        root.appendChild(minVerElem);
+        
+        //Max version
+        Element maxVerElem = XML.createElement("variable", doc);
+        maxVerElem.setAttribute("name", "JDKPathPanel.maxVersion");
+        maxVerElem.setAttribute("value", maxVer.getText());
+        root.appendChild(maxVerElem);
+        
+        return root;
+    }
+
+    public void initFromXML(Document xmlFile)
+    {
+        //Load variables. Some may be null
+        String minVerStr = XML.getVariable(xmlFile, "JDKPathPanel.minVersion");
+        String maxVerStr = XML.getVariable(xmlFile, "JDKPathPanel.maxVersion");
+        String skip      = XML.getVariable(xmlFile, "JDKPathPanel.skipIfValid");
+
+        if (minVerStr != null)
+            minVer.setText(minVerStr);
+        
+        if (maxVerStr != null)
+            maxVer.setText(maxVerStr);        
+        
+        if (skip != null)
+        {
+            skip = skip.toLowerCase();
+            
+            //Skip
+            if (skip.equals("yes") || skip.equals("true"))
+                yes.setSelected(true);
+            //Don't skip            
+            else
+                no.setSelected(true);                
+        }
+    }
+    
+    JTextField minVer, maxVer;
+    JRadioButton yes, no;
+    //TODO I don't know if this needs to be internationalized
+    JLabel dotLabel = new JLabel(".");
+}

Modified: izpack-frontend/trunk/src/utils/XML.java
===================================================================
--- izpack-frontend/trunk/src/utils/XML.java	2006-01-17 20:02:47 UTC (rev 184)
+++ izpack-frontend/trunk/src/utils/XML.java	2006-01-25 01:55:39 UTC (rev 185)
@@ -190,19 +190,11 @@
      * @return Value of the src attribute 
      */
     public static String getResourceValue(Document document, String id) 
-    {
-        XPath xpath = XPathFactory.newInstance().newXPath();
+    {        
         try
         {            
-            //Search only for the <res> element we are interested in
-            NodeList resource = (NodeList) xpath.evaluate("//res[@id='" + id + "']", document, XPathConstants.NODESET);
-            
-            if (resource.getLength() == 1)
-            {
-                String filename = xpath.evaluate("//res[1]/@src", resource.item(0));               
-             
-                return filename;
-            }
+            //Use XPath to return the resource value by searching with it
+            return xpath.evaluate("//res[@id='" + id + "']/@src", document);            
         }
         catch (XPathExpressionException xpee)
         {
@@ -239,6 +231,35 @@
 	    return root;
     }
     
+    /**
+     * Structure:
+     * <variables>
+     *  <variable name="" value="">
+     * </variables>
+     *
+     * Parse a full install xml file to load a specified variable. Does not handle multiple variables with
+     * the same name
+     * 
+     * @param document The XML document
+     * @param id The variable name to look for
+     * @return Value of the src attribute 
+     */
+    public static String getVariable(Document document, String id) 
+    {        
+        try
+        {   
+            //Find the variable and return it's value
+            return xpath.evaluate("//variable[@name='" + id + "']/@value", document);
+        }
+        catch (XPathExpressionException xpee)
+        {
+            //Chances are, this is because the resource is missing
+            //Therefore, just give a null return value
+        } 
+        
+        return null;
+    }
+    
     public static Element createRootElement(String name)
     {
         Document doc = getNewDocument();
@@ -268,4 +289,5 @@
     }
     
     private static Document doc;
+    private static XPath xpath = XPathFactory.newInstance().newXPath();
 }




More information about the izpack-changes mailing list