[izpack-changes] r1832 - in izpack-src/trunk/src: doc-ng/XHTML dtd lib/com/izforge/izpack lib/com/izforge/izpack/compiler lib/com/izforge/izpack/panels

noreply at berlios.de noreply at berlios.de
Sat May 12 15:31:09 CEST 2007


Author: aikebah
Date: 2007-05-12 15:30:52 +0200 (Sat, 12 May 2007)
New Revision: 1832

Modified:
   izpack-src/trunk/src/doc-ng/XHTML/node4.html
   izpack-src/trunk/src/dtd/installation.dtd
   izpack-src/trunk/src/lib/com/izforge/izpack/Pack.java
   izpack-src/trunk/src/lib/com/izforge/izpack/compiler/CompilerConfig.java
   izpack-src/trunk/src/lib/com/izforge/izpack/compiler/PackInfo.java
   izpack-src/trunk/src/lib/com/izforge/izpack/panels/ImgPacksPanel.java
Log:
Enabling externalized pack-configurations based on a patch proposed by Syed Khadeer

Modified: izpack-src/trunk/src/doc-ng/XHTML/node4.html
===================================================================
--- izpack-src/trunk/src/doc-ng/XHTML/node4.html	2007-05-11 19:38:20 UTC (rev 1831)
+++ izpack-src/trunk/src/doc-ng/XHTML/node4.html	2007-05-12 13:30:52 UTC (rev 1832)
@@ -656,8 +656,8 @@
 <p>Several panels, such as the license panel and the shortcut panel, require additional data to perform their task. This data is supplied in the form of resources. This section describes how to
 specify them. Take a look at each panel description to see if it might need any resources. Currently, no checks are made to ensure resources needed by any panel have been included. The <tt>
 &lt;resources&gt;</tt> element is not required, and no <tt>&lt;res&gt;</tt> elements are required within.<br />
+The <tt>&lt;resources&gt;</tt> element is the only element besides the <tt>&lt;packs&gt;</tt> element that is taken into consideration in referenced pack-files (see <a href="#packs-element"><tt>&lt;packs&gt;</tt> element</a> for more info)<br />
 </p>
-
 <p>You have to set one <tt>&lt;res&gt;</tt> markup for each resource. Here are the attributes to specify :</p>
 
 <ul>
@@ -705,7 +705,7 @@
 <h2><a name="SECTION00438000000000000000"></a> <a name="packs-element"></a><br />
 The Packs Element <tt>&lt;packs&gt;</tt></h2>
 
-<p>This is a crucial section as it is used to specify the files that need to be installed. The <tt>&lt;packs&gt;</tt> section consists of several <tt>&lt;pack&gt;</tt> tags.</p>
+<p>This is a crucial section as it is used to specify the files that need to be installed. The <tt>&lt;packs&gt;</tt> section consists of several <tt>&lt;pack&gt;</tt> and <tt>&lt;refpack&gt;</tt> tags.</p>
 
 <p>The <tt>&lt;pack&gt;</tt> takes the following attributes :</p>
 
@@ -724,8 +724,9 @@
 this feature will make IzPack take the files on disk instead of from the installer. <i>Please make sure that your relative files paths are correct !</i></li>
 
 <li><tt>id</tt>: this attribute is used to give a unique id to the pack to be used for internationalization.</li>
+<li><tt>packImgId</tt>: this attribute is used to reference a unique resource that represents the pack's image for the ImgPacksPanel. The resource should be defined in the <tt>&lt;resources&gt;</tt> element of the installation XML using the same value for the <tt>id</tt> attribute of the <tt>&lt;res&gt;</tt> element.</li>
 </ul>
