-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeedUris.java
More file actions
154 lines (136 loc) · 4.39 KB
/
FeedUris.java
File metadata and controls
154 lines (136 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* Copyright (c) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.gtt;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Contains constants for the various feed uris.
*
*
*/
public class FeedUris {
private static String baseUrl = "http://translate.google.com/toolkit/feeds";
/**
* Prevent instantiation of utility function
*/
private FeedUris() {
}
/**
* @param baseUrlArg the base url for the feeds
*/
public static void setBaseUrl(String baseUrlArg) {
baseUrl = baseUrlArg;
}
/**
* Returns the documents feed url.
*/
public static URL getDocumentsFeedUrl() throws MalformedURLException {
return new URL(baseUrl + "/documents");
}
/**
* Returns the feed url for given document.
*
* @param docId id of the document whose feed url is requried
*/
public static URL getDocumentFeedUrl(String docId)
throws MalformedURLException {
String format = baseUrl + "/documents/%s";
return createUrl(format, docId);
}
/**
* Returns the feed url to use for deleting the given document.
*
* @param docId id of the document whose feed url is requried
*/
public static URL getDocumentPermDeleteUrl(String docId)
throws MalformedURLException {
String format = baseUrl + "/documents/%s?delete=true";
return createUrl(format, docId);
}
/**
* Returns the feed url to use for downloading the given document.
*
* @param docId id of the document whose feed url is requried
*/
public static URL getDocumentDownloadFeedUrl(String docId)
throws MalformedURLException {
String format = baseUrl + "/documents/export/%s";
return createUrl(format, docId);
}
/**
* Returns the translation memories feed url.
*/
public static URL getTranslationMemoriesFeedUrl()
throws MalformedURLException {
return new URL(baseUrl + "/tm");
}
/**
* Returns the feed url for given translation memory.
*
* @param docId id of the translation memory whose feed url is requried
*/
public static URL getTranslationMemoryFeedUrl(String tmId)
throws MalformedURLException {
String format = baseUrl + "/tm/%s";
return createUrl(format, tmId);
}
/**
* Returns the glossaries feed url.
*/
public static URL getGlossariesFeedUrl() throws MalformedURLException {
return new URL(baseUrl + "/glossary");
}
/**
* Returns the feed url for given glossary.
*
* @param docId id of the glossary whose feed url is requried
*/
public static URL getGlossaryFeedUrl(String glossaryId)
throws MalformedURLException {
String format = baseUrl + "/glossary/%s";
return createUrl(format, glossaryId);
}
/**
* Returns the acl feeds url for given feed and entryId.
*
* @param feedName the name of the feed, one of {'documents, 'tm, 'glossary'}
* @param entryId id of the document/translation memory/glossary
* whose feed url is requried
*/
public static URL getAclFeedUrl(String feedName, String entryId)
throws MalformedURLException {
String format = baseUrl + "/acl/%s/%s";
return createUrl(format, feedName, entryId);
}
/**
* Returns the acl feeds url for given feed, entryId and email id.
*
* @param feedName the name of the feed, one of {'documents, 'tm, 'glossary'}
* @param entryId id of the document/translation memory/glossary
* whose feed url is requried
* @param emailId email id of the person relative to whom the feed url is
* required.
*/
public static URL getAclFeedUrl(String feedName, String entryId,
String emailId) throws MalformedURLException {
String format = baseUrl + "/acl/%s/%s/%s";
return createUrl(format, feedName, entryId, emailId);
}
private static URL createUrl(String format, Object... args)
throws MalformedURLException {
String feedUrl = String.format(format, args);
return new URL(feedUrl);
}
}