You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2008/02/03 22:04:03 UTC
svn commit: r618087 - in
/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model:
NodePointer.java beans/NullPropertyPointer.java
dynamic/DynamicPropertyPointer.java jdom/JDOMNodePointer.java
Author: mbenson
Date: Sun Feb 3 13:03:58 2008
New Revision: 618087
URL: http://svn.apache.org/viewvc?rev=618087&view=rev
Log:
consolidate duplicate code
Modified:
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.java
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java
Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java?rev=618087&r1=618086&r2=618087&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java Sun Feb 3 13:03:58 2008
@@ -19,6 +19,7 @@
import java.util.HashSet;
import java.util.Locale;
+import org.apache.commons.jxpath.AbstractFactory;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.JXPathException;
import org.apache.commons.jxpath.NodeSet;
@@ -810,6 +811,55 @@
*/
public void printPointerChain() {
printDeep(this, "");
+ }
+
+ /**
+ * Return a string escaping single and double quotes.
+ * @param string string to treat
+ * @return string with any necessary changes made.
+ */
+ protected String escape(String string) {
+ final char[] c = new char[] { '\'', '"' };
+ final String[] esc = new String[] { "'", """ };
+ StringBuffer sb = null;
+ for (int i = 0; sb == null && i < c.length; i++) {
+ if (string.indexOf(c[i]) >= 0) {
+ sb = new StringBuffer(string);
+ }
+ }
+ if (sb == null) {
+ return string;
+ }
+ for (int i = 0; i < c.length; i++) {
+ if (string.indexOf(c[i]) < 0) {
+ continue;
+ }
+ int pos = 0;
+ while (pos < sb.length()) {
+ if (sb.charAt(pos) == c[i]) {
+ sb.replace(pos, pos + 1, esc[i]);
+ pos += esc[i].length();
+ } else {
+ pos++;
+ }
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Get the AbstractFactory associated with the specified JXPathContext.
+ * @param context JXPathContext
+ * @return AbstractFactory
+ */
+ protected AbstractFactory getAbstractFactory(JXPathContext context) {
+ AbstractFactory factory = context.getFactory();
+ if (factory == null) {
+ throw new JXPathException(
+ "Factory is not set on the JXPathContext - cannot create path: "
+ + asPath());
+ }
+ return factory;
}
/**
Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java?rev=618087&r1=618086&r2=618087&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java Sun Feb 3 13:03:58 2008
@@ -266,41 +266,6 @@
}
/**
- * Return a string escaping single and double quotes.
- * @param string string to treat
- * @return string with any necessary changes made.
- */
- private String escape(String string) {
- final char[] c = new char[] { '\'', '"' };
- final String[] esc = new String[] { "'", """ };
- StringBuffer sb = null;
- for (int i = 0; sb == null && i < c.length; i++) {
- if (string.indexOf(c[i]) >= 0) {
- sb = new StringBuffer(string);
- }
- }
- if (sb == null) {
- return string;
- }
- for (int i = 0; i < c.length; i++) {
- if (string.indexOf(c[i]) < 0) {
- continue;
- }
- int pos = 0;
- while (pos < sb.length()) {
- if (sb.charAt(pos) == c[i]) {
- sb.replace(pos, pos + 1, esc[i]);
- pos += esc[i].length();
- }
- else {
- pos++;
- }
- }
- }
- return sb.toString();
- }
-
- /**
* Create a "bad factory" JXPathAbstractFactoryException for the specified AbstractFactory.
* @param factory AbstractFactory
* @return JXPathAbstractFactoryException
Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.java?rev=618087&r1=618086&r2=618087&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.java (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.java Sun Feb 3 13:03:58 2008
@@ -23,7 +23,6 @@
import org.apache.commons.jxpath.DynamicPropertyHandler;
import org.apache.commons.jxpath.JXPathAbstractFactoryException;
import org.apache.commons.jxpath.JXPathContext;
-import org.apache.commons.jxpath.JXPathException;
import org.apache.commons.jxpath.JXPathInvalidAccessException;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.ri.model.beans.PropertyPointer;
@@ -316,43 +315,4 @@
return buffer.toString();
}
- /**
- * Escape string.
- * @param string s
- * @return String
- */
- private String escape(String string) {
- int index = string.indexOf('\'');
- while (index != -1) {
- string =
- string.substring(0, index)
- + "'"
- + string.substring(index + 1);
- index = string.indexOf('\'');
- }
- index = string.indexOf('\"');
- while (index != -1) {
- string =
- string.substring(0, index)
- + """
- + string.substring(index + 1);
- index = string.indexOf('\"');
- }
- return string;
- }
-
- /**
- * Get abstractFactory from context.
- * @param context to search
- * @return AbstractFactory
- */
- private AbstractFactory getAbstractFactory(JXPathContext context) {
- AbstractFactory factory = context.getFactory();
- if (factory == null) {
- throw new JXPathException(
- "Factory is not set on the JXPathContext - cannot create path: "
- + asPath());
- }
- return factory;
- }
}
Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java?rev=618087&r1=618086&r2=618087&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java Sun Feb 3 13:03:58 2008
@@ -19,7 +19,6 @@
import java.util.List;
import java.util.Locale;
-import org.apache.commons.jxpath.AbstractFactory;
import org.apache.commons.jxpath.JXPathAbstractFactoryException;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.JXPathException;
@@ -743,40 +742,6 @@
}
/**
- * Return a string escaping single and double quotes.
- * @param string string to treat
- * @return string with any necessary changes made.
- */
- private String escape(String string) {
- final char[] c = new char[] { '\'', '"' };
- final String[] esc = new String[] { "'", """ };
- StringBuffer sb = null;
- for (int i = 0; sb == null && i < c.length; i++) {
- if (string.indexOf(c[i]) >= 0) {
- sb = new StringBuffer(string);
- }
- }
- if (sb == null) {
- return string;
- }
- for (int i = 0; i < c.length; i++) {
- if (string.indexOf(c[i]) < 0) {
- continue;
- }
- int pos = 0;
- while (pos < sb.length()) {
- if (sb.charAt(pos) == c[i]) {
- sb.replace(pos, pos + 1, esc[i]);
- pos += esc[i].length();
- } else {
- pos++;
- }
- }
- }
- return sb.toString();
- }
-
- /**
* Get relative position of this among like-named siblings.
* @return 1..n
*/
@@ -911,21 +876,6 @@
JDOMNodePointer other = (JDOMNodePointer) object;
return node == other.node;
- }
-
- /**
- * Get the AbstractFactory associated with the specified JXPathContext.
- * @param context JXPathContext
- * @return AbstractFactory
- */
- private AbstractFactory getAbstractFactory(JXPathContext context) {
- AbstractFactory factory = context.getFactory();
- if (factory == null) {
- throw new JXPathException(
- "Factory is not set on the JXPathContext - cannot create path: "
- + asPath());
- }
- return factory;
}
}