-
+<p>The <tt>&lt;refpack&gt;</tt> takes only one attribute <tt>file</tt>, which contains the relative path (from the installation compiler) to an externally defined packs-definition. This external packs definition is a regular IzPack installation XML. However the only elements that are used from that XML file are the <tt>&lt;packs&gt;</tt> and the <tt>&lt;resources&gt;</tt> elements. This enables a model in which a single developer is responsible for maintaining the packs and resources related to the development-package assigned to him. The main install XML references these xml-files to avoid synchronization efforts between the central installation XML and the developer-maintained installer XMLs.
 <h3><a name="SECTION00438100000000000000">Internationalization of the PacksPanel</a></h3>
 
 <p>In order to provide internationalization for the PacksPanel, so that your users can be presented with a different name and description for each language you support, you have to create a file named
@@ -1090,10 +1091,9 @@
 
 <h2><a name="SECTION00445000000000000000">ImgPacksPanel</a></h2>
 
-<p>This is the same as above, but for each panel a different picture is shown to the user. The pictures are specified with the resources <tt>ImgPacksPanel.img.x</tt> where x stands for the pack
-number, the numbers start from 0. Of course it's up to you to specify as many images as needed and with correct numbers. For instance if you have 2 packs <tt>core</tt> and <tt>documentation</tt> (in
-this order), then the resource for <tt>core</tt> will be <tt>ImgPacksPanel.img.0</tt> and the resource for <tt>doc</tt> will be <tt>ImgPacksPanel.img.1</tt>. The supported image formats depend on
-what you JVM supports, but starting from J2SE 1.3, <i>GIF</i>, <i>JPEG</i> and <i>PNG</i> are supported.<br />
+<p>This is the same as above, but for each pack a different picture is shown to the user. The pictures are specified using the packImgId attribute for each pack in the installer XML. The initial image will be the image of the first pack that has a packImgId. The image is updated each time the user (de)selects a pack that has a packImgId. Of course it's up to you to specify an image for each pack in your installation with a unique packImgId. For instance if you have 2 packs <tt>core</tt>  and <tt>documentation</tt> (in
+this order), and you assign both packs a packImgId that is identical to the pack's name then the resource for <tt>core</tt> will be <tt>core</tt> and the resource for <tt>documentation</tt> will be <tt>documentation</tt>. The initially shown image will be the resource  <tt>core</tt>. The supported image formats depend on
+what your client's JVM supports, but starting from J2SE 1.3, <i>GIF</i>, <i>JPEG</i> and <i>PNG</i> are supported.<br />
 </p>
 
 <h2><a name="SECTION00446000000000000000">TargetPanel</a></h2>

Modified: izpack-src/trunk/src/dtd/installation.dtd
===================================================================
--- izpack-src/trunk/src/dtd/installation.dtd	2007-05-11 19:38:20 UTC (rev 1831)
+++ izpack-src/trunk/src/dtd/installation.dtd	2007-05-12 13:30:52 UTC (rev 1832)
@@ -96,10 +96,11 @@
         <!ATTLIST listener jar CDATA #IMPLIED>
 
 <!-- The packs section (indicates the packs to create) -->
-<!ELEMENT packs (pack+)>
+<!ELEMENT packs ((pack|refpack)+)>
     <!ELEMENT pack (description, os*, file*, singlefile*, fileset*, updatecheck?, parsable*, executable*, depends*)>
         <!ATTLIST pack name CDATA #REQUIRED>
         <!ATTLIST pack id CDATA #IMPLIED>
+        <!ATTLIST pack packImgId IDREF #IMPLIED>
         <!ATTLIST pack required (yes|no) #REQUIRED>
         <!ATTLIST pack preselected (yes|no) "yes">
         <!ATTLIST pack os (unix|windows|mac) #IMPLIED>
@@ -157,6 +158,8 @@
       <!ELEMENT updatecheck (include*, exclude*)>
       <!ELEMENT depends EMPTY>
           <!ATTLIST depends packname CDATA #REQUIRED>
+    <!ELEMENT refpack EMPTY>
+        <!ATTLIST refpack file CDATA #REQUIRED>
           
 <!-- Allows the inclusion in the installer or uninstaller of a native library -->
 <!ELEMENT native (os*)>

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/Pack.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/Pack.java	2007-05-11 19:38:20 UTC (rev 1831)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/Pack.java	2007-05-12 13:30:52 UTC (rev 1832)
@@ -90,6 +90,9 @@
     /** The color of the node. This is used for the dependency graph algorithms */
     public int color;
 
