You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by gr...@apache.org on 2005/01/26 17:53:49 UTC

svn commit: r126516 - /lenya/trunk/src/java/org/apache/lenya/xml/XLink.java /lenya/trunk/src/java/org/apache/lenya/xml/XPath.java

Author: gregor
Date: Wed Jan 26 08:40:34 2005
New Revision: 126516

URL: http://svn.apache.org/viewcvs?view=rev&rev=126516
Log:
Re-added Xlink and XPath classes that slipped into the XPS removal.
Added:
   lenya/trunk/src/java/org/apache/lenya/xml/XLink.java   (contents, props changed)
   lenya/trunk/src/java/org/apache/lenya/xml/XPath.java   (contents, props changed)

Added: lenya/trunk/src/java/org/apache/lenya/xml/XLink.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/xml/XLink.java?view=auto&rev=126516
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/xml/XLink.java	Wed Jan 26 08:40:34 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  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: XLink.java 42598 2004-03-01 16:18:28Z gregor $  */
+
+package org.apache.lenya.xml;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class XLink {
+
+    public String type = null;
+    public String href = null;
+    public String show = null;
+    public String name = null;
+    public Element element = null;
+
+    public static final String XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
+    public static final String ATTRIBUTE_HREF = "href";
+    public static final String ATTRIBUTE_SHOW = "show";
+    public static final String ATTRIBUTE_TYPE = "type";
+
+    /**
+     *
+     */
+    public XLink() {
+        type = "simple";
+        show = "undefined";
+    }
+
+    /**
+     *
+     */
+    public XLink(Element element) {
+        this();
+        this.element = element;
+
+        name = element.getNodeName();
+
+        Attr hrefAttribute = element.getAttributeNodeNS(XLINK_NAMESPACE, ATTRIBUTE_HREF);
+        if (hrefAttribute != null) {
+            href = hrefAttribute.getNodeValue();
+        }
+        Attr typeAttribute = element.getAttributeNodeNS(XLINK_NAMESPACE, ATTRIBUTE_TYPE);
+        if (typeAttribute != null) {
+            type = typeAttribute.getNodeValue();
+        }
+        Attr showAttribute = element.getAttributeNodeNS(XLINK_NAMESPACE, ATTRIBUTE_SHOW);
+        if (showAttribute != null) {
+            show = showAttribute.getNodeValue();
+        }
+
+    }
+
+
+    /**
+     *
+     */
+    public String toString() {
+        return "XLink: type=\""
+            + type
+            + "\", href=\""
+            + href
+            + "\", show=\""
+            + show
+            + "\", name=\""
+            + name
+            + "\"";
+    }
+}

Added: lenya/trunk/src/java/org/apache/lenya/xml/XPath.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/xml/XPath.java?view=auto&rev=126516
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/xml/XPath.java	Wed Jan 26 08:40:34 2005
@@ -0,0 +1,119 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  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: XPath.java 42598 2004-03-01 16:18:28Z gregor $  */
+
+package org.apache.lenya.xml;
+
+import java.util.StringTokenizer;
+
+import org.w3c.dom.Node;
+
+public class XPath {
+    String xpath = null;
+    String[] parts = null;
+
+    /**
+     *
+     */
+    public XPath(String xpath) {
+        this.xpath = xpath;
+
+        StringTokenizer st = new StringTokenizer(xpath, "/");
+        int length = st.countTokens();
+        parts = new String[length];
+
+        for (int i = 0; i < length; i++) {
+            parts[i] = st.nextToken();
+        }
+    }
+
+    /**
+     *
+     */
+    public XPath getParent() {
+        String parentXPath = "";
+
+        for (int i = 0; i < (parts.length - 1); i++) {
+            parentXPath = parentXPath + "/" + parts[i];
+        }
+
+        return new XPath(parentXPath);
+    }
+
+    /**
+     *
+     */
+    public short getType() {
+        if (parts[parts.length - 1].indexOf("@") == 0) {
+            return Node.ATTRIBUTE_NODE;
+        }
+
+        return Node.ELEMENT_NODE;
+    }
+
+    /**
+     *
+     */
+    public String toString() {
+        return xpath;
+    }
+
+    /**
+     *
+     */
+    public String getName() {
+        if (getType() == Node.ATTRIBUTE_NODE) {
+            return parts[parts.length - 1].substring(1);
+        }
+
+        return parts[parts.length - 1];
+    }
+
+    /**
+     * Describe 'getName' method here.
+     *
+     * @return a value of type 'String'
+     */
+    public String getElementName() {
+        if (getType() == Node.ATTRIBUTE_NODE) {
+            return parts[parts.length - 2];
+        }
+
+        return parts[parts.length - 1];
+    }
+
+    /**
+     *
+     */
+    public String getNameWithoutPredicates() {
+        return removePredicates(getName());
+    }
+
+    /**
+     * Remove predicates (square brackets), http://www.w3.org/TR/xpath
+     */
+    public String removePredicates(String s) {
+        int index = s.indexOf("[");
+
+        if (index >= 0) {
+            return s.substring(0, index);
+        }
+
+        return s;
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org