Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.cocoon.xml.sax;
 
XML utility methods.

Version:
$Id: SAXUtils.java 729283 2008-12-24 09:25:21Z cziegeler $
 
 public class SAXUtils {

    
Empty attributes immutable object.
 
     public static final Attributes EMPTY_ATTRIBUTES = new ImmutableAttributesImpl();

    
Add string data

Parameters:
contentHandler The SAX content handler
data The string data
 
     public static void data(ContentHandler contentHandler,
                             String data)
     throws SAXException {
 
         contentHandler.characters(data.toCharArray(), 0, data.length());
     }

    
Create a start and endElement with a empty Namespace and without Attributes

Parameters:
localName The local name (without prefix)
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
 
     public static void createElement(ContentHandler contentHandler,
                                      String localName)
     throws SAXException {
 
         startElement(contentHandlerlocalName);
         endElement(contentHandlerlocalName);
     }

    
Create a start and endElement with a empty Namespace and without Attributes The content of the Element is set to the stringValue parameter

Parameters:
localName The local name (without prefix)
stringValue The content of the Element
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
 
     public static void createElement(ContentHandler contentHandler,
                                      String localName,
                                      String stringValue)
     throws SAXException {
 
         startElement(contentHandlerlocalName);
         data(contentHandlerstringValue);
         endElement(contentHandlerlocalName);
     }

    
Create a start and endElement with a empty Namespace

Parameters:
localName The local name (without prefix)
atts The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
org.xml.sax.Attributes
 
     public static void createElement(ContentHandler contentHandler,
                                      String localName,
                                      Attributes atts)
     throws SAXException {
        startElement(contentHandlerlocalNameatts);
        endElement(contentHandlerlocalName);
    }

    
Create a start and endElement with a empty Namespace The content of the Element is set to the stringValue parameter

Parameters:
localName The local name (without prefix)
atts The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
stringValue The content of the Element
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
org.xml.sax.Attributes
    public static void createElement(ContentHandler contentHandler,
                                     String localName,
                                     Attributes atts,
                                     String stringValue)
    throws SAXException {
        startElement(contentHandlerlocalNameatts);
        data(contentHandlerstringValue);
        endElement(contentHandlerlocalName);
    }

    
Create a start and endElement without Attributes

Parameters:
localName The local name (without prefix)
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
    public static void createElementNS(ContentHandler contentHandler,
                                       String namespaceURI,
                                       String localName)
    throws SAXException {
        startElement(contentHandlernamespaceURIlocalName);
        endElement(contentHandlernamespaceURIlocalName);
    }

    
Create a start and endElement without Attributes The content of the Element is set to the stringValue parameter

Parameters:
localName The local name (without prefix)
stringValue The content of the Element
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
    public static void createElementNS(ContentHandler contentHandler,
                                       String namespaceURI,
                                       String localName,
                                       String stringValue)
    throws SAXException {
        startElement(contentHandlernamespaceURIlocalName);
        data(contentHandlerstringValue);
        endElement(contentHandlernamespaceURIlocalName);
    }

    
Create a start and endElement

Parameters:
localName The local name (without prefix)
atts The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
org.xml.sax.Attributes
    public static void createElementNS(ContentHandler contentHandler,
                                       String namespaceURI,
                                       String localName,
                                       Attributes atts)
    throws SAXException {
        startElement(contentHandlernamespaceURIlocalNameatts);
        endElement(contentHandlernamespaceURIlocalName);
    }

    
Create a start and endElement with a empty Namespace The content of the Element is set to the stringValue parameter

Parameters:
localName The local name (without prefix)
atts The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
stringValue The content of the Element
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
org.xml.sax.Attributes
    public static void createElementNS(ContentHandler contentHandler,
                                       String namespaceURI,
                                       String localName,
                                       Attributes atts,
                                       String stringValue)
    throws SAXException {
        startElement(contentHandlernamespaceURIlocalNameatts);
        data(contentHandlerstringValue);
        endElement(contentHandlernamespaceURIlocalName);
    }


    
Create endElement with empty Namespace

For information on the names, see startElement.

Parameters:
localName The local name (without prefix)
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
    public static void endElement(ContentHandler contentHandler,
                                  String localName)
    throws SAXException {
        contentHandler.endElement(""localNamelocalName);
    }

    
Create endElement Prefix must be mapped to empty String

For information on the names, see startElement.

Parameters:
localName The local name (without prefix)
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
    public static void endElement(ContentHandler contentHandler,
                                  String namespaceURI,
                                  String localName)
    throws SAXException {
        contentHandler.endElement(namespaceURIlocalNamelocalName);
    }

    
Create a startElement with a empty Namespace and without Attributes

Parameters:
localName The local name (without prefix)
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
    public static void startElement(ContentHandler contentHandler,
                                    String localName)
    throws SAXException {
        contentHandler.startElement(""localNamelocalName);
    }

    
Create a startElement without Attributes Prefix must be mapped to empty String

Parameters:
namespaceURI The Namespace URI
localName The local name (without prefix)
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
    public static void startElement(ContentHandler contentHandler,
                                    String namespaceURI,
                                    String localName)
    throws SAXException {
        contentHandler.startElement(namespaceURIlocalNamelocalName);
    }

    
Create a startElement with a empty Namespace

Parameters:
localName The local name (without prefix)
atts The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
org.xml.sax.Attributes
    public static void startElement(ContentHandler contentHandler,
                                    String localName,
                                    Attributes atts)
    throws SAXException {
        contentHandler.startElement(""localNamelocalNameatts);
    }

    
Create a startElement with a empty Namespace Prefix must be mapped to empty String

Parameters:
namespaceURI The Namespace URI
localName The local name (without prefix)
atts The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
See also:
endElement(org.xml.sax.ContentHandler,java.lang.String)
org.xml.sax.Attributes
    public static void startElement(ContentHandler contentHandler,
                                    String namespaceURI,
                                    String localName,
                                    Attributes atts)
    throws SAXException {
        contentHandler.startElement(namespaceURIlocalNamelocalNameatts);
    }
New to GrepCode? Check out our FAQ X