Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

jquery selectors impl

  • Loading branch information...
commit 92730abda068157a55c48dd66b6fb8860b4bff84 1 parent 1169876
@michelegonella authored
View
38 zen-webservice/src/main/java/com/nominanuda/web/htmlcomposer/DomManipulationHandler.java
@@ -23,18 +23,18 @@
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
-import com.nominanuda.code.Nullable;
import com.nominanuda.lang.Fun0;
-import com.nominanuda.lang.Strings;
import com.nominanuda.lang.Tuple2;
import com.nominanuda.xml.ForwardingTransformerHandlerBase;
-import com.nominanuda.xml.SwallowingTransformerHandlerBase;
import com.nominanuda.xml.SaxBuffer.SaxBit;
+import com.nominanuda.xml.SwallowingTransformerHandlerBase;
public abstract class DomManipulationHandler extends ForwardingTransformerHandlerBase {
private int nestingLevel = 0;
private final DomManipulationStmt stmt;
- private Stack<Tuple2<Integer, Fun0<Void>>> triggerStack = new Stack<Tuple2<Integer,Fun0<Void>>>();
+ private final JquerySelectorExpr jqSelector;
+ private final Stack<Tuple2<Integer, Fun0<Void>>> triggerStack = new Stack<Tuple2<Integer,Fun0<Void>>>();
+ protected final Stack<HtmlTag> parentElementStack = new Stack<HtmlTag>();
private ContentHandler liveContentHandler;
private final static ContentHandler devNull = new SwallowingTransformerHandlerBase();
@@ -58,21 +58,24 @@ public static DomManipulationHandler build(DomManipulationStmt stmt) {
private DomManipulationHandler(DomManipulationStmt domManipulationStmt) {
stmt = domManipulationStmt;
- }
+ jqSelector = new JquerySelectorExpr(stmt.getSelector());
- protected String getSelector() {
- return stmt.getSelector();
}
+// protected String getSelector() {
+// return stmt.getSelector();
+// }
+//
@Override
public void startElement(String uri, String localName, String qName,
Attributes atts) throws SAXException {
nestingLevel++;
- if(matches(localName, atts)) {
+ if(matches(localName, atts, parentElementStack)) {
onMatchedStartElement(uri, localName, qName, atts);
} else {
super.startElement(uri, localName, qName, atts);
}
+ parentElementStack.push(new HtmlTag(localName, atts));
}
protected abstract void onMatchedStartElement(String uri, String localName, String qName,
@@ -95,25 +98,12 @@ public void endElement(String uri, String localName, String qName)
} else {
super.endElement(uri, localName, qName);
}
+ parentElementStack.pop();
nestingLevel--;
}
- //TODO
- private boolean matches(String tag, Attributes atts) {
- if(getSelector().startsWith(".")) {
- if(classMatches(atts.getValue("class"), getSelector().substring(1))) {
- return true;
- }
- } else if(true) {
- if(tag.equals(getSelector())) {
- return true;
- }
- }
- return false;//TODO
- }
-
- private boolean classMatches(@Nullable String clsAttr, String targetClass) {
- return clsAttr != null && Strings.splitAndTrim(clsAttr, "\\s+").contains(targetClass);
+ private boolean matches(String tag, Attributes atts, Stack<HtmlTag> parents) {
+ return jqSelector.matches(tag, atts, parents);
}
protected void turnOnOutput() {
View
15 zen-webservice/src/test/java/com/nominanuda/web/htmlcomposer/HtmlSaxPageTest.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2008-2011 the original author or authors.
+ *
+ * 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.
+ */
package com.nominanuda.web.htmlcomposer;
import static com.nominanuda.web.htmlcomposer.DomOp.after;
Please sign in to comment.
Something went wrong with that request. Please try again.