PageRenderTime 58ms CodeModel.GetById 48ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/testability-explorer/src/main/java/com/google/test/metric/report/SourceLinker.java

http://testability-explorer.googlecode.com/
Java | 70 lines | 41 code | 9 blank | 20 comment | 5 complexity | 36c845ab275b7c43d57ef7b772cf5e6f MD5 | raw file
 1/*
 2 * Copyright 2007 Google Inc.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package com.google.test.metric.report;
17
18public class SourceLinker implements SourceLinkGenerator {
19
20  private final String lineUrlTemplate;
21  private final String classUrlTemplate;
22  private final boolean noTemplate;
23
24  /**
25   *
26   * @param lineUrlTemplate Template for generating Urls for divs with class "Line"
27   * @param classUrlTemplate Template for generating Urls for divs with class "Class"
28   */
29  public SourceLinker(String lineUrlTemplate, String classUrlTemplate) {
30    this.classUrlTemplate = classUrlTemplate;
31    this.lineUrlTemplate = lineUrlTemplate;
32    this.noTemplate = lineUrlTemplate.equals("") || classUrlTemplate.equals("");
33  }
34
35  public String buildClassLink(String filePath, String anchorText) {
36    if (noTemplate) {
37      return anchorText;
38    }
39    String url = String.format("<a href=\"%s\" target=\"source\">%s</a>", classUrlTemplate,
40            anchorText);
41    url = url.replace("{path}", filePath);
42    return url;
43  }
44
45
46  public String buildLineLink(String filePath, int lineNumber, String anchorText) {
47    if (noTemplate) {
48      return anchorText;
49    }
50    String url = String.format("<a href=\"%s\" target=\"source\">%s</a>", lineUrlTemplate,
51            anchorText);
52    url = url.replace("{path}", filePath);
53    url = url.replace("{line}", "" + lineNumber);
54    return url;
55  }
56
57  public String getOriginalFilePath(String className) {
58    if (noTemplate) {
59      return className;
60    }
61    className = className.replace('.', '/');
62
63    int internalClassDelim = className.indexOf('$');
64    if (internalClassDelim > -1) {
65      className = className.substring(0, internalClassDelim );
66    }
67    return className + ".java";
68  }
69
70}