If you think the Android project utexas-utilities listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.nasageek.utexasutilities;
/*www.java2s.com*/import com.nasageek.utexasutilities.fragments.BlackboardFragment;
import com.nasageek.utexasutilities.model.CourseMapItem;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.ArrayList;
import java.util.Stack;
publicclass CourseMapSaxHandler extends DefaultHandler {
// ===========================================================
// Fields
// ===========================================================
privateboolean in_maptag = false;
privateboolean in_childrentag = false;
privateint folderDepth;
private Stack<ArrayList> recLists;
private ArrayList top;
private ArrayList content;
public CourseMapSaxHandler() {
super();
}
public ArrayList getParsedData() {
return this.top;
}
@Override
publicvoid startDocument() throws SAXException {
this.top = new ArrayList();
this.content = top;
this.recLists = new Stack<ArrayList>();
this.folderDepth = 0;
}
@Override
publicvoid endDocument() throws SAXException {
// Nothing to do
}
/**
* Gets be called on opening tags like: <tag> Can provide attribute(s), when
* xml was like: <tag attribute="attributeValue">
*/
@Override
publicvoid startElement(String namespaceURI, String localName, String qName, Attributes atts)
throws SAXException {
if (localName.equals("map-item")) {
this.in_maptag = true;
// maybe I should just check for a non-null viewurl, I suppose this
// works for the time being, though
// TODO: actually include SUBHEADERs as non-clickable list items
// instead of ignoring them
if (atts.getValue("linktype") != null && !atts.getValue("linktype").equals("DIVIDER")
&& !atts.getValue("linktype").equals("SUBHEADER")) {
String host = "";
Boolean blackboardItem = false;
if (!(atts.getValue("viewurl").contains("http://") || atts.getValue("viewurl")
.contains("https://"))) {
host = BlackboardFragment.BLACKBOARD_DOMAIN;
}
content.add(new MyPair(new CourseMapItem(atts.getValue("name"), host
+ atts.getValue("viewurl").replace("&", "&"), atts
.getValue("contentid"), atts.getValue("linktype")), new ArrayList()));
}
folderDepth++;
} elseif (localName.equals("children")) {
this.in_childrentag = true;
recLists.push(content);
content = (ArrayList) ((MyPair) (content.get(content.size() - 1))).second;
}
}
/**
* Gets be called on closing tags like: </tag>
*/
@Override
publicvoid endElement(String namespaceURI, String localName, String qName) throws SAXException {
if (localName.equals("map-item")) {
folderDepth--;
if (folderDepth == 0) {
this.in_maptag = false;
}
} elseif (localName.equals("children")) {
this.in_childrentag = false;
content = recLists.pop();
}
}
/**
* Gets be called on the following structure: <tag>characters</tag>
*/
@Override
publicvoid characters(char ch[], int start, int length) {
}
}