| package org.eclipse.epp.installer.launcher; |
| |
| import java.io.BufferedReader; |
| import java.io.IOException; |
| import java.io.InputStream; |
| import java.io.InputStreamReader; |
| import java.util.Collection; |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| /** |
| * <p> |
| * Copyright (c) 2006, Instantiations, Inc.<br> |
| * All Rights Reserved |
| */ |
| public class InstallManifest { |
| private Map mainSection; |
| private Map sections = new HashMap(); |
| |
| public InstallManifest(){ |
| |
| } |
| |
| public InstallManifest(InputStream is) throws IOException{ |
| load(is); |
| } |
| |
| public void load(InputStream is) throws IOException{ |
| BufferedReader br = new BufferedReader(new InputStreamReader(is)); |
| String sectionName = null; |
| mainSection = new HashMap(); |
| String mainSectionName = readSection(br, mainSection); |
| if(mainSectionName != null){ |
| // there should be no "Platform" key in main section! |
| throw new IOException("Invalid main manifest section"); |
| } |
| do{ |
| Map section = new HashMap(); |
| sectionName = readSection(br, section); |
| if(sectionName == null && section.size() != 0) { |
| // "Platform" key not found in section |
| throw new IOException("Invalid manifest section: no key 'Platform'"); |
| }else if(sectionName != null){ |
| sections.put(sectionName, section); |
| } |
| }while(sectionName != null); |
| } |
| |
| private String readSection(BufferedReader br, Map section) throws IOException { |
| String sectionName = null; |
| String line; |
| while((line = br.readLine()) != null){ |
| if(line.equals("")){ // empty line is section delimiter |
| return sectionName; |
| } |
| |
| int delimiter = line.indexOf(":"); |
| if(delimiter == -1) { |
| throw new IOException("Invalid manifest: Line is not key:value pair!"); |
| } |
| |
| String name = line.substring(0, delimiter).trim(); |
| String value = line.substring(delimiter+1).trim(); |
| |
| if(name.equals("Platform")){ |
| sectionName = value; |
| }else{ |
| if(section.get(name) != null) { |
| throw new IOException("Invalid manifest: duplicated keys in section!"); |
| } |
| section.put(name, value); |
| } |
| } |
| return sectionName; |
| } |
| |
| public Map getMainAttributes(){ |
| return mainSection; |
| } |
| public Collection getEntries(){ |
| return sections.entrySet(); |
| } |
| public Map getAttributes(String name){ |
| return (Map) sections.get(name); |
| } |
| } |