All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.phloc.commons.xml.IXMLIterationHandler Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
/**
 * Copyright (C) 2006-2015 phloc systems
 * http://www.phloc.com
 * office[at]phloc[dot]com
 *
 * Licensed 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 com.phloc.commons.xml;

import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * Callback interface when iterating XML nodes.
 * 
 * @author Philip Helger
 */
public interface IXMLIterationHandler
{
  /**
   * At the very beginning of the document.
   * 
   * @param eVersion
   *        The XML version to use. If null is passed,
   *        {@link EXMLVersion#DEFAULT} will be used.
   * @param sEncoding
   *        The encoding to be used for this document. It may be
   *        null but it is strongly recommended to write a correct
   *        charset.
   * @param bStandalone
   *        if true this is a standalone XML document without a
   *        connection to an existing DTD or XML schema
   */
  void onDocumentStart (@Nullable EXMLVersion eVersion, @Nullable String sEncoding, boolean bStandalone);

  /**
   * On XML document type.
   * 
   * @param sQualifiedElementName
   *        Qualified name of the root element.
   * @param sPublicID
   *        Document type public ID
   * @param sSystemID
   *        Document type system ID
   */
  void onDocumentType (@Nonnull final String sQualifiedElementName,
                       @Nullable final String sPublicID,
                       @Nullable final String sSystemID);

  /**
   * On processing instruction
   * 
   * @param sTarget
   *        The target
   * @param sData
   *        The data (attributes as a string)
   */
  void onProcessingInstruction (@Nonnull String sTarget, @Nullable String sData);

  /**
   * On entity reference.
   * 
   * @param sEntityRef
   *        The reference (without '&' and ';' !!)
   */
  void onEntityReference (@Nonnull String sEntityRef);

  /**
   * Ignorable whitespace characters.
   * 
   * @param aWhitespaces
   *        The whitespace character sequence
   */
  void onContentElementWhitespace (@Nullable CharSequence aWhitespaces);

  /**
   * Comment node.
   * 
   * @param sComment
   *        The comment text
   */
  void onComment (@Nullable String sComment);

  /**
   * Text node.
   * 
   * @param sText
   *        The contained text
   * @param bEscape
   *        If true the text should be XML masked,
   *        false if not. The false case is especially
   *        interesting for HTML inline JS and CSS code.
   */
  void onText (@Nullable String sText, boolean bEscape);

  /**
   * CDATA node.
   * 
   * @param sText
   *        The contained text
   */
  void onCDATA (@Nullable String sText);

  /**
   * Start of an element.
   * 
   * @param sNamespacePrefix
   *        Optional namespace prefix. May be null.
   * @param sTagName
   *        Tag name
   * @param aAttrs
   *        Optional set of attributes.
   * @param bHasChildren
   *        true if the current element has children
   */
  void onElementStart (@Nullable String sNamespacePrefix,
                       @Nonnull String sTagName,
                       @Nullable Map  aAttrs,
                       boolean bHasChildren);

  /**
   * End of an element.
   * 
   * @param sNamespacePrefix
   *        Optional namespace prefix. May be null.
   * @param sTagName
   *        Tag name
   * @param bHasChildren
   *        true if the current element has children
   */
  void onElementEnd (@Nullable String sNamespacePrefix, @Nonnull String sTagName, boolean bHasChildren);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy