sourcedomparser.java

来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 96 行

JAVA
96
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/gefmodule/util/SourceDOMParser.java,v 1.1.1.1 2004/07/01 09:07:49 wang_j Exp $
 * $Revision: 1.1.1.1 $
 * $Date: 2004/07/01 09:07:49 $
 *
 * ====================================================================
 *
 * The NanJing HopeRun(IT-FOREST) Software License, Version 2.0.0
 *
 * Copyright 2003-2004 by NanJing HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and
 *                        IT Forest Corporation
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
 * You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into with
 * HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
 */

package com.webpump.ui.gefmodule.util;

import java.util.Hashtable;

import org.apache.xerces.parsers.DOMParser;
import org.apache.xerces.xni.*;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

/**
 * Class for SourceDOMParser
 * 
 * @author shi_l
 * @version 2.0.0 2004-5-30
 */
public class SourceDOMParser extends DOMParser {
	private Hashtable lines = new Hashtable();
	boolean notSupported;
	private XMLLocator locator;

	public SourceDOMParser() {
		try {
			setFeature(DEFER_NODE_EXPANSION, false);
		} catch (Exception e) {
			notSupported = true;
		}
	}

	public void reset() {
		super.reset();
		lines.clear();
	}

	public void startDocument(XMLLocator locator, String encoding, Augmentations augs)
		throws XNIException {
		super.startDocument(locator, encoding, augs);
		this.locator = locator;
	}

	public void startElement(QName element, XMLAttributes atts, Augmentations augs)
		throws XNIException {
		super.startElement(element, atts, augs);
		if (notSupported)
			return;
		try {
			Integer[] range = new Integer[2];
			range[0] = new Integer(locator.getLineNumber());
			Node elNode = (Node) getProperty(CURRENT_ELEMENT_NODE);
			if (elNode != null)
				lines.put(elNode, range);
		} catch (SAXException e) {
		}
	}

	public void endElement(QName element, Augmentations augs) throws XNIException {
		if (notSupported)
			return;
		try {
			Node elNode = (Node) getProperty(CURRENT_ELEMENT_NODE);
			if (elNode != null) {
				Integer[] range = (Integer[]) lines.get(elNode);
				if (range != null) {
					Integer endValue = new Integer(locator.getLineNumber());
					range[1] = endValue;
				}
			}
		} catch (SAXException e) {
		}
		super.endElement(element, augs);
	}

	public Hashtable getLineTable() {
		return lines;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?