[Htmlparser-cvs] htmlparser/src/org/htmlparser/util DefaultParserFeedback.java,1.23,1.24 LinkProcess
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-09-03 23:38:03
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util In directory sc8-pr-cvs1:/tmp/cvs-serv31228/util Modified Files: DefaultParserFeedback.java LinkProcessor.java NodeIterator.java NodeList.java ParserUtils.java PeekingIterator.java SimpleNodeIterator.java Translate.java Log Message: Change tabs to spaces in all source files. Index: DefaultParserFeedback.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/DefaultParserFeedback.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** DefaultParserFeedback.java 24 Aug 2003 21:59:44 -0000 1.23 --- DefaultParserFeedback.java 3 Sep 2003 23:36:22 -0000 1.24 *************** *** 69,73 **** * </pre> */ ! protected int mode; /** --- 69,73 ---- * </pre> */ ! protected int mMode; /** *************** *** 79,88 **** * QUIET - no messages * </pre> */ public DefaultParserFeedback (int mode) { ! if (mode<QUIET||mode>DEBUG) ! throw new IllegalArgumentException ("illegal mode (" + mode + "), must be one of: QUIET, NORMAL, DEBUG"); ! this.mode = mode; } --- 79,93 ---- * QUIET - no messages * </pre> + * @exception IllegalArgumentException if mode is not + * QUIET, NORMAL or DEBUG. */ public DefaultParserFeedback (int mode) { ! if (mode<QUIET||mode>DEBUG) ! throw new IllegalArgumentException ( ! "illegal mode (" ! + mode ! + "), must be one of: QUIET, NORMAL, DEBUG"); ! mMode = mode; } *************** *** 101,105 **** public void info (String message) { ! if (mode!=QUIET) System.out.println ("INFO: " + message); } --- 106,110 ---- public void info (String message) { ! if (QUIET != mMode) System.out.println ("INFO: " + message); } *************** *** 111,115 **** public void warning (String message) { ! if (mode!=QUIET) System.out.println ("WARNING: " + message); } --- 116,120 ---- public void warning (String message) { ! if (QUIET != mMode) System.out.println ("WARNING: " + message); } *************** *** 122,129 **** public void error (String message, ParserException exception) { ! if (mode!=QUIET) { System.out.println ("ERROR: " + message); ! if (mode == DEBUG && (exception!=null)) exception.printStackTrace (); } --- 127,134 ---- public void error (String message, ParserException exception) { ! if (QUIET != mMode) { System.out.println ("ERROR: " + message); ! if (DEBUG == mMode && (null != exception)) exception.printStackTrace (); } Index: LinkProcessor.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/LinkProcessor.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** LinkProcessor.java 24 Aug 2003 21:59:45 -0000 1.23 --- LinkProcessor.java 3 Sep 2003 23:36:22 -0000 1.24 *************** *** 76,80 **** else { ! URL url = constructUrl(link, base); ret = url.toExternalForm (); } --- 76,80 ---- else { ! URL url = constructUrl(link, base); ret = url.toExternalForm (); } *************** *** 88,124 **** } ! public URL constructUrl(String link, String base) ! throws MalformedURLException { ! String path; ! boolean modified; ! boolean absolute; ! int index; ! URL url; // constructed URL combining relative link and base ! url = new URL (new URL (base), link); ! path = url.getFile (); ! modified = false; ! absolute = link.startsWith ("/"); ! if (!absolute) { // we prefer to fix incorrect relative links ! // this doesn't fix them all, just the ones at the start ! while (path.startsWith ("/.")) { ! if (path.startsWith ("/../")) { ! path = path.substring (3); ! modified = true; ! } ! else if (path.startsWith ("/./") || path.startsWith("/.")) { ! path = path.substring (2); ! modified = true; ! } else break; ! } ! } ! // fix backslashes ! while (-1 != (index = path.indexOf ("/\\"))) { ! path = path.substring (0, index + 1) + path.substring (index + 2); ! modified = true; ! } ! if (modified) ! url = new URL (url, path); ! return url; ! } /** --- 88,124 ---- } ! public URL constructUrl(String link, String base) ! throws MalformedURLException { ! String path; ! boolean modified; ! boolean absolute; ! int index; ! URL url; // constructed URL combining relative link and base ! url = new URL (new URL (base), link); ! path = url.getFile (); ! modified = false; ! absolute = link.startsWith ("/"); ! if (!absolute) { // we prefer to fix incorrect relative links ! // this doesn't fix them all, just the ones at the start ! while (path.startsWith ("/.")) { ! if (path.startsWith ("/../")) { ! path = path.substring (3); ! modified = true; ! } ! else if (path.startsWith ("/./") || path.startsWith("/.")) { ! path = path.substring (2); ! modified = true; ! } else break; ! } ! } ! // fix backslashes ! while (-1 != (index = path.indexOf ("/\\"))) { ! path = path.substring (0, index + 1) + path.substring (index + 2); ! modified = true; ! } ! if (modified) ! url = new URL (url, path); ! return url; ! } /** *************** *** 194,207 **** } ! public static String removeLastSlash(String baseUrl) { ! if(baseUrl.charAt(baseUrl.length()-1)=='/') ! { ! return baseUrl.substring(0,baseUrl.length()-1); ! } ! else ! { ! return baseUrl; ! } ! } } --- 194,207 ---- } ! public static String removeLastSlash(String baseUrl) { ! if(baseUrl.charAt(baseUrl.length()-1)=='/') ! { ! return baseUrl.substring(0,baseUrl.length()-1); ! } ! else ! { ! return baseUrl; ! } ! } } Index: NodeIterator.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/NodeIterator.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** NodeIterator.java 24 Aug 2003 21:59:45 -0000 1.24 --- NodeIterator.java 3 Sep 2003 23:36:22 -0000 1.25 *************** *** 36,40 **** * @return <code>true</code> if a call to <code>nextHTMLNode()</code> will succeed. */ ! public boolean hasMoreNodes() throws ParserException; /** --- 36,40 ---- * @return <code>true</code> if a call to <code>nextHTMLNode()</code> will succeed. */ ! public boolean hasMoreNodes() throws ParserException; /** *************** *** 42,46 **** * @return The next node in the HTML stream, or null if there are no more nodes. */ ! public Node nextNode() throws ParserException; ! } --- 42,46 ---- * @return The next node in the HTML stream, or null if there are no more nodes. */ ! public Node nextNode() throws ParserException; ! } Index: NodeList.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/NodeList.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** NodeList.java 24 Aug 2003 21:59:45 -0000 1.40 --- NodeList.java 3 Sep 2003 23:36:22 -0000 1.41 *************** *** 35,59 **** public class NodeList implements Serializable { ! private static final int INITIAL_CAPACITY=10; ! //private static final int CAPACITY_INCREMENT=20; ! private Node nodeData[]; ! private int size; ! private int capacity; ! private int capacityIncrement; ! private int numberOfAdjustments; ! ! public NodeList() { ! size = 0; ! capacity = INITIAL_CAPACITY; ! nodeData = newNodeArrayFor(capacity); ! capacityIncrement = capacity*2; ! numberOfAdjustments = 0; ! } ! ! public void add(Node node) { ! if (size==capacity) ! adjustVectorCapacity(); ! nodeData[size++]=node; ! } /** --- 35,59 ---- public class NodeList implements Serializable { ! private static final int INITIAL_CAPACITY=10; ! //private static final int CAPACITY_INCREMENT=20; ! private Node nodeData[]; ! private int size; ! private int capacity; ! private int capacityIncrement; ! private int numberOfAdjustments; ! ! public NodeList() { ! size = 0; ! capacity = INITIAL_CAPACITY; ! nodeData = newNodeArrayFor(capacity); ! capacityIncrement = capacity*2; ! numberOfAdjustments = 0; ! } ! ! public void add(Node node) { ! if (size==capacity) ! adjustVectorCapacity(); ! nodeData[size++]=node; ! } /** *************** *** 61,69 **** * @param list The list to add. */ ! public void add (NodeList list) { for (int i = 0; i < list.size; i++) add (list.nodeData[i]); ! } /** --- 61,69 ---- * @param list The list to add. */ ! public void add (NodeList list) { for (int i = 0; i < list.size; i++) add (list.nodeData[i]); ! } /** *************** *** 71,166 **** * @param node The new first element. */ ! public void prepend(Node node) { ! if (size==capacity) ! adjustVectorCapacity(); System.arraycopy (nodeData, 0, nodeData, 1, size); size++; ! nodeData[0]=node; ! } ! private void adjustVectorCapacity() { ! capacity += capacityIncrement; ! capacityIncrement *= 2; ! Node oldData [] = nodeData; ! nodeData = newNodeArrayFor(capacity); ! System.arraycopy(oldData, 0, nodeData, 0, size); ! numberOfAdjustments++; ! } ! private Node[] newNodeArrayFor(int capacity) { ! return new Node[capacity]; ! } ! ! public int size() { ! return size; ! } ! ! public Node elementAt(int i) { ! return nodeData[i]; ! } ! public int getNumberOfAdjustments() { ! return numberOfAdjustments; ! } ! ! public SimpleNodeIterator elements() { ! return new SimpleNodeIterator() { ! int count = 0; ! ! public boolean hasMoreNodes() { ! return count < size; ! } ! ! public Node nextNode() { ! synchronized (NodeList.this) { ! if (count < size) { ! return nodeData[count++]; ! } ! } ! throw new NoSuchElementException("Vector Enumeration"); ! } ! }; ! } ! ! public Node [] toNodeArray() { ! Node [] nodeArray = newNodeArrayFor(size); ! System.arraycopy(nodeData, 0, nodeArray, 0, size); ! return nodeArray; ! } ! ! public String asString() { ! StringBuffer buff = new StringBuffer(); ! for (int i=0;i<size;i++) ! buff.append(nodeData[i].toPlainTextString()); ! return buff.toString(); ! } ! ! public String asHtml() { ! StringBuffer buff = new StringBuffer(); ! for (int i=0;i<size;i++) ! buff.append(nodeData[i].toHtml()); ! return buff.toString(); ! } ! ! public void remove(int index) { ! System.arraycopy(nodeData, index+1, nodeData, index, size-index-1); ! size--; ! } ! ! public void removeAll() { ! size = 0; ! capacity = INITIAL_CAPACITY; ! nodeData = newNodeArrayFor(capacity); ! capacityIncrement = capacity*2; ! numberOfAdjustments = 0; ! } ! ! public String toString() { ! StringBuffer text = new StringBuffer(); ! for (int i=0;i<size;i++) ! text.append(nodeData[i].toPlainTextString()); ! return text.toString(); ! } /** --- 71,166 ---- * @param node The new first element. */ ! public void prepend(Node node) { ! if (size==capacity) ! adjustVectorCapacity(); System.arraycopy (nodeData, 0, nodeData, 1, size); size++; ! nodeData[0]=node; ! } ! private void adjustVectorCapacity() { ! capacity += capacityIncrement; ! capacityIncrement *= 2; ! Node oldData [] = nodeData; ! nodeData = newNodeArrayFor(capacity); ! System.arraycopy(oldData, 0, nodeData, 0, size); ! numberOfAdjustments++; ! } ! private Node[] newNodeArrayFor(int capacity) { ! return new Node[capacity]; ! } ! ! public int size() { ! return size; ! } ! ! public Node elementAt(int i) { ! return nodeData[i]; ! } ! public int getNumberOfAdjustments() { ! return numberOfAdjustments; ! } ! ! public SimpleNodeIterator elements() { ! return new SimpleNodeIterator() { ! int count = 0; ! ! public boolean hasMoreNodes() { ! return count < size; ! } ! ! public Node nextNode() { ! synchronized (NodeList.this) { ! if (count < size) { ! return nodeData[count++]; ! } ! } ! throw new NoSuchElementException("Vector Enumeration"); ! } ! }; ! } ! ! public Node [] toNodeArray() { ! Node [] nodeArray = newNodeArrayFor(size); ! System.arraycopy(nodeData, 0, nodeArray, 0, size); ! return nodeArray; ! } ! ! public String asString() { ! StringBuffer buff = new StringBuffer(); ! for (int i=0;i<size;i++) ! buff.append(nodeData[i].toPlainTextString()); ! return buff.toString(); ! } ! ! public String asHtml() { ! StringBuffer buff = new StringBuffer(); ! for (int i=0;i<size;i++) ! buff.append(nodeData[i].toHtml()); ! return buff.toString(); ! } ! ! public void remove(int index) { ! System.arraycopy(nodeData, index+1, nodeData, index, size-index-1); ! size--; ! } ! ! public void removeAll() { ! size = 0; ! capacity = INITIAL_CAPACITY; ! nodeData = newNodeArrayFor(capacity); ! capacityIncrement = capacity*2; ! numberOfAdjustments = 0; ! } ! ! public String toString() { ! StringBuffer text = new StringBuffer(); ! for (int i=0;i<size;i++) ! text.append(nodeData[i].toPlainTextString()); ! return text.toString(); ! } /** *************** *** 168,175 **** * @param classType The class to search for. */ ! public NodeList searchFor (Class classType) { return (searchFor (classType, false)); ! } /** --- 168,175 ---- * @param classType The class to search for. */ ! public NodeList searchFor (Class classType) { return (searchFor (classType, false)); ! } /** Index: ParserUtils.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/ParserUtils.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** ParserUtils.java 24 Aug 2003 21:59:45 -0000 1.26 --- ParserUtils.java 3 Sep 2003 23:36:22 -0000 1.27 *************** *** 38,120 **** public class ParserUtils { ! ! public static String toString(Tag tag) { ! String tagName = tag.getAttribute(Tag.TAGNAME); ! Hashtable attrs = tag.getAttributes(); ! StringBuffer lString = new StringBuffer(tagName); ! lString.append(" TAG\n"); ! lString.append("--------\n"); ! for (Enumeration e = attrs.keys(); e.hasMoreElements();) { ! String key = (String) e.nextElement(); ! String value = (String) attrs.get(key); ! if (!key.equalsIgnoreCase(Tag.TAGNAME) && value.length() > 0) ! lString.append(key).append(" : ").append(value).append("\n"); ! } ! return lString.toString(); ! } ! public static Map adjustScanners(NodeReader reader) { ! Map tempScanners = new Hashtable(); ! tempScanners = reader.getParser().getScanners(); ! // Remove all existing scanners ! reader.getParser().flushScanners(); ! return tempScanners; ! } ! ! public static void restoreScanners(NodeReader reader, Map tempScanners) { ! // Flush the scanners ! reader.getParser().setScanners(tempScanners); ! } ! public static String removeChars(String s, char occur) { ! StringBuffer newString = new StringBuffer(); ! char ch; ! for (int i = 0; i < s.length(); i++) { ! ch = s.charAt(i); ! if (ch != occur) ! newString.append(ch); ! } ! return newString.toString(); ! } ! public static String removeEscapeCharacters(String inputString) { ! inputString = ParserUtils.removeChars(inputString, '\r'); ! inputString = ParserUtils.removeChars(inputString, '\n'); ! inputString = ParserUtils.removeChars(inputString, '\t'); ! return inputString; ! } ! public static String removeLeadingBlanks(String plainText) { ! while (plainText.indexOf(' ') == 0) ! plainText = plainText.substring(1); ! return plainText; ! } ! public static String removeTrailingBlanks(String text) { ! char ch = ' '; ! while (ch == ' ') { ! ch = text.charAt(text.length() - 1); ! if (ch == ' ') ! text = text.substring(0, text.length() - 1); ! } ! return text; ! } ! /** ! * Search given node and pick up any objects of given type, return ! * Node array. ! * @param node ! * @param type ! * @return Node[] ! */ ! public static Node[] findTypeInNode(Node node, Class type) { ! NodeList nodeList = new NodeList(); ! node.collectInto(nodeList, type); ! Node spans[] = nodeList.toNodeArray(); ! return spans; ! } } --- 38,120 ---- public class ParserUtils { ! ! public static String toString(Tag tag) { ! String tagName = tag.getAttribute(Tag.TAGNAME); ! Hashtable attrs = tag.getAttributes(); ! StringBuffer lString = new StringBuffer(tagName); ! lString.append(" TAG\n"); ! lString.append("--------\n"); ! for (Enumeration e = attrs.keys(); e.hasMoreElements();) { ! String key = (String) e.nextElement(); ! String value = (String) attrs.get(key); ! if (!key.equalsIgnoreCase(Tag.TAGNAME) && value.length() > 0) ! lString.append(key).append(" : ").append(value).append("\n"); ! } ! return lString.toString(); ! } ! public static Map adjustScanners(NodeReader reader) { ! Map tempScanners = new Hashtable(); ! tempScanners = reader.getParser().getScanners(); ! // Remove all existing scanners ! reader.getParser().flushScanners(); ! return tempScanners; ! } ! ! public static void restoreScanners(NodeReader reader, Map tempScanners) { ! // Flush the scanners ! reader.getParser().setScanners(tempScanners); ! } ! public static String removeChars(String s, char occur) { ! StringBuffer newString = new StringBuffer(); ! char ch; ! for (int i = 0; i < s.length(); i++) { ! ch = s.charAt(i); ! if (ch != occur) ! newString.append(ch); ! } ! return newString.toString(); ! } ! public static String removeEscapeCharacters(String inputString) { ! inputString = ParserUtils.removeChars(inputString, '\r'); ! inputString = ParserUtils.removeChars(inputString, '\n'); ! inputString = ParserUtils.removeChars(inputString, '\t'); ! return inputString; ! } ! public static String removeLeadingBlanks(String plainText) { ! while (plainText.indexOf(' ') == 0) ! plainText = plainText.substring(1); ! return plainText; ! } ! public static String removeTrailingBlanks(String text) { ! char ch = ' '; ! while (ch == ' ') { ! ch = text.charAt(text.length() - 1); ! if (ch == ' ') ! text = text.substring(0, text.length() - 1); ! } ! return text; ! } ! /** ! * Search given node and pick up any objects of given type, return ! * Node array. ! * @param node ! * @param type ! * @return Node[] ! */ ! public static Node[] findTypeInNode(Node node, Class type) { ! NodeList nodeList = new NodeList(); ! node.collectInto(nodeList, type); ! Node spans[] = nodeList.toNodeArray(); ! return spans; ! } } Index: PeekingIterator.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/PeekingIterator.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** PeekingIterator.java 24 Aug 2003 21:59:45 -0000 1.12 --- PeekingIterator.java 3 Sep 2003 23:36:22 -0000 1.13 *************** *** 32,57 **** public interface PeekingIterator extends NodeIterator{ ! /** ! * Fetch a node without consuming it. ! * Subsequent calls to <code>peek()</code> will return subsequent nodes. ! * The node returned by <code>peek()</code> will never be a node already ! * consumed by <code>nextHTMLNode()</code>.<p> ! * For example, say there are nodes <H1><H2><H3><H4><H5>, ! * this is the nodes that would be returned for the indicated calls: ! * <pre> ! * peek() H1 ! * peek() H2 ! * nextHTMLNode() H1 ! * peek() H3 ! * nextHTMLNode() H2 ! * nextHTMLNode() H3 ! * nextHTMLNode() H4 ! * peek() H5 ! * </pre> ! * @return The next node that would be returned by <code>nextHTMLNode()</code> ! * or the node after the last node returned by <code>peek()</code>, whichever ! * is later in the stream. or null if there are no more nodes available via ! * the above rules. ! */ ! public Node peek () throws ParserException; } --- 32,57 ---- public interface PeekingIterator extends NodeIterator{ ! /** ! * Fetch a node without consuming it. ! * Subsequent calls to <code>peek()</code> will return subsequent nodes. ! * The node returned by <code>peek()</code> will never be a node already ! * consumed by <code>nextHTMLNode()</code>.<p> ! * For example, say there are nodes <H1><H2><H3><H4><H5>, ! * this is the nodes that would be returned for the indicated calls: ! * <pre> ! * peek() H1 ! * peek() H2 ! * nextHTMLNode() H1 ! * peek() H3 ! * nextHTMLNode() H2 ! * nextHTMLNode() H3 ! * nextHTMLNode() H4 ! * peek() H5 ! * </pre> ! * @return The next node that would be returned by <code>nextHTMLNode()</code> ! * or the node after the last node returned by <code>peek()</code>, whichever ! * is later in the stream. or null if there are no more nodes available via ! * the above rules. ! */ ! public Node peek () throws ParserException; } Index: SimpleNodeIterator.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/SimpleNodeIterator.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** SimpleNodeIterator.java 24 Aug 2003 21:59:45 -0000 1.26 --- SimpleNodeIterator.java 3 Sep 2003 23:36:22 -0000 1.27 *************** *** 40,55 **** public interface SimpleNodeIterator extends NodeIterator { ! /** ! * Check if more nodes are available. ! * @return <code>true</code> if a call to <code>nextHTMLNode()</code> will ! * succeed. ! */ ! public boolean hasMoreNodes(); ! /** ! * Get the next node. ! * @return The next node in the HTML stream, or null if there are no more ! * nodes. ! */ ! public Node nextNode(); } --- 40,55 ---- public interface SimpleNodeIterator extends NodeIterator { ! /** ! * Check if more nodes are available. ! * @return <code>true</code> if a call to <code>nextHTMLNode()</code> will ! * succeed. ! */ ! public boolean hasMoreNodes(); ! /** ! * Get the next node. ! * @return The next node in the HTML stream, or null if there are no more ! * nodes. ! */ ! public Node nextNode(); } Index: Translate.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/Translate.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Translate.java 24 Aug 2003 21:59:45 -0000 1.32 --- Translate.java 3 Sep 2003 23:36:22 -0000 1.33 *************** *** 472,476 **** public static String decode (StringBuffer stringBuffer) { ! return decode(stringBuffer.toString()); } --- 472,476 ---- public static String decode (StringBuffer stringBuffer) { ! return decode(stringBuffer.toString()); } |