diff options
author | Victor Mocanu | 2017-09-21 11:48:52 +0200 |
---|---|---|
committer | Victor Mocanu | 2017-09-21 11:48:52 +0200 |
commit | e897a4a68362dd9bf06baea639ca02145796a0ff (patch) | |
tree | 994937df1cfd801fd6859d3a59d7ec8e2788703f /src/main/java/org/openslx/util | |
parent | [VBox] working coppy of VboxConfig class, children are removed but empty line... (diff) | |
download | master-sync-shared-e897a4a68362dd9bf06baea639ca02145796a0ff.tar.gz master-sync-shared-e897a4a68362dd9bf06baea639ca02145796a0ff.tar.xz master-sync-shared-e897a4a68362dd9bf06baea639ca02145796a0ff.zip |
[VBox] removed empty lines, the FilteredDefinitionArray looks good now
Diffstat (limited to 'src/main/java/org/openslx/util')
-rw-r--r-- | src/main/java/org/openslx/util/vm/VboxConfig.java | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java index 6a983ce..8e90c4e 100644 --- a/src/main/java/org/openslx/util/vm/VboxConfig.java +++ b/src/main/java/org/openslx/util/vm/VboxConfig.java @@ -93,7 +93,7 @@ public class VboxConfig DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); //dbFactory.setValidating( true ); //dbFactory.setIgnoringElementContentWhitespace( true ); - + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); InputSource is = new InputSource( new StringReader( filtered ) ); @@ -131,7 +131,7 @@ public class VboxConfig { try { XPathFactory xpathFactory = XPathFactory.newInstance(); - + XPathExpression xpathExp = xpathFactory.newXPath().compile( "//text()[normalize-space(.) = '']" ); NodeList emptyTextNodes = (NodeList)xpathExp.evaluate( doc, XPathConstants.NODESET ); @@ -194,7 +194,7 @@ public class VboxConfig LOGGER.error( "There can not be more HDDs with the same UUID!" ); return; } - + Element deviceElement = (Element)devicesNodes.item( 0 ); String controllerDevice = deviceElement.getAttribute( "type" ); String bus = deviceElement.getAttribute( "name" ); @@ -272,34 +272,41 @@ public class VboxConfig for ( String blackedTag : blackList ) { String blackedExpression = ".//" + blackedTag; XPathExpression blackedExpr = xPath.compile( blackedExpression ); - + NodeList blackedNodes = (NodeList)blackedExpr.evaluate( this.doc, XPathConstants.NODESET ); + //LOGGER.debug( blackedNodes.getLength() ); for ( int i = 0; i < blackedNodes.getLength(); i++ ) { // get the child node Element child = (Element)blackedNodes.item( i ); // get the parent node - Element parent = (Element)child.getParentNode(); + Node parent = (Node)child.getParentNode(); // remove child - if ( child.getTagName().equals( "Adapter" ) && child.getAttribute( "enabled" ).equals( "true" )) { + if ( child.getTagName().equals( "Adapter" ) && child.getAttribute( "enabled" ).equals( "true" ) ) { continue; } + + // the structure of the xml Document is achieved through children nodes that are made up of just /n and spaces + // when a child node is deleted we get an empty line there the old child node used to be + Node prevChild = child.getPreviousSibling(); parent.removeChild( child ); - LOGGER.debug( parent.getChildNodes().getLength() ); - //Node blackedListedElement = (Node)blackedNodes.item( 0 ); - // in case of network adapter skip the enabled one - - //Node parent = blackedListedElement.getParentNode(); - //if (blackedListedElement. ) { - // parent.removeChild( blackedListedElement ); - //} - - - //NodeList children = parent.getChildNodes(); - //LOGGER.debug( "--Children--" ); - //for ( int j=0; j < children.getLength(); j++){ - //LOGGER.debug( parent.getChildNodes().item( j ).getNodeName() ); + + // HACK remove empty lines + // format children have type 3 + if ( prevChild.getNodeType() == 3 ) { + // the value of these Nodes are characters + String tmp = prevChild.getNodeValue(); + boolean shouldDelete = true; + for ( int foo = 0; foo < tmp.length(); foo++ ) { + if ( !Character.isWhitespace( tmp.charAt( foo ) ) ) { + shouldDelete = false; + break; + } + } + if ( shouldDelete ) + parent.removeChild( prevChild ); } } + } } //private void removeTag |