In the following code, because I am using the
for (Iterator<element> i = el.elements (). Iterator (); I.hasnext ();)
The iterator iterates through the flag of all the child nodes of the root node, but because the Linux baseline has a <initcmd> node that causes flag to be empty,
Throwing an exception while the database operation is in the incoming service causes the program to be suspended, the error message is not output to the console and printed directly to the page.
The workaround is that the try catch handles the exception and returns false.
Public BooleanIsfound (String xcwindex) {Try{Xconfiglinuxexample Example=Newxconfiglinuxexample (); Xconfiglinuxexample.criteria Criteria=Example.createcriteria (); Criteria.andxcwindexequalto (Xcwindex); LongCount =Xconfiglinuxmapper.countbyexample (example); returnCount > 0; }Catch(Exception e) {//System.out.println ("Xcwindex is empty, when not traversed to flag"); return false; } }
Public voidGetsystypebyuuid (String uuid)throwsIOException, documentexception {Switch(UUID) { Case"66c221be-6ab2-ef53-1589-fe16877914e2"://WindowsImportdataxml ("66c221be-6ab2-ef53-1589-fe16877914e2"); Break; Case"66c221be-6ab2-ef53-1589-fe16877914f4"://Linux Linux systems need to remove <initcmd> interferenceLinuxbaseline ("66c221be-6ab2-ef53-1589-fe16877914f4"); Break; } }
Public voidLinuxbaseline (String uuid)throwsdocumentexception, IOException {jsonobject jsonobject=NewJsonobject (); String result=NULL; Comptools Comptools=NewComptools (); String Path= "c:\\rm-root\\upload\\assetsconfresultxml\\" +Uploadedfilename;//creating the DOM4J parserSaxreader reader =NewSaxreader (); Document Document= Reader.read (NewFile (path)); Element Root=document.getrootelement (); List<Element> elements =root.elements (); String Flag; String Xcwvalue; Integer Nonecomplianceconfcount= 0; for(Element el:elements) { for(Iterator<element> i =el.elements (). iterator (); I.hasnext ();) {element element=(Element) i.next (); Flag= Element.attributevalue ("Flag"); if(Xconfiglinuxservice.isfound (flag)) {Xconfiglinux Allbyxcwindex=xconfiglinuxservice.getallbyxcwindex (flag); Xcwvalue= Element.element ("cmd"). Element ("value")). GetText (); Result=Comptools.linuxcomp (Allbyxcwindex.getcindex (). toString (), Flag, Xconfiglinuxservice, xcwvalue); Jsonobject.put (flag, result); if("1". Equals (Result)) {Nonecomplianceconfcount+=1; } } Else {//System.out.println ("Not Found:" +flag);}}} assetsservice.saveassetsdata (originalfilename,jsonobject,nonecompliance CONFCOUNT,UUID); }
Java program running in the event of an exception is not processed, will be thrown into the Java Virtual machine for processing, the program is suspended after the run, the page output error message (not output to the console)