Package com.jamesmurty.utils

Examples of com.jamesmurty.utils.XMLBuilder


   }

   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 String generateXml(String templateName, URI entity, CatalogItemOptions options)
            throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
      XMLBuilder rootBuilder = buildRoot(templateName);
      if (options.getDescription() != null)
         rootBuilder.e("Description").t(options.getDescription());
      rootBuilder.e("Entity").a("href", entity.toASCIIString());
      for (Entry<String, String> entry : options.getProperties().entrySet()) {
         rootBuilder.e("Property").a("key", entry.getKey()).t(entry.getValue());
      }
      Properties outputProperties = new Properties();
      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
      return rootBuilder.asString(outputProperties);
   }
View Full Code Here

      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
      return rootBuilder.asString(outputProperties);
   }

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

      O options = findOptionsInArgsOrNew(gRequest);
      return stringBinder.bindToRequest(request, generateXml(name, source, isSourceDelete, options));
   }

   protected String generateXml(String name, String source, boolean isSourceDelete, O options) {
      XMLBuilder rootBuilder = buildRoot(name, options);
      addElementsUnderRoot(rootBuilder, source, options, isSourceDelete);
      Properties outputProperties = new Properties();
      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
      try {
         return rootBuilder.asString(outputProperties);
      } catch (Exception e) {
         throw Throwables.propagate(e);
      }
   }
View Full Code Here

   @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;
   }
View Full Code Here

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

         if (net.getPrimaryNetworkConnectionIndex() != null)
            networkConnectionSection.e("PrimaryNetworkConnectionIndex").t(
                  net.getPrimaryNetworkConnectionIndex().toString());
         for (NetworkConnection networkConnection : net.getConnections()) {
            XMLBuilder networkConnectionSectionChild = networkConnectionSection.e("NetworkConnection").a("network",
                  networkConnection.getNetwork());
            networkConnectionSectionChild.e("NetworkConnectionIndex").t(
                  networkConnection.getNetworkConnectionIndex() + "");
            if (networkConnection.getExternalIpAddress() != null)
               networkConnectionSectionChild.e("ExternalIpAddress").t(networkConnection.getExternalIpAddress());
            if (networkConnection.getIpAddress() != null)
               networkConnectionSectionChild.e("IpAddress").t(networkConnection.getIpAddress());
            networkConnectionSectionChild.e("IsConnected").t(networkConnection.isConnected() + "");
            if (networkConnection.getMACAddress() != null)
               networkConnectionSectionChild.e("MACAddress").t(networkConnection.getMACAddress());
            if (networkConnection.getIpAddressAllocationMode() != null)
               networkConnectionSectionChild.e("IpAddressAllocationMode").t(
                     networkConnection.getIpAddressAllocationMode().toString());
         }

         if (net.getEdit() != null)
            networkConnectionSection.e("Link").a("rel", "edit").a("type", net.getType())
View Full Code Here

   }

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

      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
      return rootBuilder.asString(outputProperties);
   }

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

      }
   }

   private String generateXml(Map<String, Object> postParams) throws ParserConfigurationException,
            FactoryConfigurationError, TransformerException {
      XMLBuilder rootBuilder = XMLBuilder.create(element);
      for (Entry<String, Object> entry : postParams.entrySet())
         rootBuilder.a(entry.getKey(), (String) entry.getValue());
      rootBuilder.a("xmlns", ns);
      Properties outputProperties = new Properties();
      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
      return rootBuilder.asString(outputProperties);
   }
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.