+    /** The id to use if we want to obtain this pack's image resource */
+    public String packImgId;
+
     /** white colour */
     public final static int WHITE = 0;
 
@@ -124,6 +127,7 @@
         this.preselected = preselected;
         this.loose = loose;
         this.excludeGroup = excludegroup;
+        this.packImgId = null;
         nbytes = 0;
         color = PackInfo.WHITE;
     }

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/compiler/CompilerConfig.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/compiler/CompilerConfig.java	2007-05-11 19:38:20 UTC (rev 1831)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/compiler/CompilerConfig.java	2007-05-12 13:30:52 UTC (rev 1832)
@@ -8,6 +8,7 @@
  * Copyright 2001 Johannes Lehtinen
  * Copyright 2002 Paul Wilkinson
  * Copyright 2004 Gaganis Giorgos
+ * Copyright 2007 Syed Khadeer / Hans Aikema
  *
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -75,6 +76,7 @@
 import net.n3.nanoxml.StdXMLParser;
 import net.n3.nanoxml.StdXMLReader;
 import net.n3.nanoxml.XMLElement;
+import net.n3.nanoxml.XMLException;
 
 /**
  * A parser for the installer xml configuration. This parses a document
@@ -548,12 +550,36 @@
     protected void addPacks(XMLElement data) throws CompilerException
     {
         notifyCompilerListener("addPacks", CompilerListener.BEGIN, data);
+
+        // the actual adding is delegated to addPacksSingle to enable recursive
+        // parsing of refpack package definitions
+        addPacksSingle(data);
+        
+        compiler.checkDependencies();
+        compiler.checkExcludes();
+
+        notifyCompilerListener("addPacks", CompilerListener.END, data);
+    }
+
+    /**
+     * Add packs and their contents to the installer without checking 
+     * the dependencies and includes.
+     * 
+     * Helper method to recursively add more packs from refpack XML packs definitions
+     * 
+     * @param data The XML data
+     * @throws CompilerException
+     */
+    private void addPacksSingle(XMLElement data) throws CompilerException
+    {
+        notifyCompilerListener("addPacksSingle", CompilerListener.BEGIN, data);
         // Initialisation
         XMLElement root = requireChildNamed(data, "packs");
 
         // at least one pack is required
         Vector packElements = root.getChildrenNamed("pack");
-        if (packElements.isEmpty()) parseError(root, "<packs> requires a <pack>");
+        Vector refPackElements = root.getChildrenNamed("refpack");
+        if (packElements.isEmpty() && refPackElements.isEmpty()) parseError(root, "<packs> requires a <pack> or <refpack>");
 
         File baseDir = new File(basedir);
         
@@ -565,6 +591,7 @@
             // Trivial initialisations
             String name = requireAttribute(el, "name");
             String id = el.getAttribute("id");
+            String packImgId = el.getAttribute("packImgId");
             
             boolean loose = "true".equalsIgnoreCase(el.getAttribute("loose", "false"));
             String description = requireChildNamed(el, "description").getContent();
@@ -602,6 +629,11 @@
                     pack.addInstallGroup(igroup);
                 }
             }
+            
+            // Set the packImgId if specified
+            if (packImgId != null) {
+                pack.setPackImgId(packImgId);
+            }
 
             // We get the parsables list
             Iterator iter = el.getChildrenNamed("parsable").iterator();
@@ -889,10 +921,73 @@
             compiler.addPack(pack);
         }
         
