View Javadoc
1 /*** 2 * PerspectiveReader.java 3 * Project: Dependency Tool 4 * 5 * Copyright 2003 ELCA Informatique SA 6 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 7 * www.elca.ch 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public License 11 * as published by the Free Software Foundation; either version 2.1 of 12 * the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 22 * USA 23 */ 24 25 package dptool.config; 26 27 import java.io.File; 28 import java.util.HashMap; 29 import java.util.Iterator; 30 import java.util.List; 31 import java.util.Vector; 32 33 import javax.swing.filechooser.FileFilter; 34 import javax.swing.JFileChooser; 35 36 import org.jdom.Document; 37 import org.jdom.Element; 38 import org.jdom.input.SAXBuilder; 39 40 /*** 41 * Describe class <code>PerspectiveReader</code> here. 42 * 43 * @author Peter Moosmann 44 * @version 0.1-alpha 45 * @version $Id$ 46 */ 47 public class PerspectiveReader 48 { 49 public File getPerspectiveFile() 50 { 51 JFileChooser chooser = new JFileChooser(); 52 chooser.setFileFilter(new XmlFileFilter()); 53 chooser.showOpenDialog(null); 54 55 return chooser.getSelectedFile(); 56 } 57 58 public class XmlFileFilter extends FileFilter 59 { 60 public boolean accept(File file) 61 { 62 return (file.isDirectory() || file.getName().endsWith(".xml")); 63 } 64 public String getDescription() 65 { 66 return "Perspective files *.xml"; 67 } 68 } 69 70 public void readPackageLayerData() throws Exception 71 { 72 File perspectiveFile = getPerspectiveFile(); 73 SAXBuilder builder = new SAXBuilder(); 74 Document doc = builder.build(perspectiveFile); 75 76 Element root = doc.getRootElement(); 77 Element perspective = root.getChild("perspective"); 78 79 filters = perspective.getChildren("Filter"); 80 aggregators = perspective.getChildren("Aggregator"); 81 82 Element layerOrder = perspective.getChild("LayerOrder"); 83 84 Iterator layerIt = layerOrder.getChildren("layer").iterator(); 85 86 map = new HashMap(); 87 Vector vect = new Vector(); 88 89 while (layerIt.hasNext()) 90 { 91 Element layer = (Element) layerIt.next(); 92 String layerName = layer.getChildText("name"); 93 Iterator packageIt = layer.getChildren("package").iterator(); 94 vect.add(layerName); 95 96 while (packageIt.hasNext()) 97 { 98 Element pkgName = (Element) packageIt.next(); 99 String packageName = pkgName.getText(); 100 101 map.put(packageName, layerName); 102 } 103 } 104 layers = (String[]) vect.toArray(new String[vect.size()]); 105 } 106 107 public String[] getLayers() 108 { 109 return layers; 110 } 111 112 public HashMap getPackageLayerData() 113 { 114 return map; 115 } 116 117 public List getFilters() 118 { 119 return filters; 120 } 121 122 public List getAggregators() 123 { 124 return aggregators; 125 } 126 127 private HashMap map = null; 128 private String[] layers = null; 129 130 private List filters = null; 131 132 private List aggregators = null; 133 } 134

This page was automatically generated by Maven