Package com.jamesmurty.utils

Examples of com.jamesmurty.utils.XMLBuilder


   @Override
   public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
      checkArgument(checkNotNull(payload, "cpuCount") instanceof Integer, "this binder is only valid for Integers!");
      Integer cpuCount = 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("hertz * 10^6");
         cpuItem.e("rasd:Description").t("Number of Virtual CPUs");
         cpuItem.e("rasd:ElementName").t(cpuCount.toString() + " virtual CPU(s)");
         cpuItem.e("rasd:InstanceID").t("4");
         cpuItem.e("rasd:ResourceType").t(ResourceType.PROCESSOR.value());
         cpuItem.e("rasd:VirtualQuantity").t(cpuCount.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;
   }
View Full Code Here


   @Override
   public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
      checkArgument(checkNotNull(payload, "GuestCustomizationSection") instanceof GuestCustomizationSection,
               "this binder is only valid for GuestCustomizationSection!");
      GuestCustomizationSection guest = GuestCustomizationSection.class.cast(payload);
      XMLBuilder guestCustomizationSection;
      try {
         guestCustomizationSection = XMLBuilder.create("GuestCustomizationSection").a("xmlns", ns).a("xmlns:ovf",
                  "http://schemas.dmtf.org/ovf/envelope/1").a("type", guest.getType()).a("href",
                  guest.getHref().toASCIIString()).a("ovf:required", "false");
         guestCustomizationSection.e("ovf:Info").t(guest.getInfo());

         if (guest.isEnabled() != null)
            guestCustomizationSection.e("Enabled").t(guest.isEnabled().toString());
         if (guest.shouldChangeSid() != null)
            guestCustomizationSection.e("ChangeSid").t(guest.shouldChangeSid().toString());
         if (guest.getVirtualMachineId() != null)
            guestCustomizationSection.e("VirtualMachineId").t(guest.getVirtualMachineId().toString());
         if (guest.isJoinDomainEnabled() != null)
            guestCustomizationSection.e("JoinDomainEnabled").t(guest.isJoinDomainEnabled().toString());
         if (guest.shouldUseOrgSettings() != null)
            guestCustomizationSection.e("UseOrgSettings").t(guest.shouldUseOrgSettings().toString());
         if (guest.getDomainName() != null)
            guestCustomizationSection.e("DomainName").t(guest.getDomainName().toString());
         if (guest.getDomainUserName() != null)
            guestCustomizationSection.e("DomainUserName").t(guest.getDomainUserName().toString());
         if (guest.getDomainUserPassword() != null)
            guestCustomizationSection.e("DomainUserPassword").t(guest.getDomainUserPassword().toString());
         if (guest.isAdminPasswordEnabled() != null)
            guestCustomizationSection.e("AdminPasswordEnabled").t(guest.isAdminPasswordEnabled().toString());
         if (guest.isAdminPasswordAuto() != null)
            guestCustomizationSection.e("AdminPasswordAuto").t(guest.isAdminPasswordAuto().toString());
         // if (guest.getAdminPassword() != null)
         // guestCustomizationSection.e("AdminPassword").t(guest.getAdminPassword().toString());
         if (guest.isResetPasswordRequired() != null)
            guestCustomizationSection.e("ResetPasswordRequired").t(guest.isResetPasswordRequired().toString());
         if (guest.getCustomizationScript() != null)
            guestCustomizationSection.e("CustomizationScript").t(guest.getCustomizationScript());
         if (guest.getComputerName() != null)
            guestCustomizationSection.e("ComputerName").t(guest.getComputerName().toString());
         if (guest.getEdit() != null)
            guestCustomizationSection.e("Link").a("rel", "edit").a("type", guest.getType()).a("href",
                     guest.getHref().toASCIIString());

         Properties outputProperties = new Properties();
         outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
         request =  super.bindToRequest(request, guestCustomizationSection.asString(outputProperties));
         request.getPayload().getContentMetadata().setContentType(guest.getType());
      } catch (Exception e) {
         Throwables.propagate(e);
      }
      return request;
View Full Code Here

      return request;
   }

   protected XMLBuilder generateBuilder(BucketLogging bucketLogging) throws ParserConfigurationException,
         FactoryConfigurationError {
      XMLBuilder rootBuilder = XMLBuilder.create("BucketLoggingStatus")
            .attr("xmlns", S3Constants.S3_REST_API_XML_NAMESPACE).e("LoggingEnabled");
      rootBuilder.e("TargetBucket").t(bucketLogging.getTargetBucket());
      rootBuilder.e("TargetPrefix").t(bucketLogging.getTargetPrefix());
      XMLBuilder grantsBuilder = rootBuilder.elem("TargetGrants");
      for (Grant grant : bucketLogging.getTargetGrants()) {
         XMLBuilder grantBuilder = grantsBuilder.elem("Grant");
         XMLBuilder granteeBuilder = grantBuilder.elem("Grantee").attr("xmlns:xsi",
               "http://www.w3.org/2001/XMLSchema-instance");

         if (grant.getGrantee() instanceof GroupGrantee) {
            granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier());
         } else if (grant.getGrantee() instanceof CanonicalUserGrantee) {
            CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee();
            granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up();
            if (grantee.getDisplayName() != null) {
               granteeBuilder.elem("DisplayName").text(grantee.getDisplayName());
            }
         } else if (grant.getGrantee() instanceof EmailAddressGrantee) {
            granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress")
                  .text(grant.getGrantee().getIdentifier());
         }
         grantBuilder.elem("Permission").text(grant.getPermission().toString());
      }
      return grantsBuilder;