-        compiler.checkDependencies();
-        compiler.checkExcludes();
+        Iterator refPackIter = refPackElements.iterator();
+        while (refPackIter.hasNext())
+        {
+        	XMLElement el = (XMLElement) refPackIter.next();
 
-        notifyCompilerListener("addPacks", CompilerListener.END, data);
+            // get the name of reference xml file
+        	String refFileName = requireAttribute(el, "file");
+        	
+        	// Load the reference XML file
+        	
+        	// Initialises the parser
+            IXMLReader refXMLReader = null;
+            
+            File refXMLFile = new File(refFileName);
+            if (!refXMLFile.isAbsolute()) refXMLFile = new File(basedir, refFileName);
+            if (!refXMLFile.canRead()) {
+                throw new CompilerException("Invalid file: " + refXMLFile);
+            }
+            
+            try
+            {
+            	refXMLReader = new StdXMLReader(new FileInputStream(refXMLFile.getAbsolutePath()));
+            }
+            catch (CompilerException c)
+            {
+            	throw new CompilerException("Compiler exception while reading refXMLFile");
+            }
+            catch (IOException io)
+            {
+            	throw new CompilerException("IOException exception while reading refXMLFile");
+            }
+            
+            StdXMLParser refXMLParser = new StdXMLParser();
+            refXMLParser.setBuilder(new StdXMLBuilder());
+            refXMLParser.setReader(refXMLReader);
+            refXMLParser.setValidator(new NonValidator());
+
+            // We get it
+            XMLElement refXMLData = null;
+            try
+            {
+                refXMLData = (XMLElement) refXMLParser.parse();
+            }
+            catch (XMLException x)
+            {
+                throw new CompilerException("Error parsing installation file", x);
+            }
+            
+            // Now checked the loaded XML file for basic syntax
+            // We check it
+            if (!"installation".equalsIgnoreCase(refXMLData.getName())) {
+                parseError(refXMLData, "this is not an IzPack XML installation file");
+            }
+            if (!VERSION.equalsIgnoreCase(requireAttribute(refXMLData, "version"))) {
+                parseError(refXMLData, "the file version is different from the compiler version");
+            }
+            
+            // Read the properties and perform replacement on the rest of the tree
+            substituteProperties(refXMLData);
+            
+            // call addResources to add the referenced XML resources to this installation
+            addResources(refXMLData);
+            
+            // Recursively call myself to add all packs and refpacks from the reference XML
+            addPacksSingle(refXMLData);
+        }
+        notifyCompilerListener("addPacksSingle", CompilerListener.END, data);
     }
 
     /**
@@ -1465,7 +1560,7 @@
         }
         else
         {
-            throw new CompilerException("Neither install file or text specified");
+            throw new CompilerException("Neither install file nor text specified");
         }
 
         StdXMLParser parser = new StdXMLParser();
@@ -1487,7 +1582,7 @@
         // We check it
         if (!"installation".equalsIgnoreCase(data.getName()))
             parseError(data, "this is not an IzPack XML installation file");
-        if (!requireAttribute(data, "version").equalsIgnoreCase(VERSION))
+        if (!VERSION.equalsIgnoreCase(requireAttribute(data, "version")))
             parseError(data, "the file version is different from the compiler version");
 
         // We finally return the tree
@@ -1976,7 +2071,7 @@
     private static String resolveIzPackHome(String home)
     {
         File test = new File(home, IZ_TEST_SUBDIR + File.separator + IZ_TEST_FILE);
-        if( test != null && test.exists())
+        if(test.exists())
             return( home);
         // Try to resolve the path using compiler.jar which also should be under
         // IZPACK_HOME.

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/compiler/PackInfo.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/compiler/PackInfo.java	2007-05-11 19:38:20 UTC (rev 1831)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/compiler/PackInfo.java	2007-05-12 13:30:52 UTC (rev 1832)
@@ -293,4 +293,9 @@
     {
         return pack.name;
     }
+
+    public void setPackImgId(String packImgId)
+    {
+        pack.packImgId = packImgId;
+    }
 }

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/ImgPacksPanel.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/ImgPacksPanel.java	2007-05-11 19:38:20 UTC (rev 1831)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/ImgPacksPanel.java	2007-05-12 13:30:52 UTC (rev 1832)
@@ -29,7 +29,7 @@
 import java.awt.GridBagLayout;
 import java.awt.Insets;
 import java.net.URL;
-import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 
 import javax.swing.BorderFactory;
@@ -39,6 +39,7 @@
 import javax.swing.JScrollPane;
 import javax.swing.event.ListSelectionEvent;
 
+import com.izforge.izpack.Pack;
 import com.izforge.izpack.installer.InstallData;
 import com.izforge.izpack.installer.InstallerFrame;
 import com.izforge.izpack.installer.ResourceManager;
@@ -63,7 +64,7 @@
     private static final long serialVersionUID = 3977858492633659444L;
 
     /** The images to display. */
-    private ArrayList images;
+    private HashMap images;
 
     /** The img label. */
     private JLabel imgLabel;
@@ -109,7 +110,19 @@
         packsTable = createPacksTable(250, tableScroller, layout, gbConstraints);
 
         // Create the image label with a scroller.
-        imgLabel = new JLabel((ImageIcon) images.get(0));
+        // Use the image of the first pack having an image as initial image
+        Iterator pack_it = idata.availablePacks.iterator();
+        Pack firstImgPack = null;
+        boolean imgFound = false;
+        while ( !imgFound && pack_it.hasNext()) {
+        	firstImgPack = (Pack) pack_it.next();
+        	imgFound = firstImgPack.packImgId != null;
+        }
+        if (imgFound) {
+        	imgLabel = new JLabel((ImageIcon) images.get(firstImgPack.packImgId));
+        } else {
+        	imgLabel = new JLabel();
+        }
         JScrollPane imgScroller = new JScrollPane(imgLabel);
         imgScroller.setPreferredSize(getPreferredSizeFromImages());
         parent.buildConstraints(gbConstraints, 1, 1, 1, 1, 0.5, 1.0);
@@ -159,18 +172,24 @@
     private void preLoadImages()
     {
         int size = idata.availablePacks.size();
-        images = new ArrayList(size);
-        for (int i = 0; i < size; i++)
-            try
-            {
-                URL url = ResourceManager.getInstance().getURL("ImgPacksPanel.img." + i);
-                ImageIcon img = new ImageIcon(url);
-                images.add(img);
+        images = new HashMap(size);
+        Iterator pack_it = idata.availablePacks.iterator();
+        while (pack_it.hasNext())
+        {
+            Pack pack = (Pack) pack_it.next();
+            if (pack.packImgId != null) {
+                try
+                {
+                    URL url = ResourceManager.getInstance().getURL(pack.packImgId);
+                    ImageIcon img = new ImageIcon(url);
+                    images.put(pack.packImgId, img);
+                }
+                catch (Exception err)
+                {
+                    err.printStackTrace();
+                }
             }
-            catch (Exception err)
-            {
-                err.printStackTrace();
-            }
+        }
     }
 
     /**
@@ -183,7 +202,7 @@
         int maxHeight = 60;
         ImageIcon icon;
 
-        for (Iterator it = images.iterator(); it.hasNext();)
+        for (Iterator it = images.values().iterator(); it.hasNext();)
         {
             icon = (ImageIcon) it.next();
             maxWidth = Math.max(maxWidth, icon.getIconWidth());
@@ -203,10 +222,18 @@
      */
     public void valueChanged(ListSelectionEvent e)
     {
+        // this MUST be called before calling the super's valueChanged() since
+        // that method refreshes the tablemodel and thus deselects the 
+        // just selected row
+        int i = packsTable.getSelectedRow(); 
         super.valueChanged(e);
-        int i = packsTable.getSelectedRow();
-        if (i >= 0) imgLabel.setIcon((ImageIcon) images.get(i));
-
+        if (i < 0) {
+            return;
+        }
+        if (i >= 0) {
+            Pack pack = (Pack) idata.availablePacks.get(i);
+            imgLabel.setIcon((ImageIcon) images.get(pack.packImgId));
+        }
     }
 
 }




More information about the izpack-changes mailing list