001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2011 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar 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 * Sonar 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 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.api.web.gwt.client.webservices; 021 022 import com.google.gwt.core.client.JavaScriptObject; 023 import com.google.gwt.json.client.JSONArray; 024 import com.google.gwt.json.client.JSONObject; 025 import org.sonar.api.web.gwt.client.Utils; 026 027 import java.util.ArrayList; 028 import java.util.List; 029 030 /** 031 * @deprecated since 2.5, use {@link org.sonar.wsclient.services.PropertyQuery} instead. 032 */ 033 @Deprecated 034 public final class PropertiesQuery extends Query<Properties> { 035 036 private String key; 037 038 public PropertiesQuery() { 039 } 040 041 public PropertiesQuery(String key) { 042 this.key = key; 043 } 044 045 @Override 046 public String toString() { 047 String url = Utils.getServerApiUrl() + "/properties"; 048 if (key != null) { 049 url += "/" + key; 050 } 051 return url + "?"; 052 } 053 054 @Override 055 public void execute(QueryCallBack<Properties> callback) { 056 JsonUtils.requestJson(this.toString(), new JSONHandlerDispatcher<Properties>(callback) { 057 @Override 058 public Properties parseResponse(JavaScriptObject obj) { 059 return new Properties(parseProperties(obj)); 060 } 061 062 private List<Property> parseProperties(JavaScriptObject obj) { 063 JSONArray array = new JSONArray(obj); 064 List<Property> properties = new ArrayList<Property>(); 065 for (int i = 0; i < array.size(); i++) { 066 JSONObject jsonObject = array.get(i).isObject(); 067 if (jsonObject != null) { 068 properties.add(parseProperty(jsonObject)); 069 } 070 } 071 return properties; 072 } 073 074 private Property parseProperty(JSONObject json) { 075 return new Property(JsonUtils.getString(json, "key"), JsonUtils.getString(json, "value")); 076 } 077 }); 078 } 079 }