From c3c2f50948bb67de1d09c5e3db399c8fb55b8c72 Mon Sep 17 00:00:00 2001 From: Jukka Lauri Zitting Date: Tue, 18 Mar 2008 22:18:07 +0000 Subject: [PATCH] TIKA-129: node() support for the streaming XPath utility git-svn-id: https://svn.eu.apache.org/repos/asf/incubator/tika/trunk@638609 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../org/apache/tika/sax/xpath/NodeMatcher.java | 42 ++++++++++++++++++++++ .../org/apache/tika/sax/xpath/XPathParser.java | 2 ++ 3 files changed, 46 insertions(+) create mode 100644 src/main/java/org/apache/tika/sax/xpath/NodeMatcher.java diff --git a/CHANGES.txt b/CHANGES.txt index 4a37eb7..e1acf3c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -24,6 +24,8 @@ Unreleased changes (0.2-incubating) 10. TIKA-127 - Add support for Visio files (Jukka Zitting) +11. TIKA-129 - node() support for the streaming XPath utility (Jukka Zitting) + Release 0.1-incubating - 12/27/2007 diff --git a/src/main/java/org/apache/tika/sax/xpath/NodeMatcher.java b/src/main/java/org/apache/tika/sax/xpath/NodeMatcher.java new file mode 100644 index 0000000..706ac2d --- /dev/null +++ b/src/main/java/org/apache/tika/sax/xpath/NodeMatcher.java @@ -0,0 +1,42 @@ +/* + * 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.tika.sax.xpath; + +/** + * Final evaluation state of a .../node() XPath expression. + * Matches all elements, attributes, and text. + */ +public class NodeMatcher extends Matcher { + + public static final Matcher INSTANCE = new NodeMatcher(); + + @Override + public boolean matchesElement() { + return true; + } + + @Override + public boolean matchesAttribute(String namespace, String name) { + return true; + } + + @Override + public boolean matchesText() { + return true; + } + +} diff --git a/src/main/java/org/apache/tika/sax/xpath/XPathParser.java b/src/main/java/org/apache/tika/sax/xpath/XPathParser.java index 65cd02d..8884672 100644 --- a/src/main/java/org/apache/tika/sax/xpath/XPathParser.java +++ b/src/main/java/org/apache/tika/sax/xpath/XPathParser.java @@ -58,6 +58,8 @@ public class XPathParser { public Matcher parse(String xpath) { if (xpath.equals("/text()")) { return TextMatcher.INSTANCE; + } else if (xpath.equals("/node()")) { + return NodeMatcher.INSTANCE; } else if (xpath.equals("/@*")) { return AttributeMatcher.INSTANCE; } else if (xpath.length() == 0) { -- 2.11.4.GIT