当前位置: 首页>>代码示例>>Java>>正文


Java Response.getEntityAsDom方法代码示例

本文整理汇总了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;
    }
 
开发者ID:OpenNMS,项目名称:rancid-api,代码行数:25,代码来源:RWSClientApi.java

示例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;
 }
 
开发者ID:OpenNMS,项目名称:rancid-api,代码行数:29,代码来源:RWSClientApi.java

示例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;
}
 
开发者ID:OpenNMS,项目名称:rancid-api,代码行数:32,代码来源:RWSClientApi.java

示例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;

  }
 
开发者ID:OpenNMS,项目名称:rancid-api,代码行数:49,代码来源:RWSClientApi.java


注:本文中的org.restlet.data.Response.getEntityAsDom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。