本文整理汇总了Java中org.apache.commons.httpclient.HttpURL.getURI方法的典型用法代码示例。如果您正苦于以下问题:Java HttpURL.getURI方法的具体用法?Java HttpURL.getURI怎么用?Java HttpURL.getURI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.HttpURL
的用法示例。
在下文中一共展示了HttpURL.getURI方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resourceExists
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
/**
* Returns <code>true</code> if the resource given as URL does exist.
* @param client
* @param httpURL
* @return <code>true</code>if the resource exists
* @throws IOException
* @throws HttpException
*/
public static boolean resourceExists(HttpClient client, HttpURL httpURL)
throws IOException, HttpException
{
HeadMethod head = new HeadMethod(httpURL.getURI());
head.setFollowRedirects(true);
int status = client.executeMethod(head);
switch (status) {
case WebdavStatus.SC_OK:
return true;
case WebdavStatus.SC_NOT_FOUND:
return false;
default:
HttpException ex = new HttpException();
ex.setReasonCode(status);
ex.setReason(head.getStatusText());
throw ex;
}
}
示例2: putFile
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
public static void putFile(HttpClient client,
HttpURL url,
InputStream is,
String contentType,
String lockToken)
throws IOException, HttpException
{
PutMethod put = new PutMethod(url.getURI());
generateIfHeader(put, lockToken);
put.setRequestHeader("Content-Type", contentType);
put.setRequestBody(is);
put.setFollowRedirects(true);
int status = client.executeMethod(put);
switch (status) {
case WebdavStatus.SC_OK:
case WebdavStatus.SC_CREATED:
case WebdavStatus.SC_NO_CONTENT:
return;
default:
HttpException ex = new HttpException();
ex.setReason(put.getStatusText());
ex.setReasonCode(status);
throw ex;
}
}
示例3: unlockResource
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
public static void unlockResource(HttpClient client, HttpURL url,
String lockToken)
throws IOException, HttpException
{
UnlockMethod unlock = new UnlockMethod(url.getURI(), lockToken);
unlock.setFollowRedirects(true);
int status = client.executeMethod(unlock);
switch (status) {
case WebdavStatus.SC_OK:
case WebdavStatus.SC_NO_CONTENT:
return;
default:
HttpException ex = new HttpException();
ex.setReasonCode(status);
ex.setReason(unlock.getStatusText());
throw ex;
}
}
示例4: copyResource
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
public static void copyResource(HttpClient client, HttpURL url,
String destination, int depth, boolean overwrite)
throws IOException, HttpException
{
CopyMethod copy = new CopyMethod(
url.getURI(),
destination,
overwrite,
depth);
copy.setFollowRedirects(true);
int status = client.executeMethod(copy);
switch (status) {
case WebdavStatus.SC_OK:
case WebdavStatus.SC_CREATED:
case WebdavStatus.SC_NO_CONTENT:
return;
default:
HttpException ex = new HttpException();
ex.setReasonCode(status);
ex.setReason(copy.getStatusText());
throw ex;
}
}
示例5: moveResource
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
public static void moveResource(HttpClient client, HttpURL url,
String destination, boolean overwrite)
throws IOException, HttpException
{
MoveMethod move = new MoveMethod(url.getURI(), destination, overwrite);
move.setFollowRedirects(true);
int status = client.executeMethod(move);
switch (status) {
case WebdavStatus.SC_OK:
case WebdavStatus.SC_CREATED:
case WebdavStatus.SC_NO_CONTENT:
return;
default:
HttpException ex = new HttpException();
ex.setReasonCode(status);
ex.setReason(move.getStatusText());
throw ex;
}
}
示例6: collectionExists
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
public static boolean collectionExists(HttpClient client, HttpURL httpURL)
throws IOException, HttpException
{
Vector props = new Vector(1);
props.add(RESOURCETYPE);
PropFindMethod propFind = new PropFindMethod(httpURL.getURI(),
0, PropFindMethod.BY_NAME);
propFind.setFollowRedirects(true);
propFind.setPropertyNames(props.elements());
int status = client.executeMethod(propFind);
switch (status) {
case WebdavStatus.SC_MULTI_STATUS:
Property p = findProperty(propFind, RESOURCETYPE, httpURL.getPath());
if (p instanceof ResourceTypeProperty) {
return ((ResourceTypeProperty)p).isCollection();
} else {
throw new WebdavException("PROPFFIND does not return resourcetype");
}
case WebdavStatus.SC_NOT_FOUND:
return false;
default:
HttpException ex = new HttpException();
ex.setReasonCode(status);
ex.setReason(propFind.getStatusText());
throw ex;
}
}
示例7: getLastModified
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
public static long getLastModified(HttpClient client, HttpURL url)
throws IOException, HttpException
{
Vector props = new Vector(1);
props.add(GETLASTMODIFIED);
PropFindMethod propFind = new PropFindMethod(url.getURI(), 0);
propFind.setPropertyNames(props.elements());
propFind.setFollowRedirects(true);
int status = client.executeMethod(propFind);
switch (status) {
case WebdavStatus.SC_MULTI_STATUS:
Property p = findProperty(propFind, GETLASTMODIFIED, url.getPath());
if (p != null) {
try {
Date d = GETLASTMODIFIED_FORMAT.parse(p.getPropertyAsString());
return d.getTime();
}
catch (ParseException e) {
throw new HttpException("Invalid lastmodified property: " +
p.getPropertyAsString());
}
}
throw new HttpException("PROPFIND does not return lastmodified.");
default:
HttpException ex = new HttpException();
ex.setReasonCode(status);
ex.setReason(propFind.getStatusText());
throw ex;
}
}
示例8: assureExistingCollection
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
/**
*
* @param client
* @param httpURL
* @param lockToken the locktoken to be used or <code>null</code> if
* none is to be used
* @throws IOException
* @throws HttpException
*/
public static boolean assureExistingCollection(HttpClient client,
HttpURL httpURL,
String lockToken)
throws IOException, HttpException
{
String path = httpURL.getPath();
if (!path.endsWith("/")) {
path = path + "/";
}
Stack toBeCreated = new Stack();
while (!path.equals("/")) {
HttpURL parent = Utils.createHttpURL(httpURL, path);
if (!collectionExists(client, parent)) {
toBeCreated.push(path);
path = path.substring(0, path.lastIndexOf("/", path.length()-2)+1);
} else {
break;
}
}
boolean created = !toBeCreated.empty();
while(!toBeCreated.empty()) {
HttpURL newColl = Utils.createHttpURL(httpURL, (String)toBeCreated.pop());
MkcolMethod mkcol = new MkcolMethod(newColl.getURI());
mkcol.setFollowRedirects(true);
generateIfHeader(mkcol, lockToken);
int status = client.executeMethod(mkcol);
if (status != WebdavStatus.SC_CREATED) {
HttpException ex = new HttpException("Can't create collection " +
newColl);
ex.setReasonCode(status);
ex.setReason(mkcol.getStatusText());
throw ex;
}
}
return created;
}
示例9: readCollection
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
protected void readCollection(HttpURL collURL)
throws URIException
{
if (!collURL.getPath().endsWith(SEPARATOR)) {
collURL = Utils.createHttpURL(collURL, "");
collURL.setPath(collURL.getPath() + SEPARATOR);
}
// get a list of all resources from the given URL
PropFindMethod propFind = new PropFindMethod(collURL.getURI(),
DepthSupport.DEPTH_1,
PropFindMethod.BY_NAME);
propFind.setPropertyNames(propertyNames.elements());
propFind.setFollowRedirects(true);
try {
this.client.executeMethod(propFind);
}
catch (IOException e) {
Utils.makeBuildException("Can't read collection content!", e);
}
List subCollections = new ArrayList();
this.properties.storeProperties(propFind);
// this collection
addResource(collURL.getPath(), true);
// for each content element, check resource type and classify
for (Enumeration e = propFind.getAllResponseURLs(); e.hasMoreElements(); )
{
String href = (String) e.nextElement();
ResourceTypeProperty property =
this.properties.getResourceType(collURL, href);
if (property != null) {
if (property.isCollection()) {
if (!href.endsWith(SEPARATOR)) href = href + SEPARATOR;
// the collection URL itself may be in the list of
// response URL; filter them out to avoid recursion
HttpURL sub = Utils.createHttpURL(collURL, href);
if (!sub.equals(collURL)) {
subCollections.add(Utils.createHttpURL(collURL, href));
}
} else {
addResource(href, false);
}
} else {
throw new BuildException("Can't determine resourcetype.");
}
}
// read all sub collections
for(Iterator i = subCollections.iterator(); i.hasNext();) {
readCollection((HttpURL)i.next());
}
}
示例10: proppatch
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
protected void proppatch(HttpURL url, String logName)
throws IOException, HttpException
{
log(logName, ifVerbose());
PropPatchMethod propPatch = new PropPatchMethod(url.getURI());
if (this.locktoken != null) {
Utils.generateIfHeader(propPatch, this.locktoken);
}
int c = 1;
for(Iterator i = toRemove.iterator(); i.hasNext(); ) {
Remove r = (Remove)i.next();
propPatch.addPropertyToRemove(r.name,
r.abbrev != null ? r.abbrev : "NS"+(c++),
r.namespace);
}
for(Iterator i = toSet.iterator(); i.hasNext(); ) {
Set a = (Set)i.next();
propPatch.addPropertyToSet(a.name,
a.getValue(),
a.abbrev != null ? a.abbrev : "NS"+(c++),
a.namespace);
}
int status = getHttpClient().executeMethod(propPatch);
count++;
switch (status) {
case WebdavStatus.SC_OK:
// ok
break;
case WebdavStatus.SC_MULTI_STATUS:
for(Enumeration e = propPatch.getResponses(); e.hasMoreElements();) {
ResponseEntity response = (ResponseEntity)e.nextElement();
if (response.getStatusCode() > 400) {
throw Utils.makeBuildException("Error while PROPPATCH",
propPatch.getResponses());
}
}
break;
default:
HttpException ex = new HttpException();
ex.setReasonCode(status);
throw ex;
}
}
示例11: WebdavFile
import org.apache.commons.httpclient.HttpURL; //导入方法依赖的package包/类
/**
* @param httpUrl Webdav URL
*/
public WebdavFile(HttpURL httpUrl) throws URIException {
super(httpUrl.getURI());
this.httpUrl = httpUrl;
}