00001 /* 00002 * ################################################################ 00003 * 00004 * ProActive: The Java(TM) library for Parallel, Distributed, 00005 * Concurrent computing with Security and Mobility 00006 * 00007 * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis 00008 * Contact: proactive@objectweb.org 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 * USA 00024 * 00025 * Initial developer(s): The ProActive Team 00026 * http://www.inria.fr/oasis/ProActive/contacts.html 00027 * Contributor(s): 00028 * 00029 * ################################################################ 00030 */ 00031 package org.objectweb.proactive.core.xml.io; 00032 00033 import org.xml.sax.SAXException; 00034 00035 00044 public class DefaultHandlerAdapter extends org.xml.sax.helpers.DefaultHandler { 00045 protected XMLHandler targetHandler; 00046 00047 // 00048 // -- CONSTRUCTORS ----------------------------------------------- 00049 // 00050 public DefaultHandlerAdapter(XMLHandler targetHandler) { 00051 this.targetHandler = targetHandler; 00052 } 00053 00054 // 00055 // -- PUBLIC METHODS ----------------------------------------------- 00056 // 00057 // 00058 // -- ContentHandler methods ------------------------------------------------------ 00059 // 00060 00066 // public void startPrefixMapping(String prefix, String uri) throws org.xml.sax.SAXException { 00067 // //System.out.println("startPrefixMapping prefix="+prefix+" uri="+uri); 00068 // targetHandler.startPrefixMapping(prefix, uri); 00069 // } 00070 // 00071 // 00072 // /** 00073 // * endPrefixMapping. 00074 // * Receive notification of the start of a Namespace mapping. 00075 // */ 00076 // public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException { 00077 // //System.out.println("endPrefixMapping prefix="+prefix); 00078 // targetHandler.endPrefixMapping(prefix); 00079 // } 00080 00084 public void startElement(String namespaceURI, String localName, 00085 String qName, org.xml.sax.Attributes atts) 00086 throws org.xml.sax.SAXException { 00087 //System.out.println("DefaultHandlerAdaptor startElement localName="+localName+" qName="+qName); 00088 targetHandler.startElement(qName, new AttributesImpl(atts)); 00089 } 00090 00094 public void endElement(String namespaceURI, String localName, String qName) 00095 throws org.xml.sax.SAXException { 00096 //System.out.println("DefaultHandlerAdaptor endElement localName="+localName+" qName="+qName); 00097 targetHandler.endElement(qName); 00098 } 00099 00100 // public void skippedEntity(java.lang.String name) { 00101 // // ignore 00102 // // System.out.println("skippedEntity "+name); 00103 // } 00104 // 00105 // 00106 // public void processingInstruction(java.lang.String target, java.lang.String data) { 00107 // // ignore 00108 // //System.out.println("processingInstruction target="+target+" data="+data); 00109 // } 00110 00114 public void characters(char[] ch, int start, int length) 00115 throws org.xml.sax.SAXException { 00116 if (length > 0) { 00117 char[] c = new char[length]; 00118 System.arraycopy(ch, start, c, 0, length); 00119 targetHandler.readValue(parseCharacterEntities(new String(c))); 00120 } 00121 } 00122 00123 // /** 00124 // * ignorableWhitespace. 00125 // */ 00126 // public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException { 00127 // // ignore 00128 // } 00129 // 00130 // -- ErrorHandler methods ------------------------------------------------------ 00131 // 00132 // /** 00133 // * Warning. 00134 // */ 00135 // public void warning(org.xml.sax.SAXParseException ex) { 00136 // System.err.println("[Warning] : "+ex.getMessage()); 00137 // } 00138 // 00139 // /** Error. */ 00140 // public void error(org.xml.sax.SAXParseException ex) { 00141 // System.err.println("[Error] : "+ex.getMessage()); 00142 // } 00143 // 00144 // /** Fatal error. */ 00145 // public void fatalError(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException { 00146 // System.err.println("[Fatal Error] : "+ex.getMessage()); 00147 // throw ex; 00148 // } 00149 // 00150 // -- PROTECTED METHODS ------------------------------------------------------ 00151 // 00152 protected class AttributesImpl implements Attributes { 00153 private org.xml.sax.Attributes attributes; 00154 00155 AttributesImpl(org.xml.sax.Attributes attributes) { 00156 this.attributes = attributes; 00157 } 00158 00159 public String getValue(int index) { 00160 return attributes.getValue(index); 00161 } 00162 00163 public String getValue(String qName) throws SAXException{ 00164 String attribute = attributes.getValue(qName); 00165 if ((attribute != null) && (attribute.indexOf("${") >= 0)) { 00166 return org.objectweb.proactive.core.xml.VariableContract.xmlproperties.transform(attribute); 00167 } 00168 00169 return attribute; 00170 } 00171 00172 public String getValue(String uri, String localPart) throws SAXException{ 00173 String attribut = attributes.getValue(uri, localPart); 00174 if ((attribut != null) && (attribut.indexOf("${") >= 0)) { 00175 return org.objectweb.proactive.core.xml.VariableContract.xmlproperties.transform(attribut); 00176 } 00177 00178 return attribut; 00179 // return attributes.getValue(uri, localPart); 00180 } 00181 00182 public int getLength() { 00183 return attributes.getLength(); 00184 } 00185 } 00186 00187 protected class EmptyAttributesImpl implements Attributes { 00188 EmptyAttributesImpl() { 00189 } 00190 00191 public String getValue(int index) { 00192 return null; 00193 } 00194 00195 public String getValue(String qName) { 00196 return null; 00197 } 00198 00199 public String getValue(String uri, String localPart) { 00200 return null; 00201 } 00202 00203 public int getLength() { 00204 return 0; 00205 } 00206 } 00207 00208 // 00209 // -- PRIVATE METHODS ------------------------------------------------------ 00210 // 00211 private String parseCharacterEntities(String in) { 00212 return in; 00213 } 00214 }