RootElementSaxContentHandler.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.message.soap.reader;

  21. import org.xml.sax.Attributes;
  22. import org.xml.sax.SAXException;
  23. import org.xml.sax.helpers.DefaultHandler;

  24. /**
  25.  * RootElementSaxContentHandler
  26.  *
  27.  * @author Andrea Poli (poli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class RootElementSaxContentHandler extends DefaultHandler {

  32.     private String localName;
  33.     private String namespace;
  34.     private String prefix;
  35.    
  36.     private String excludedNamespace;
  37.    
  38.     public RootElementSaxContentHandler(String excludedNamespace) {
  39.         this.excludedNamespace = excludedNamespace;
  40.     }
  41.    
  42.     @Override
  43.     public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
  44.        
  45.         //System.out.println("--------- startElement uri["+uri+"] localName["+localName+"] qName["+qName+"]");
  46.        
  47.         if(!this.excludedNamespace.equals(uri)) {
  48.             this.localName = localName;
  49.             this.namespace = uri;
  50.             if(qName!=null && qName.contains(":") && !qName.startsWith(":")) {
  51.                 this.prefix = qName.substring(0, qName.indexOf(":"));
  52.             }
  53.             else {
  54.                 this.prefix = "";
  55.             }
  56.         }
  57.     }

  58.     public String getLocalName() {
  59.         return this.localName;
  60.     }

  61.     public String getNamespace() {
  62.         return this.namespace;
  63.     }
  64.    
  65.     public String getPrefix() {
  66.         return this.prefix;
  67.     }
  68. }