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: package org.netbeans.modules.subversion.options;
042:
043: import java.util.regex.Matcher;
044: import java.util.regex.Pattern;
045: import org.tigris.subversion.svnclientadapter.SVNUrl;
046:
047: /**
048: *
049: * @author Tomas Stupka
050: */
051: public class AnnotationExpression {
052:
053: private String urlExp;
054: private String annotationExp;
055: private Pattern urlPattern;
056:
057: public AnnotationExpression(String urlExp, String annotationExp) {
058: this .urlExp = urlExp;
059: this .annotationExp = annotationExp;
060: this .urlPattern = Pattern.compile(urlExp);
061: }
062:
063: public String getUrlExp() {
064: return urlExp;
065: }
066:
067: public String getAnnotationExp() {
068: return annotationExp;
069: }
070:
071: @Override
072: public boolean equals(Object obj) {
073: if (obj == null) {
074: return false;
075: }
076: if (getClass() != obj.getClass()) {
077: return false;
078: }
079: final AnnotationExpression other = (AnnotationExpression) obj;
080: if (this .urlExp != other.urlExp
081: && (this .urlExp == null || !this .urlExp
082: .equals(other.urlExp))) {
083: return false;
084: }
085: if (this .annotationExp != other.annotationExp
086: && (this .annotationExp == null || !this .annotationExp
087: .equals(other.annotationExp))) {
088: return false;
089: }
090: return true;
091: }
092:
093: @Override
094: public int hashCode() {
095: int hash = 7;
096: return hash;
097: }
098:
099: public Pattern getUrlPatern() {
100: return urlPattern;
101: }
102:
103: void setUrlExp(String urlExp) {
104: this .urlExp = urlExp;
105: }
106:
107: void setAnnotationExp(String annotationExp) {
108: this .annotationExp = annotationExp;
109: }
110:
111: public String getCopyName(String url) {
112: Matcher m = getUrlPatern().matcher(url);
113: if (m.matches()) {
114: String ae = getAnnotationExp();
115:
116: StringBuffer copyName = new StringBuffer();
117: StringBuffer groupStr = new StringBuffer();
118: boolean inGroup = false;
119:
120: for (int i = 0; i < ae.length(); i++) {
121: char c = ae.charAt(i);
122: if (c == '\\') {
123: inGroup = true;
124: continue;
125: } else if (inGroup) {
126: if (Character.isDigit(c)) {
127: groupStr.append(c);
128: } else {
129: if (groupStr.length() > 0) {
130: try {
131: int group = Integer.valueOf(
132: groupStr.toString()).intValue();
133: copyName.append(m.group(group));
134: } catch (Exception e) {
135: copyName.append('\\');
136: copyName.append(groupStr);
137: }
138: groupStr = new StringBuffer();
139: } else {
140: copyName.append('\\');
141: copyName.append(c);
142: }
143: inGroup = false;
144: }
145: continue;
146: }
147: copyName.append(c);
148: }
149: if (groupStr.length() > 0) {
150: try {
151: int group = Integer.valueOf(groupStr.toString())
152: .intValue();
153: copyName.append(m.group(group));
154: } catch (Exception e) {
155: copyName.append('\\');
156: copyName.append(groupStr);
157: }
158: }
159: return copyName.toString();
160: }
161: return null;
162: }
163:
164: }
|