@Override
 public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
   checkArgument(
       checkNotNull(payload, "memoryInMB") instanceof Integer,
       "this binder is only valid for Integers!");
   Integer memoryInMB = Integer.class.cast(payload);
   XMLBuilder cpuItem;
   try {
     cpuItem = XMLBuilder.create("Item").a("xmlns", ns).a("xmlns:rasd", RESOURCE_ALLOCATION_NS);
     cpuItem.e("rasd:AllocationUnits").t("byte * 2^20");
     cpuItem.e("rasd:Description").t("Memory Size");
     cpuItem.e("rasd:ElementName").t(memoryInMB.toString() + " MB of memory");
     cpuItem.e("rasd:InstanceID").t("5");
     cpuItem.e("rasd:Reservation").t("0");
     cpuItem.e("rasd:ResourceType").t(ResourceType.MEMORY.value());
     cpuItem.e("rasd:VirtualQuantity").t(memoryInMB.toString());
     cpuItem.e("rasd:Weight").t("0");
     Properties outputProperties = new Properties();
     outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
     request = super.bindToRequest(request, cpuItem.asString(outputProperties));
   } catch (Exception e) {
     Throwables.propagate(e);
   }
   return request;
 }
예제 #2
0
  private String combineData() {
    String content = "";
    XMLBuilder builder = null;
    int index = 0;
    String[] tags;

    boolean isEntry = contentArray.size() != 2;

    if (isEntry) {
      tags =
          new String[] {
            "date-created",
            "time-created",
            "latitude",
            "longitude",
            "first-name",
            "middle-name",
            "last-name",
            "birthday",
            "age",
            "gender",
            "address",
            "slide-number",
            "region",
            "case",
            "species",
            "drugs-given",
            "exam-result",
            "remarks"
          };
    } else {
      tags = new String[] {"user", "pass"};
    }

    try {
      if (isEntry) builder = XMLBuilder.create("entry");
      else builder = XMLBuilder.create("credentials");
      Log.d("MakeTextFile", String.valueOf(contentArray.size()));
      for (String data : contentArray) {
        builder.element(tags[index++]).text(data);
        Log.v("WRITE", "CONTENT: " + data);
      }

      Properties outputProperties = new Properties();
      outputProperties.put(javax.xml.transform.OutputKeys.METHOD, "xml");
      outputProperties.put(javax.xml.transform.OutputKeys.INDENT, "yes");
      outputProperties.put("{http://xml.apache.org/xslt}indent-amount", "2");
      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");

      content = builder.asString(outputProperties);

    } catch (ParserConfigurationException e) {
      e.printStackTrace();
    } catch (TransformerException e) {
      e.printStackTrace();
    }

    return content;
  }