All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vmware.vim.rest.ResultConverter Maven / Gradle / Ivy

There is a newer version: 6.0.05
Show newest version
/*================================================================================
Copyright (c) 2009 VMware, Inc. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution.

* Neither the name of VMware, Inc. nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior 
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
================================================================================*/

package com.vmware.vim.rest;

/** The utility to convert the HTML table to XML format.
  * @author Steve JIN ([email protected])
*/

public class ResultConverter
{
  final static String TABLE_START = " \n");
    
    int tableEnd = html.lastIndexOf(TABLE_END);
    convertTable(html, pos, tableEnd, xml);

    xml.append(" ");

    return xml.toString();
  }
  
  private static int convertTable(String html, int from, int to, StringBuffer xml)
  {
    int pos = html.indexOf(TABLE_START, from);
    pos = html.indexOf(TR_START, pos) + TR_START.length();
//    System.out.println("ConvertTable Pos:" + pos);
    
    while( (pos = html.indexOf(TR_START, pos))!= -1)
    {
      if(pos > to)
      {
        return to;
      }
      pos = html.indexOf(TD_START, pos);
      int nameStart = html.indexOf(">", pos) + 1;
      int nameEnd = html.indexOf(TD_END, nameStart);
      String name = html.substring(nameStart, nameEnd);
      
      pos = html.indexOf(TD_START, nameEnd);
      int typeStart = html.indexOf(">", pos) + 1;
      int typeEnd = html.indexOf(TD_END, typeStart);
      String type = html.substring(typeStart, typeEnd);
     
      xml.append("<" + name + " type=\"" + type + "\">");
      
      pos = convertTdValue(html, typeEnd, to, type, xml);

      xml.append("\n");
    }
//    System.out.println("ConvertTable Pos(end):" + pos);
    return pos;
  }
  
  private static int convertTdValue(String html, int from, int to, String type, StringBuffer xml)
  {
    int pos = html.indexOf(TD_START, from);
  
//    System.out.println("ConvertTdValue Pos:" + pos);
    
    String value = "";
    
    if(!isSimpleTdValue(html, pos, to))
    {
      int tableEnd = getTableEnd(html, pos + TD_START.length() + TABLE_START.length(), to-1);
      //System.out.println("tableEnd:" + tableEnd);
//ServiceContent

Name Type Value
aboutAboutInfo
Name Type Value
apiTypestring"HostAgent"
apiVersionstring"2.0.0"
buildstring"62355"
dynamicPropertyDynamicProperty[]Unset
dynamicTypestringUnset
fullNamestring"VMware ESX Server 3.5.0 build-62355"
localeBuildstring"000"
localeVersionstring"INTL"
namestring"VMware ESX Server"
osTypestring"vmnix-x86"
productLineIdstring"esx"
vendorstring"VMware, Inc."
versionstring"3.5.0"
accountManagerManagedObjectReference:HostLocalAccountManagerha-localacctmgr
alarmManagerManagedObjectReference:AlarmManagerUnset
authorizationManagerManagedObjectReference:AuthorizationManagerha-authmgr
customFieldsManagerManagedObjectReference:CustomFieldsManagerUnset
customizationSpecManagerManagedObjectReference:CustomizationSpecManagerUnset
diagnosticManagerManagedObjectReference:DiagnosticManagerha-diagnosticmgr
dynamicPropertyDynamicProperty[]Unset
dynamicTypestringUnset
eventManagerManagedObjectReference:EventManagerha-eventmgr
extensionManagerManagedObjectReference:ExtensionManagerUnset
fileManagerManagedObjectReference:FileManagerha-nfc-file-manager
licenseManagerManagedObjectReference:LicenseManagerha-license-manager
perfManagerManagedObjectReference:PerformanceManagerha-perfmgr
propertyCollectorManagedObjectReference:PropertyCollectorha-property-collector
rootFolderManagedObjectReference:Folderha-folder-root
scheduledTaskManagerManagedObjectReference:ScheduledTaskManagerUnset
searchIndexManagedObjectReference:SearchIndexha-searchindex
sessionManagerManagedObjectReference:SessionManagerha-sessionmgr
settingManagedObjectReference:OptionManagerHostAgentSettings
taskManagerManagedObjectReference:TaskManagerha-taskmgr
userDirectoryManagedObjectReference:UserDirectoryha-user-directory
viewManagerManagedObjectReference:ViewManagerViewManager
virtualDiskManagerManagedObjectReference:VirtualDiskManagerha-vdiskmanager
virtualizationManagerManagedObjectReference:VirtualizationManagerUnset
pos = convertTable(html, pos, tableEnd + TABLE_END.length()+1, xml); //System.out.println("pos:" + pos); } else { int valueStart = html.indexOf(">", pos) + 1; int valueEnd = html.indexOf(TD_END, valueStart); value = html.substring(valueStart, valueEnd); if("Unset".equals(value)) { value=""; } else if("string".equals(type)) { value = value.substring(1, value.length()-1); } else if(value.indexOf("href=")!=-1) { int start = value.indexOf(">"); int end = value.indexOf("", start); value = value.substring(start+1, end); } xml.append(value); } return pos; } private static boolean isSimpleTdValue(String html, int from, int to) { int pos = html.indexOf("




© 2015 - 2024 Weber Informatics LLC | Privacy Policy