本文整理汇总了Java中org.restlet.data.Response.getEntityAsDom方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getEntityAsDom方法的具体用法?Java Response.getEntityAsDom怎么用?Java Response.getEntityAsDom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.data.Response
的用法示例。
在下文中一共展示了Response.getEntityAsDom方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInfo
import org.restlet.data.Response; //导入方法依赖的package包/类
private static List<String> getInfo(ConnectionProperties cp, String listUri) throws RancidApiException{
if (!inited){
throw(new RancidApiException("Error: Api not initialized"));
}
String url = cp.getUrl()+cp.getDirectory()+listUri;
Response response=getMethodRWS(cp, url);
DomRepresentation dmr = response.getEntityAsDom();
List<String> data = new ArrayList<String>();
try {
Document doc = dmr.getDocument();
for (int ii = 0; ii < doc.getElementsByTagName("Resource").getLength() ; ii++) {
data.add(doc.getElementsByTagName("Resource").item(ii).getTextContent());
}
}
catch(final IOException e){
throw(new RancidApiException("Error: IOException Method GET: URL:" +url + ":" + e.getMessage(), RancidApiException.OTHER_ERROR));
}
return data;
}
示例2: getRWSRancidNodeTLO
import org.restlet.data.Response; //导入方法依赖的package包/类
public static RancidNode getRWSRancidNodeTLO(ConnectionProperties cp ,String group, String devicename) throws RancidApiException{
if (!inited){
throw(new RancidApiException("Error: Api not initialized"));
}
String url = cp.getUrl() + cp.getDirectory()+"/rancid/groups/" + group + "/" + devicename;
Response response =getMethodRWS(cp, url);
DomRepresentation dmr = response.getEntityAsDom();
RancidNode rn = new RancidNode();
try {
Document doc = dmr.getDocument();
rn.setDeviceName(devicename);
rn.setDeviceType(safeGetElement(doc, "deviceType"));
String stateUp = safeGetElement(doc, "state");
rn.setStateUp(stateUp != null && stateUp.compareTo("up") == 0);
rn.setComment(safeGetElement(doc, "comment"));
rn.setGroup(group);
}
catch( IOException e){
throw(new RancidApiException("Error: IOException Method GET: URL:" +url + ":" + e.getMessage(), RancidApiException.OTHER_ERROR));
}
return rn;
}
示例3: getRWSAuthNode
import org.restlet.data.Response; //导入方法依赖的package包/类
public static RancidNodeAuthentication getRWSAuthNode(ConnectionProperties cp, String devicename) throws RancidApiException{
if (!inited){
throw(new RancidApiException("Error: Api not initialized"));
}
String url = cp.getUrl() + cp.getDirectory()+"/rancid/clogin/" + devicename;
Response response = getMethodRWS(cp, url);
DomRepresentation dmr = response.getEntityAsDom();
RancidNodeAuthentication rna = new RancidNodeAuthentication();
try {
Document doc = dmr.getDocument();
rna.setDeviceName(devicename);
rna.setUser(safeGetElement(doc, "user"));
rna.setPassword(safeGetElement(doc, "password"));
rna.setEnablePass(safeGetElement(doc, "enablepassword"));
rna.setConnectionMethod(safeGetElement(doc, "method"));
rna.setAutoEnable(false);
final String autoEnable = safeGetElement(doc, "autoenable");
if (autoEnable != null && autoEnable.compareTo("1") == 0) {
rna.setAutoEnable(true);
}
}
catch( IOException e){
throw(new RancidApiException("Error: IOException Method GET: URL:" +url+ ":" + e.getMessage(), RancidApiException.OTHER_ERROR));
}
return rna;
}
示例4: getBucket
import org.restlet.data.Response; //导入方法依赖的package包/类
public static RWSBucket getBucket(ConnectionProperties cp, String bucketName ) throws RancidApiException {
if (!inited){
throw(new RancidApiException("Error: Api not initialized"));
}
String url = cp.getUrl() + cp.getDirectory()+"/storage/buckets/" + bucketName;
Response response = getMethodRWS(cp, url);
DomRepresentation dmr = response.getEntityAsDom();
RWSBucket bucket = new RWSBucket(bucketName);
try {
Document doc = dmr.getDocument();
int fileNumber = doc.getElementsByTagName("File").getLength();
bucket.setBucketItem(new ArrayList<BucketItem>(fileNumber));
for (int j = 0 ; j < fileNumber ; j++){
String itemName="";
int itemSize=0;
Date itemDate=null;
for (int i = 0; i < doc.getElementsByTagName("File").item(j).getChildNodes().getLength(); i++) {
LOG.debug("Item:" + i +" NodeName: " + doc.getElementsByTagName("File").item(j).getChildNodes().item(i).getNodeName());
LOG.debug("Item:" + i +" NodeTextContent: " + doc.getElementsByTagName("File").item(j).getChildNodes().item(i).getTextContent());
if ("Name".equals(doc.getElementsByTagName("File").item(j).getChildNodes().item(i).getNodeName())) {
itemName = doc.getElementsByTagName("File").item(j).getChildNodes().item(i).getTextContent();
} else if ("Size".equals(doc.getElementsByTagName("File").item(j).getChildNodes().item(i).getNodeName())) {
itemSize = Integer.parseInt(doc.getElementsByTagName("File").item(j).getChildNodes().item(i).getTextContent());
} else if ("LastModified".equals(doc.getElementsByTagName("File").item(j).getChildNodes().item(i).getNodeName())) {
SimpleDateFormat format = new SimpleDateFormat("yyyy/M/d H:m:s z");
itemDate = format.parse(doc.getElementsByTagName("File").item(j).getChildNodes().item(i).getTextContent());
}
}
bucket.setBucket(j, itemName, itemSize, itemDate);
}
} catch (IOException e) {
throw(new RancidApiException("Error: IOException Method GET: URL:" +url+ ":" + e.getMessage(), RancidApiException.OTHER_ERROR));
} catch (ParseException pe) {
throw(new RancidApiException("Error: ParseException Method GET: URL:" +url+ ":" + pe.getMessage(), RancidApiException.OTHER_ERROR));
}
return bucket;
}