001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2013 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * SonarQube is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.wsclient.services; 021 022public class SourceQuery extends Query<Source> { 023 public static final String BASE_URL = "/api/sources"; 024 025 private String resourceKeyOrId; 026 private int from = 0; 027 private int to = 0; 028 029 public SourceQuery(String resourceKeyOrId) { 030 this.resourceKeyOrId = resourceKeyOrId; 031 } 032 033 public String getResourceKeyOrId() { 034 return resourceKeyOrId; 035 } 036 037 public SourceQuery setResourceKeyOrId(String resourceKeyOrId) { 038 this.resourceKeyOrId = resourceKeyOrId; 039 return this; 040 } 041 042 public int getFrom() { 043 return from; 044 } 045 046 /** 047 * Get only a few lines 048 * 049 * @param from Index of the first line, starts to 1 050 * @param excludedTo Index of the last line (excluded). 051 */ 052 public SourceQuery setFromLineToLine(int from, int excludedTo) { 053 this.from = from; 054 this.to = excludedTo; 055 return this; 056 } 057 058 public SourceQuery setLinesFromLine(int from, int length) { 059 this.from = from; 060 this.to = from + length; 061 return this; 062 } 063 064 public int getTo() { 065 return to; 066 } 067 068 @Override 069 public String getUrl() { 070 StringBuilder url = new StringBuilder(BASE_URL); 071 url.append('?'); 072 appendUrlParameter(url, "resource", resourceKeyOrId); 073 if (from > 0 && to > 0) { 074 url.append("from=").append(from).append("&to=").append(to).append("&"); 075 } 076 return url.toString(); 077 } 078 079 @Override 080 public Class<Source> getModelClass() { 081 return Source.class; 082 } 083 084 public static SourceQuery create(String resourceKeyOrId) { 085 return new SourceQuery(resourceKeyOrId); 086 } 087}