From e69b3a703d992e6a6623fd8578106cdb4224871d Mon Sep 17 00:00:00 2001 From: Stephan Schwär Date: Thu, 8 Oct 2020 10:20:44 +0900 Subject: Improve comments describing new classes and cleanup --- src/main/java/org/openslx/util/vm/OvfConfig.java | 85 +++++++++--------------- 1 file changed, 30 insertions(+), 55 deletions(-) (limited to 'src/main/java/org/openslx/util/vm/OvfConfig.java') diff --git a/src/main/java/org/openslx/util/vm/OvfConfig.java b/src/main/java/org/openslx/util/vm/OvfConfig.java index 3055075..df8b0ca 100644 --- a/src/main/java/org/openslx/util/vm/OvfConfig.java +++ b/src/main/java/org/openslx/util/vm/OvfConfig.java @@ -20,86 +20,61 @@ import org.openslx.util.vm.VmMetaData.HardDisk; import org.w3c.dom.Document; import org.xml.sax.SAXException; - /** * Class handling the parsing of a .ovf machine description file - * For now, only used to parse the xml to get the path of the vmdk - * from the ovf for sanity checking and cleanup after conversion. + * For now only a dummy for conversion and will be replaced in + * the image upload flow after converting the ovf to vmx. */ -public class OvfConfig -{ - private static final Logger LOGGER = Logger.getLogger( OvfConfig.class ); - - // key information set during initial parsing of the XML file +public class OvfConfig { + private static final Logger LOGGER = Logger.getLogger(OvfConfig.class); + + // key information set during initial parsing of the XML file private String osName = new String(); private ArrayList hddsArray = new ArrayList(); // XPath and DOM parsing related members - private Document doc = null; - + private Document doc = null; - public OvfConfig( File file ) throws IOException, UnsupportedVirtualizerFormatException - { + public OvfConfig(File file) throws IOException, UnsupportedVirtualizerFormatException { LOGGER.info("Entering OvfConfig class creation"); - // first validate xml - // try { - // SchemaFactory factory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI ); - // InputStream xsdStream = OvfConfig.class.getResourceAsStream( "/master-sync-shared/xml/ovf_1.1.1.xsd" ); - // LOGGER.info("xsdStream creation worked"); - // if ( xsdStream == null ) { - // LOGGER.warn( "Cannot validate ovf XML: No XSD found in JAR" ); - // } else { - // LOGGER.info("Before schema creation"); - // Schema schema = factory.newSchema( new StreamSource( xsdStream ) ); - // LOGGER.info("Created schema class"); - // Validator validator = schema.newValidator(); - // LOGGER.info("Created validator class"); - // validator.validate( new StreamSource( file ) ); - // LOGGER.info("Validated"); - // } - // } catch ( SAXException e ) { - // LOGGER.error( "Selected ovf file was not validated against the XSD schema: " + e.getMessage() ); - // } - LOGGER.info("XSD validation worked."); - // valid xml, try to create the DOM - doc = XmlHelper.parseDocumentFromStream( new FileInputStream( file ) ); - doc = XmlHelper.removeFormattingNodes( doc ); - if ( doc == null ) - throw new UnsupportedVirtualizerFormatException( "Could not create DOM from given ovf machine configuration file!" ); + doc = XmlHelper.parseDocumentFromStream(new FileInputStream(file)); + doc = XmlHelper.removeFormattingNodes(doc); + if (doc == null) + throw new UnsupportedVirtualizerFormatException( + "Could not create DOM from given ovf machine configuration file!"); LOGGER.info("DOM creation worked"); init(); - } - - /** - * Main initialization functions parsing the document created during the constructor. - * @throws UnsupportedVirtualizerFormatException + } + + /** + * Main initialization functions parsing the document created during the + * constructor. + * + * @throws UnsupportedVirtualizerFormatException */ - private void init() throws UnsupportedVirtualizerFormatException - { + private void init() throws UnsupportedVirtualizerFormatException { LOGGER.info("Entering OvfConfig init"); - if ( Util.isEmptyString( getDisplayName() ) ) { - throw new UnsupportedVirtualizerFormatException( "Machine doesn't have a name" ); + if (Util.isEmptyString(getDisplayName())) { + throw new UnsupportedVirtualizerFormatException("Machine doesn't have a name"); } - LOGGER.info( getDisplayName() ); + LOGGER.info(getDisplayName()); // try { - // setHdds(); // } catch ( XPathExpressionException e ) { // LOGGER.debug( "Could not initialize VBoxConfig", e ); // return; // } - } - - /** + } + + /** * Getter for the display name * * @return the display name of this VM */ - public String getDisplayName() - { + public String getDisplayName() { try { - return XmlHelper.XPath.compile( "/Envelope/VirtualSystem/Name" ).evaluate( this.doc ); - } catch ( XPathExpressionException e ) { + return XmlHelper.XPath.compile("/Envelope/VirtualSystem/Name").evaluate(this.doc); + } catch (XPathExpressionException e) { return ""; } } -- cgit v1.2.3-55-g7522