1 /*** 2 * 3 */ 4 package com.fernsroth.squashfs; 5 6 import java.io.File; 7 import java.io.IOException; 8 import java.io.InputStream; 9 10 import javax.xml.parsers.ParserConfigurationException; 11 import javax.xml.parsers.SAXParser; 12 import javax.xml.parsers.SAXParserFactory; 13 14 import org.xml.sax.SAXException; 15 16 import com.fernsroth.squashfs.exception.NestedSquashFSExcception; 17 import com.fernsroth.squashfs.exception.SquashFSException; 18 import com.fernsroth.squashfs.model.Manifest; 19 20 /*** 21 * 22 * @author Joseph M. Ferner (Near Infinity Corporation) 23 */ 24 public class SquashFSManifest { 25 26 /*** 27 * the sax parser factory. 28 */ 29 private static SAXParserFactory factory; 30 31 static { 32 factory = SAXParserFactory.newInstance(); 33 factory.setValidating(true); 34 } 35 36 /*** 37 * loads a manifest file. 38 * @param manifestInput the manifest input. 39 * @param rootDirectory the root directory. 40 * @return the loaded manifest. 41 * @throws SquashFSException 42 * @throws IOException 43 */ 44 public static Manifest load(InputStream manifestInput, File rootDirectory) 45 throws SquashFSException, IOException { 46 try { 47 SAXParser parser = factory.newSAXParser(); 48 ManifestSAXHandler manifestHandler = new ManifestSAXHandler( 49 rootDirectory); 50 parser.parse(manifestInput, manifestHandler); 51 return manifestHandler.getManifest(); 52 } catch (ParserConfigurationException e) { 53 throw new NestedSquashFSExcception("could not load manifest file", 54 e); 55 } catch (SAXException e) { 56 throw new NestedSquashFSExcception("could not load manifest file", 57 e); 58 } 59 } 60 }