001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.editor;
043:
044: import java.util.Map;
045: import java.util.regex.Matcher;
046: import java.util.regex.Pattern;
047: import java.util.regex.PatternSyntaxException;
048: import javax.swing.text.BadLocationException;
049: import javax.swing.text.Document;
050: import org.netbeans.lib.editor.util.swing.DocumentUtilities;
051: import org.openide.DialogDisplayer;
052: import org.openide.ErrorManager;
053: import org.openide.NotifyDescriptor;
054: import org.openide.util.NbBundle;
055:
056: /**
057: *
058: * @author Martin Roskanin
059: * @deprecated Without any replacement.
060: */
061: public class DocumentFinder {
062: /**
063: * Finds in document
064: *
065: * @param doc document where to find
066: * @param startOffset offset in the document where the search will start
067: * @param endOffset offset where the search will end with reporting
068: * that nothing was found.
069: * @param props find properties
070: */
071: public static int[] find(BaseDocument doc, int startOffset,
072: int endOffset, Map props, boolean oppositeDir)
073: throws BadLocationException {
074: return org.netbeans.modules.editor.lib2.search.DocumentFinder
075: .find(doc, startOffset, endOffset, props, oppositeDir);
076: }
077:
078: public static int[] findBlocks(BaseDocument doc, int startOffset,
079: int endOffset, Map props, int blocks[])
080: throws BadLocationException {
081: return org.netbeans.modules.editor.lib2.search.DocumentFinder
082: .findBlocks(doc, startOffset, endOffset, props, blocks);
083: }
084:
085: /**
086: * Finds the searching string and substitute replace expression in case of
087: * regexp backreferences.
088: * @return FindReplaceResult, that contains positions of found string and substituted replace expression
089: */
090: public static FindReplaceResult findReplaceResult(
091: String replaceString, BaseDocument doc, int startOffset,
092: int endOffset, Map props, boolean oppositeDir)
093: throws BadLocationException {
094: org.netbeans.modules.editor.lib2.search.DocumentFinder.FindReplaceResult result = org.netbeans.modules.editor.lib2.search.DocumentFinder
095: .findReplaceResult(replaceString, doc, startOffset,
096: endOffset, props, oppositeDir);
097:
098: return new FindReplaceResult(result.getFoundPositions(), result
099: .getReplacedString());
100: }
101:
102: private DocumentFinder() {
103:
104: }
105:
106: public static class FindReplaceResult {
107: private int[] positions;
108: private String replacedString;
109:
110: public FindReplaceResult(int[] positions, String replacedString) {
111: this .positions = positions;
112: this .replacedString = replacedString;
113: }
114:
115: public String getReplacedString() {
116: return replacedString;
117: }
118:
119: public int[] getFoundPositions() {
120: return positions;
121: }
122: } // End of FindReplaceResult class
123: }
|