001: /*******************************************************************************
002: * Copyright (c) 2003, 2004 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jsp;
011:
012: import java.io.*;
013: import java.io.Reader;
014:
015: import org.eclipse.core.indexsearch.*;
016: import org.eclipse.core.resources.*;
017: import org.eclipse.core.resources.IFile;
018: import org.eclipse.core.runtime.*;
019:
020: /**
021: * @author weinand
022: */
023: public class JspIndexParser extends AbstractJspParser implements
024: IIndexer {
025:
026: public static final String JSP_TYPE_REF = "jsp_typeRef"; //$NON-NLS-1$
027:
028: IFile fFile;
029: String fFilePath;
030: boolean fInUseBean;
031: String fId;
032: String fClass;
033: IIndex fOutput;
034:
035: JspIndexParser(IFile resource) {
036: fFile = resource;
037: }
038:
039: protected void startTag(boolean endTag, String name, int startName) {
040: fInUseBean = "jsp:useBean".equals(name); //$NON-NLS-1$
041: }
042:
043: protected void tagAttribute(String attrName, String value,
044: int startName, int startValue) {
045: if (fInUseBean) {
046: if ("id".equals(attrName)) //$NON-NLS-1$
047: fId = value;
048: else if ("class".equals(attrName)) //$NON-NLS-1$
049: fClass = value;
050: }
051: }
052:
053: protected void endTag(boolean end) {
054: if (fInUseBean) {
055: if (fId != null && fClass != null) {
056:
057: String s = JSP_TYPE_REF + "/" + fClass; //$NON-NLS-1$
058: System.out.println(" " + s); //$NON-NLS-1$
059: fOutput.addRef(s, fFilePath);
060:
061: fId = fClass = null;
062: }
063: fInUseBean = false;
064: }
065: }
066:
067: public void index(IIndex indexerOutput) throws IOException {
068:
069: String type = fFile.getFileExtension();
070: if (type != null && JspUIPlugin.JSP_TYPE.equalsIgnoreCase(type)) {
071:
072: // Add the name of the file to the index
073: String path = fFile.getFullPath().toString();
074:
075: String encoding = null;
076: try {
077: encoding = fFile.getCharset();
078: } catch (CoreException e1) {
079: }
080: if (encoding == null)
081: encoding = ResourcesPlugin.getEncoding();
082:
083: String s = null;
084: IPath location = fFile.getLocation();
085: if (location == null)
086: s = ""; //$NON-NLS-1$
087: else
088: s = new String(Util.getFileCharContent(location
089: .toFile(), encoding));
090:
091: try {
092: Reader reader = new StringReader(s);
093: fOutput = indexerOutput;
094: fFilePath = path;
095: parse(reader);
096: } catch (IOException e) {
097: e.printStackTrace();
098: }
099: }
100: }
101: }
|