com.vmware.vim.rest.ResultConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yavijava Show documentation
Show all versions of yavijava Show documentation
Java library for VMware vSphere
/*================================================================================
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("" + name +">\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 about AboutInfo Name Type Value apiType string "HostAgent" apiVersion string "2.0.0" build string "62355" dynamicProperty DynamicProperty[] Unset dynamicType string Unset fullName string "VMware ESX Server 3.5.0 build-62355" localeBuild string "000" localeVersion string "INTL" name string "VMware ESX Server" osType string "vmnix-x86" productLineId string "esx" vendor string "VMware, Inc." version string "3.5.0"
accountManager ManagedObjectReference:HostLocalAccountManager ha-localacctmgr alarmManager ManagedObjectReference:AlarmManager Unset authorizationManager ManagedObjectReference:AuthorizationManager ha-authmgr customFieldsManager ManagedObjectReference:CustomFieldsManager Unset customizationSpecManager ManagedObjectReference:CustomizationSpecManager Unset diagnosticManager ManagedObjectReference:DiagnosticManager ha-diagnosticmgr dynamicProperty DynamicProperty[] Unset dynamicType string Unset eventManager ManagedObjectReference:EventManager ha-eventmgr extensionManager ManagedObjectReference:ExtensionManager Unset fileManager ManagedObjectReference:FileManager ha-nfc-file-manager licenseManager ManagedObjectReference:LicenseManager ha-license-manager perfManager ManagedObjectReference:PerformanceManager ha-perfmgr propertyCollector ManagedObjectReference:PropertyCollector ha-property-collector rootFolder ManagedObjectReference:Folder ha-folder-root scheduledTaskManager ManagedObjectReference:ScheduledTaskManager Unset searchIndex ManagedObjectReference:SearchIndex ha-searchindex sessionManager ManagedObjectReference:SessionManager ha-sessionmgr setting ManagedObjectReference:OptionManager HostAgentSettings taskManager ManagedObjectReference:TaskManager ha-taskmgr userDirectory ManagedObjectReference:UserDirectory ha-user-directory viewManager ManagedObjectReference:ViewManager ViewManager virtualDiskManager ManagedObjectReference:VirtualDiskManager ha-vdiskmanager virtualizationManager ManagedObjectReference:VirtualizationManager Unset