/** * Reads zipped file from zip input stream that includes the construction saved in xml format and * maybe image files. */ private final void readZip(ZipInputStream zip, boolean isGGTfile) throws Exception { // we have to read everything (i.e. all images) // before we process the XML file, that's why we // read the XML file into a buffer first byte[] xmlFileBuffer = null; byte[] macroXmlFileBuffer = null; boolean xmlFound = false; boolean macroXMLfound = false; boolean ggbHandler = false; // get all entries from the zip archive while (true) { ZipEntry entry = zip.getNextEntry(); if (entry == null) break; String name = entry.getName(); if (name.equals(XML_FILE) || name.equals(I2G_PRIVATE + XML_FILE)) { // load xml file into memory first xmlFileBuffer = Util.loadIntoMemory(zip); xmlFound = true; ggbHandler = true; // Added for Intergeo File Format (Yves Kreis) --> handler = getGGBHandler(); } else if (!ggbHandler && name.equals(I2G_FILE)) { // load i2g file into memory first xmlFileBuffer = Util.loadIntoMemory(zip); xmlFound = true; handler = getI2GHandler(); // <-- Added for Intergeo File Format (Yves Kreis) } else if (name.equals(XML_FILE_MACRO) || name.equals(I2G_PRIVATE + XML_FILE_MACRO)) { // load macro xml file into memory first macroXmlFileBuffer = Util.loadIntoMemory(zip); macroXMLfound = true; ggbHandler = true; handler = getGGBHandler(); } else if (name.equals(JAVASCRIPT_FILE)) { // load JavaScript kernel.setLibraryJavaScript(Util.loadIntoString(zip)); } else { // try to load image try { BufferedImage img = ImageIO.read(zip); app.addExternalImage(name, img); } catch (IOException e) { Application.debug("readZipFromURL: image could not be loaded: " + name); e.printStackTrace(); } } // get next entry zip.closeEntry(); } zip.close(); if (!isGGTfile) { // ggb file: remove all macros from kernel before processing kernel.removeAllMacros(); } // process macros if (macroXmlFileBuffer != null) { // don't clear kernel for macro files processXMLBuffer(macroXmlFileBuffer, !isGGTfile, isGGTfile); } // process construction if (!isGGTfile && xmlFileBuffer != null) { processXMLBuffer(xmlFileBuffer, !macroXMLfound, isGGTfile); } if (!(macroXMLfound || xmlFound)) throw new Exception("No XML data found in file."); }