use of java.net.URISyntaxException in project gitblit by gitblit.
the class RepositoryManager method loadRepositoryModel.
/**
* Create a repository model from the configuration and repository data.
*
* @param repositoryName
* @return a repositoryModel or null if the repository does not exist
*/
private RepositoryModel loadRepositoryModel(String repositoryName) {
Repository r = getRepository(repositoryName);
if (r == null) {
return null;
}
RepositoryModel model = new RepositoryModel();
model.isBare = r.isBare();
File basePath = getRepositoriesFolder();
if (model.isBare) {
model.name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory());
} else {
model.name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory().getParentFile());
}
if (StringUtils.isEmpty(model.name)) {
// Repository is NOT located relative to the base folder because it
// is symlinked. Use the provided repository name.
model.name = repositoryName;
}
model.projectPath = StringUtils.getFirstPathElement(repositoryName);
StoredConfig config = r.getConfig();
boolean hasOrigin = false;
if (config != null) {
// Initialize description from description file
hasOrigin = !StringUtils.isEmpty(config.getString("remote", "origin", "url"));
if (getConfig(config, "description", null) == null) {
File descFile = new File(r.getDirectory(), "description");
if (descFile.exists()) {
String desc = com.gitblit.utils.FileUtils.readContent(descFile, System.getProperty("line.separator"));
if (!desc.toLowerCase().startsWith("unnamed repository")) {
config.setString(Constants.CONFIG_GITBLIT, null, "description", desc);
}
}
}
model.description = getConfig(config, "description", "");
model.originRepository = getConfig(config, "originRepository", null);
model.addOwners(ArrayUtils.fromString(getConfig(config, "owner", "")));
model.acceptNewPatchsets = getConfig(config, "acceptNewPatchsets", true);
model.acceptNewTickets = getConfig(config, "acceptNewTickets", true);
model.requireApproval = getConfig(config, "requireApproval", settings.getBoolean(Keys.tickets.requireApproval, false));
model.mergeTo = getConfig(config, "mergeTo", null);
model.mergeType = MergeType.fromName(getConfig(config, "mergeType", settings.getString(Keys.tickets.mergeType, null)));
model.useIncrementalPushTags = getConfig(config, "useIncrementalPushTags", false);
model.incrementalPushTagPrefix = getConfig(config, "incrementalPushTagPrefix", null);
model.allowForks = getConfig(config, "allowForks", true);
model.accessRestriction = AccessRestrictionType.fromName(getConfig(config, "accessRestriction", settings.getString(Keys.git.defaultAccessRestriction, "PUSH")));
model.authorizationControl = AuthorizationControl.fromName(getConfig(config, "authorizationControl", settings.getString(Keys.git.defaultAuthorizationControl, null)));
model.verifyCommitter = getConfig(config, "verifyCommitter", false);
model.showRemoteBranches = getConfig(config, "showRemoteBranches", hasOrigin);
model.isFrozen = getConfig(config, "isFrozen", false);
model.skipSizeCalculation = getConfig(config, "skipSizeCalculation", false);
model.skipSummaryMetrics = getConfig(config, "skipSummaryMetrics", false);
model.commitMessageRenderer = CommitMessageRenderer.fromName(getConfig(config, "commitMessageRenderer", settings.getString(Keys.web.commitMessageRenderer, null)));
model.federationStrategy = FederationStrategy.fromName(getConfig(config, "federationStrategy", null));
model.federationSets = new ArrayList<String>(Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "federationSets")));
model.isFederated = getConfig(config, "isFederated", false);
model.gcThreshold = getConfig(config, "gcThreshold", settings.getString(Keys.git.defaultGarbageCollectionThreshold, "500KB"));
model.gcPeriod = getConfig(config, "gcPeriod", settings.getInteger(Keys.git.defaultGarbageCollectionPeriod, 7));
try {
model.lastGC = new SimpleDateFormat(Constants.ISO8601).parse(getConfig(config, "lastGC", "1970-01-01'T'00:00:00Z"));
} catch (Exception e) {
model.lastGC = new Date(0);
}
model.maxActivityCommits = getConfig(config, "maxActivityCommits", settings.getInteger(Keys.web.maxActivityCommits, 0));
model.origin = config.getString("remote", "origin", "url");
if (model.origin != null) {
model.origin = model.origin.replace('\\', '/');
model.isMirror = config.getBoolean("remote", "origin", "mirror", false);
}
model.preReceiveScripts = new ArrayList<String>(Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "preReceiveScript")));
model.postReceiveScripts = new ArrayList<String>(Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "postReceiveScript")));
model.mailingLists = new ArrayList<String>(Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "mailingList")));
model.indexedBranches = new ArrayList<String>(Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "indexBranch")));
model.metricAuthorExclusions = new ArrayList<String>(Arrays.asList(config.getStringList(Constants.CONFIG_GITBLIT, null, "metricAuthorExclusions")));
// Custom defined properties
model.customFields = new LinkedHashMap<String, String>();
for (String aProperty : config.getNames(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS)) {
model.customFields.put(aProperty, config.getString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, aProperty));
}
}
model.HEAD = JGitUtils.getHEADRef(r);
if (StringUtils.isEmpty(model.mergeTo)) {
model.mergeTo = model.HEAD;
}
model.availableRefs = JGitUtils.getAvailableHeadTargets(r);
model.sparkleshareId = JGitUtils.getSparkleshareId(r);
model.hasCommits = JGitUtils.hasCommits(r);
updateLastChangeFields(r, model);
r.close();
if (StringUtils.isEmpty(model.originRepository) && model.origin != null && model.origin.startsWith("file://")) {
// repository was cloned locally... perhaps as a fork
try {
File folder = new File(new URI(model.origin));
String originRepo = com.gitblit.utils.FileUtils.getRelativePath(getRepositoriesFolder(), folder);
if (!StringUtils.isEmpty(originRepo)) {
// ensure origin still exists
File repoFolder = new File(getRepositoriesFolder(), originRepo);
if (repoFolder.exists()) {
model.originRepository = originRepo.toLowerCase();
// persist the fork origin
updateConfiguration(r, model);
}
}
} catch (URISyntaxException e) {
logger.error("Failed to determine fork for " + model, e);
}
}
return model;
}
use of java.net.URISyntaxException in project buck by facebook.
the class HttpdForTests method getUri.
public URI getUri(String path) throws URISyntaxException, SocketException {
assertTrue("Server must be running before retrieving a URI, otherwise the resulting URI may " + "not have an appropriate port", isRunning.get());
URI baseUri;
try {
baseUri = server.getURI();
} catch (Exception e) {
// We'd rather catch UnknownHostException, but that's a checked exception that is claimed
// never to be thrown.
baseUri = new URI("http://localhost/");
}
Preconditions.checkNotNull(baseUri, "Unable to determine baseUri");
// we only use the scheme and port that Jetty returned.
return new URI(baseUri.getScheme(), /* user info */
null, localhost, baseUri.getPort(), path, null, null);
}
use of java.net.URISyntaxException in project AndroidSDK-RecipeBook by gabu.
the class Recipe078 method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 名古屋の明日の天気情報を取得できるURLです。
String uri = "http://weather.livedoor.com/forecast/" + "webservice/rest/v1?city=38&day=tomorrow";
// HTTPクライアントを作って
HttpClient client = new DefaultHttpClient();
// GETオブジェクトを作って
HttpGet get = new HttpGet();
try {
// URIをセット
get.setURI(new URI(uri));
// GETリクエストを実行してレスポンスを取得
HttpResponse res = client.execute(get);
// レスポンスからInputStreamを取得
InputStream in = res.getEntity().getContent();
// XMLプルパーサを生成して
XmlPullParser parser = Xml.newPullParser();
// InputStreamをセット
parser.setInput(in, "UTF-8");
int eventType = parser.getEventType();
// イベントタイプがEND_DOCUMENTになるまでループ
// けど、以下の必要な値が全て取得できたらbreakする。
String title = "";
String telop = "";
String description = "";
while (eventType != XmlPullParser.END_DOCUMENT) {
switch(eventType) {
case XmlPullParser.START_TAG:
String tag = parser.getName();
if ("title".equals(tag)) {
// タイトルを取得
title = parser.nextText();
} else if ("telop".equals(tag)) {
// 天気を取得
telop = parser.nextText();
} else if ("description".equals(tag)) {
// 天気概況文を取得
description = parser.nextText();
}
break;
}
if (!("".equals(title) || "".equals(telop) || "".equals(description))) {
// 必要な値が取得できたらループを抜ける
break;
}
// パーサを次のイベントまで進める
eventType = parser.next();
}
// TextViewに表示!
TextView v = (TextView) findViewById(R.id.text);
v.setText(title + "\n\n" + telop + "\n\n" + description);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
use of java.net.URISyntaxException in project camel by apache.
the class UndertowHelper method createMethod.
/**
* Creates the HttpMethod to use to call the remote server, often either its GET or POST.
*/
public static HttpString createMethod(Exchange exchange, UndertowEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
// is a query string provided in the endpoint URI or in a header (header
// overrules endpoint)
String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
// We need also check the HTTP_URI header query part
String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
// resolve placeholders in uriString
try {
uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
}
if (uriString != null) {
URI uri = new URI(uriString);
queryString = uri.getQuery();
}
if (queryString == null) {
queryString = endpoint.getHttpURI().getRawQuery();
}
// compute what method to use either GET or POST
HttpString answer;
String m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, String.class);
if (m != null) {
// always use what end-user provides in a header
answer = new HttpString(m);
} else if (queryString != null) {
// if a query string is provided then use GET
answer = Methods.GET;
} else {
// fallback to POST if we have payload, otherwise GET
answer = hasPayload ? Methods.POST : Methods.GET;
}
return answer;
}
use of java.net.URISyntaxException in project jaggery by wso2.
the class RhinoURISecurityDomain method getCodeSource.
public CodeSource getCodeSource() throws ScriptException {
if (codeSource != null) {
return codeSource;
}
try {
URL url = new URI(scriptURI).toURL();
codeSource = new CodeSource(url, (Certificate[]) null);
return codeSource;
} catch (MalformedURLException e) {
throw new ScriptException(e);
} catch (URISyntaxException e) {
throw new ScriptException(e);
}
}
Aggregations