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

it.tidalwave.mobile.xml.jaxen.JaxenXPathProvider Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
/***********************************************************************************************************************
 *
 * blueBill Mobile - open source birdwatching
 * ==========================================
 *
 * Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
 * http://bluebill.tidalwave.it/mobile/
 *
 ***********************************************************************************************************************
 *
 * 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.
 *
 ***********************************************************************************************************************
 *
 * $Id: JaxenXPathProvider.java,v ba6217e099eb 2010/07/03 00:04:09 fabrizio $
 *
 **********************************************************************************************************************/
package it.tidalwave.mobile.xml.jaxen;

import javax.annotation.Nonnull;
import org.jaxen.XPath;
import org.jaxen.dom.DOMXPath;
import org.jaxen.dom4j.Dom4jXPath;
import it.tidalwave.mobile.xml.XPathProvider;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id: $
 *
 **********************************************************************************************************************/
public class JaxenXPathProvider extends XPathProvider
  {
    @Nonnull
    public XPath createXPath (final @Nonnull Object document, final @Nonnull String expression)
      throws Exception
      {
        XPath xPath = null;
        
        if (document instanceof org.w3c.dom.Document)
          {
            xPath = new DOMXPath(expression);
          }
        else if (document instanceof org.dom4j.Document)
          {
            xPath = new Dom4jXPath(expression);
//            return new JDOMXPath(expression);
          }
        
        if (xPath == null)
          {
            throw new IllegalArgumentException("Unknown document class: " + document.getClass());
          }

        xPath.addNamespace("html", "http://www.w3.org/1999/xhtml");

        return xPath;
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy