blob: ddd296aa573b8c04a24b493b27bed1b6dfb9f1b1 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.jsp.ui.internal.java.search;
import java.util.HashMap;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.ui.search.ISearchRequestor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jst.jsp.ui.internal.Logger;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.text.Match;
/**
* @author pavery
*/
public class JSPSearchRequestor extends BasicJSPSearchRequestor {
private ISearchRequestor fJavaRequestor = null;
public JSPSearchRequestor() {
super();
}
public JSPSearchRequestor(ISearchRequestor javaRequestor) {
// need to report matches to javaRequestor
this.fJavaRequestor = javaRequestor;
}
/* (non-Javadoc)
* @see org.eclipse.jst.jsp.ui.internal.java.search.BasicJSPSearchRequestor#addSearchMatch(com.ibm.sse.model.text.IStructuredDocument, org.eclipse.core.resources.IFile, int, int, java.lang.String)
*/
protected void addSearchMatch(IDocument jspDocument, IFile jspFile, int jspStart, int jspEnd, String jspText) {
if(!jspFile.exists())
return;
int lineNumber = -1;
try {
lineNumber = jspDocument.getLineOfOffset(jspStart);
} catch (BadLocationException e) {
Logger.logException(e);
}
createSearchMarker(jspFile, jspStart, jspEnd, lineNumber);
if(this.fJavaRequestor != null) {
Match match = new Match(jspFile, jspStart, jspEnd - jspStart);
this.fJavaRequestor.reportMatch(match);
}
}
/**
* @param jspFile
* @param jspStart
* @param jspEnd
*/
private void createSearchMarker(IFile jspFile, int jspStart, int jspEnd, int lineNumber) {
try {
IMarker marker = jspFile.createMarker(NewSearchUI.SEARCH_MARKER);
HashMap attributes = new HashMap(4);
attributes.put(IMarker.CHAR_START, new Integer(jspStart));
attributes.put(IMarker.CHAR_END, new Integer(jspEnd));
attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
marker.setAttributes(attributes);
} catch (CoreException e) {
Logger.logException(e);
}
}
}