maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/trinidad/util/XPointerFilter.java [30:110]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public final class XPointerFilter extends XMLFilterImpl
{
  public XPointerFilter(
    XMLReader        parent,
    NamespaceSupport namespaces,
    String           xpointer)
  {
    super(parent);

    // We support a very rudimentary - but totally sufficient - XPointer syntax,
    // which is just /element/otherelement/otherotherelement/*
    if (!xpointer.startsWith("/") || !xpointer.endsWith("/*"))
      throw new IllegalArgumentException("Unsupported xpointer syntax: " +
                                         xpointer);

    xpointer = xpointer.substring(0, xpointer.length() - 2).substring(1);
    String[] elements = xpointer.split("/");
    int count = elements.length;

    _rootNamespaceURI = new String[count];
    _rootLocalName = new String[count];
    _acceptChildNodes = new boolean[count];

    for (int i = 0; i < count; i++)
    {
      String[] parts = elements[i].split(":");
      String prefix = (parts.length == 1) ? "" : parts[0];
      String namespaceURI = namespaces.getURI(prefix);
      _rootNamespaceURI[i] = (namespaceURI != null) ? namespaceURI : "";
      _rootLocalName[i] = (parts.length == 1) ? parts[0] : parts[1];
      _acceptChildNodes[i] = false;
    }
  }

  public void startElement(
    String     namespaceURI,
    String     localName,
    String     qualifiedName,
    Attributes attributes) throws SAXException
  {
    if (_depth < _acceptChildNodes.length)
    {
      _acceptChildNodes[_depth] =
           (_rootNamespaceURI[_depth].equals(namespaceURI) &&
            _rootLocalName[_depth].equals(localName));
    }
    else if (_acceptingChildNodes())
    {
      super.startElement(namespaceURI, localName, qualifiedName, attributes);
    }

    _depth++;
  }

  public void endElement(
    String namespaceURI,
    String localName,
    String qualifiedName) throws SAXException
  {
    _depth--;

    if (_depth >= _acceptChildNodes.length && _acceptingChildNodes())
      super.endElement(namespaceURI, localName, qualifiedName);
  }

  
  private boolean _acceptingChildNodes()
  {
    for (int i = _acceptChildNodes.length - 1; i >= 0; i--)
    {
      if (!_acceptChildNodes[i])
        return false;
    }

    return true;
  }

  private int     _depth;
  private boolean[] _acceptChildNodes;
  private String[]  _rootNamespaceURI;
  private String[]  _rootLocalName;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



maven2-plugins/myfaces-faces-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/faces/util/XPointerFilter.java [30:110]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public final class XPointerFilter extends XMLFilterImpl
{
  public XPointerFilter(
    XMLReader        parent,
    NamespaceSupport namespaces,
    String           xpointer)
  {
    super(parent);

    // We support a very rudimentary - but totally sufficient - XPointer syntax,
    // which is just /element/otherelement/otherotherelement/*
    if (!xpointer.startsWith("/") || !xpointer.endsWith("/*"))
      throw new IllegalArgumentException("Unsupported xpointer syntax: " +
                                         xpointer);

    xpointer = xpointer.substring(0, xpointer.length() - 2).substring(1);
    String[] elements = xpointer.split("/");
    int count = elements.length;

    _rootNamespaceURI = new String[count];
    _rootLocalName = new String[count];
    _acceptChildNodes = new boolean[count];

    for (int i = 0; i < count; i++)
    {
      String[] parts = elements[i].split(":");
      String prefix = (parts.length == 1) ? "" : parts[0];
      String namespaceURI = namespaces.getURI(prefix);
      _rootNamespaceURI[i] = (namespaceURI != null) ? namespaceURI : "";
      _rootLocalName[i] = (parts.length == 1) ? parts[0] : parts[1];
      _acceptChildNodes[i] = false;
    }
  }

  public void startElement(
    String     namespaceURI,
    String     localName,
    String     qualifiedName,
    Attributes attributes) throws SAXException
  {
    if (_depth < _acceptChildNodes.length)
    {
      _acceptChildNodes[_depth] =
           (_rootNamespaceURI[_depth].equals(namespaceURI) &&
            _rootLocalName[_depth].equals(localName));
    }
    else if (_acceptingChildNodes())
    {
      super.startElement(namespaceURI, localName, qualifiedName, attributes);
    }

    _depth++;
  }

  public void endElement(
    String namespaceURI,
    String localName,
    String qualifiedName) throws SAXException
  {
    _depth--;

    if (_depth >= _acceptChildNodes.length && _acceptingChildNodes())
      super.endElement(namespaceURI, localName, qualifiedName);
  }

  
  private boolean _acceptingChildNodes()
  {
    for (int i = _acceptChildNodes.length - 1; i >= 0; i--)
    {
      if (!_acceptChildNodes[i])
        return false;
    }

    return true;
  }

  private int     _depth;
  private boolean[] _acceptChildNodes;
  private String[]  _rootNamespaceURI;
  private String[]  _rootLocalName;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



