4 * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2011, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 import org.w3c.dom.Attr;
32 import org.w3c.dom.Document;
33 import org.w3c.dom.Element;
34 import org.w3c.dom.NodeList;
35 import org.xml.sax.SAXParseException;
36 import org.xml.sax.ErrorHandler;
37 import org.apache.xerces.parsers.DOMParser;
38 import org.xml.sax.InputSource;
40 import java.lang.Integer;
42 public class JP2XMLparser
46 public static class ROIparams{
47 public String name = null;
54 public static class IRTparams{
55 public String refimg = null;
56 public double []mat = { 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
59 public JP2XMLparser( byte[] buf)
62 InputSource source = new InputSource( new ByteArrayInputStream( buf));
63 DOMParser parser = new DOMParser();
64 parser.setErrorHandler(new MyHandler());
65 parser.parse( source);
66 document = parser.getDocument();
73 public ROIparams [] getROIparams()
76 NodeList elements = document.getElementsByTagName("roi");
77 int elementCount = elements.getLength();
79 roi = new ROIparams [elementCount];
81 for( int i = 0; i < elementCount; i++) {
82 Element element = (Element)elements.item(i);
84 roi[i] = new ROIparams();
85 roi[i].name = element.getAttribute( "name");
86 roi[i].x = Integer.parseInt( element.getAttribute( "x")) ;
87 roi[i].y = Integer.parseInt( element.getAttribute( "y")) ;
88 roi[i].w = Integer.parseInt( element.getAttribute( "w")) ;
89 roi[i].h = Integer.parseInt( element.getAttribute( "h")) ;
94 public IRTparams getIRTparams()
96 IRTparams irt = new IRTparams();
97 NodeList elements = document.getElementsByTagName("irt");
98 int elementCount = elements.getLength();
100 Element element = (Element)elements.item(0);
101 irt.refimg = element.getAttribute( "refimg");
102 for( int i=1; i<=9; i++)
103 irt.mat[i-1] = Double.parseDouble( element.getAttribute("m" + i));
109 class MyHandler implements ErrorHandler {
110 public void warning(SAXParseException e) {
111 System.out.println("Warning: line" + e.getLineNumber());
112 System.out.println(e.getMessage());
114 public void error(SAXParseException e) {
115 System.out.println("Error: line" + e.getLineNumber());
116 System.out.println(e.getMessage());
118 public void fatalError(SAXParseException e) {
119 System.out.println("Critical error: line" + e.getLineNumber());
120 System.out.println(e.getMessage());