1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 import java.io.IOException; 25 import java.io.File; 26 import java.util.zip.*; 27 28 public class XmlWrapper 29 { main(String args[])30 public static void main(String args[]) throws IOException 31 { 32 System.out.println("args.length is " + args.length); 33 if (args.length < 2) { 34 System.out.println("Usage: java XmlWrapper [<zipfile1> <zipfile2>]."); 35 //return; 36 System.exit(-1); 37 38 } 39 40 XmlWrapper w = new XmlWrapper(); 41 File currdirfp = null; 42 try { 43 currdirfp = new File("."); 44 } catch (Exception fx) { 45 System.out.println("Could not get File instance for current directory \n"); 46 //return; 47 System.exit(-1); 48 } 49 50 File f1 = null; 51 File f2 = null; 52 String fname1,fname2; 53 try { 54 f1 = File.createTempFile("xmlcomp", ".tmp", currdirfp); 55 f2 = File.createTempFile("xmlcomp", ".tmp", currdirfp); 56 } catch (Exception tx) { 57 System.out.println("Could not create TempFile "); 58 System.out.println("Exception: " + tx.toString()); 59 //return; 60 System.exit(-1); 61 } 62 63 fname1 = f1.getAbsolutePath(); 64 fname2 = f2.getAbsolutePath(); 65 66 // get content.xml file from zip file and copy it to temporary 67 // filename 68 XmlZipExtract xw1 = new XmlZipExtract(args[0]); 69 try { 70 xw1.getContentXml(fname1); 71 } catch (ZipException e) { 72 System.out.println("Exception: file is not a ZIP file: " + args[0]); 73 f1.delete(); 74 f2.delete(); 75 //return; 76 System.exit(-1); 77 } catch (Exception e) { 78 System.out.println("Exception: Could not extract XML from " + args[0]); 79 System.out.println("Exception: " + e.toString()); 80 f1.delete(); 81 f2.delete(); 82 //return; 83 System.exit(-1); 84 } 85 86 // get content.xml file from zip file and copy it to temporary 87 // filename 88 XmlZipExtract xw2 = new XmlZipExtract(args[1]); 89 try { 90 xw2.getContentXml(fname2); 91 } catch (ZipException e) { 92 System.out.println("Exception: file is not a ZIP file: " + args[0]); 93 f1.delete(); 94 f2.delete(); 95 //return; 96 System.exit(-1); 97 } catch (Exception ex) { 98 System.out.println(ex.getMessage()); 99 System.out.println("Exception: Could not extract XML from " + args[1]); 100 System.out.println("Exception: " + ex.toString()); 101 f1.delete(); 102 f2.delete(); 103 //return; 104 System.exit(-1); 105 } 106 107 boolean same = false; 108 109 try 110 { 111 XmlDiff xmldiff = new XmlDiff(); 112 113 if (args.length == 2) { 114 same = xmldiff.diff(fname1, fname2); 115 } else { 116 same = xmldiff.diff(); 117 } 118 } 119 catch (Exception ex) 120 { 121 System.out.println("XmlDiff failed"); 122 System.out.println("Exception: " + ex.toString()); 123 f1.delete(); 124 f2.delete(); 125 //return; 126 System.exit(-1); 127 } 128 129 System.out.println("Diff result: " + same); 130 if (same) 131 { 132 System.out.println("XMLDIFFRESULT:PASSED"); 133 } else { 134 System.out.println("XMLDIFFRESULT:FAILED"); 135 } 136 137 f1.delete(); 138 f2.delete(); 139 140 if (same) 141 { 142 System.exit(2); 143 } 144 else 145 { 146 System.exit(3); 147 } 148 } 149 } 150