View Full Code Here

      return request;
   }

   protected XMLBuilder generateBuilder(AccessControlList acl) throws ParserConfigurationException,
         FactoryConfigurationError {
      XMLBuilder rootBuilder = XMLBuilder.create("AccessControlPolicy").attr("xmlns",
            S3Constants.S3_REST_API_XML_NAMESPACE);
      if (acl.getOwner() != null) {
         XMLBuilder ownerBuilder = rootBuilder.elem("Owner");
         ownerBuilder.elem("ID").text(acl.getOwner().getId()).up();
         if (acl.getOwner().getDisplayName() != null) {
            ownerBuilder.elem("DisplayName").text(acl.getOwner().getDisplayName()).up();
         }
      }
      XMLBuilder grantsBuilder = rootBuilder.elem("AccessControlList");
      for (Grant grant : acl.getGrants()) {
         XMLBuilder grantBuilder = grantsBuilder.elem("Grant");
         XMLBuilder granteeBuilder = grantBuilder.elem("Grantee").attr("xmlns:xsi",
               "http://www.w3.org/2001/XMLSchema-instance");

         if (grant.getGrantee() instanceof GroupGrantee) {
            granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier());
         } else if (grant.getGrantee() instanceof CanonicalUserGrantee) {
            CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee();
            granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up();
            if (grantee.getDisplayName() != null) {
               granteeBuilder.elem("DisplayName").text(grantee.getDisplayName());
            }
         } else if (grant.getGrantee() instanceof EmailAddressGrantee) {
            granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress")
                  .text(grant.getGrantee().getIdentifier());
         }
         grantBuilder.elem("Permission").text(grant.getPermission().toString());
      }
      return grantsBuilder;
View Full Code Here

   }

   protected String generateXml(String name, @Nullable String description, boolean deploy, boolean powerOn,
         URI template, Iterable<NetworkConfig> networkConfig)
         throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
      XMLBuilder rootBuilder = buildRoot(name).a("deploy", deploy + "").a("powerOn", powerOn + "");
      if (description != null)
         rootBuilder.e("Description").t(description);
      XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
      addNetworkConfig(instantiationParamsBuilder, networkConfig);
      rootBuilder.e("Source").a("href", template.toASCIIString());
      rootBuilder.e("AllEULAsAccepted").t("true");

      Properties outputProperties = new Properties();
View Full Code Here

      return rootBuilder.asString(outputProperties);
   }

   protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder,
         Iterable<NetworkConfig> networkConfig) {
      XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection");
      networkConfigBuilder.e("ovf:Info").t("Configuration parameters for logical networks");
      for (NetworkConfig n : networkConfig) {
         XMLBuilder configurationBuilder = networkConfigBuilder.e("NetworkConfig").a("networkName", n.getNetworkName())
               .e("Configuration");
         configurationBuilder.e("ParentNetwork").a("href", n.getParentNetwork().toASCIIString());
         if (n.getFenceMode() != null) {
            configurationBuilder.e("FenceMode").t(n.getFenceMode().toString());
         }
      }
   }
View Full Code Here

   }

   protected XMLBuilder buildRoot(String name, boolean deploy, boolean powerOn) throws ParserConfigurationException,
         FactoryConfigurationError {
      XMLBuilder rootBuilder = XMLBuilder.create("CloneVAppParams").a("name", name).a("deploy", deploy + "")
            .a("powerOn", powerOn + "").a("xmlns", ns).a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
            .a("xsi:schemaLocation", ns + " " + schema);
      return rootBuilder;
   }
View Full Code Here

      return rootBuilder;
   }

   protected String generateXml(String newName, String vApp, CloneVAppOptions options)
         throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
      XMLBuilder rootBuilder = buildRoot(newName, options.isDeploy(), options.isPowerOn());
      if (options.getDescription() != null)
         rootBuilder.e("Description").text(options.getDescription());
      rootBuilder.e("VApp").a("xmlns", ns).a("href", vApp).a("type", TerremarkVCloudMediaType.VAPP_XML);
      Properties outputProperties = new Properties();
      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
      return rootBuilder.asString(outputProperties);
   }
View Full Code Here

   }

   protected String generateXml(String name, String template, SortedMap<ResourceType, String> virtualHardwareQuantity,
         String networkName, @Nullable String fenceMode, URI network) throws ParserConfigurationException,
         FactoryConfigurationError, TransformerException {
      XMLBuilder rootBuilder = buildRoot(name);

      rootBuilder.e("VAppTemplate").a("href", template);

      XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
      addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity);
      addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode, network);
      Properties outputProperties = new Properties();
      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
      return rootBuilder.asString(outputProperties);
View Full Code Here

      return rootBuilder.asString(outputProperties);
   }

   protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, @Nullable String fenceMode,
         URI network) {
      XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e("NetworkConfig")
            .a("name", name);
      if (fenceMode != null) {
         XMLBuilder featuresBuilder = networkConfigBuilder.e("Features");
         featuresBuilder.e("FenceMode").t(fenceMode);
      }
      networkConfigBuilder.e("NetworkAssociation").a("href", network.toASCIIString());
   }
View Full Code Here

TOP

Related Classes of com.jamesmurty.utils.XMLBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.