/**
  * converts an MDL object to CML. returns cml:cml/cml:molecule
  *
  * @param xml
  */
 public List<String> convertToText(Element xml) {
   List<String> stringList = null;
   CMLElement cml = CMLBuilder.ensureCML(xml);
   CMLMolecule molecule = new CMLSelector(cml).getToplevelMoleculeDescendant(true);
   if (molecule != null) {
     setMolecule(molecule);
     GaussianInputProcessor gaussianInputProcessor = new GaussianInputProcessor(this);
     stringList = gaussianInputProcessor.makeInput();
   }
   return stringList;
 }
  /**
   * This method is called when 'Finish' button is pressed in the wizard. We will create an
   * operation and run it using wizard as execution context.
   */
  public boolean performFinish() {
    try {
      Options opts = new Options(new String[0]);
      opts.setDefaultURL(serverPage.getSelectedServer() + "/services/NMRShiftDB");
      Service service = new Service();
      Call call = (Call) service.createCall();
      call.setOperationName("doSearch");
      call.setTargetEndpointAddress(new URL(opts.getURL()));
      DocumentBuilder builder;
      builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      SOAPBodyElement[] input = new SOAPBodyElement[1];
      Document doc = builder.newDocument();
      Element cdataElem;
      cdataElem = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "doSearch");
      Element reqElem;
      reqElem = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchstring");

      /*DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Node node = db.parse(new ByteArrayInputStream(new Convertor(true,"").cdkAtomContainerToCMLMolecule(ac).toXML().getBytes()));*/
      Node node =
          DOMConverter.convert(
                  new nu.xom.Document(new Convertor(true, "").cdkAtomContainerToCMLMolecule(ac)),
                  builder.getDOMImplementation())
              .getFirstChild();
      reqElem.appendChild(doc.importNode(node, true));
      Element reqElem2;
      reqElem2 = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchtype");
      Node node2;
      node2 = doc.createTextNode("--");
      reqElem2.appendChild(node2);
      Element reqElem3;
      reqElem3 = doc.createElementNS("http://www.nmrshiftdb.org/ws/NMRShiftDB/", "searchfield");
      Node node3;
      node3 = doc.createTextNode(NmrshiftdbUtils.replaceSpaces(serverPage.selectedOption()));
      reqElem3.appendChild(node3);
      cdataElem.appendChild(reqElem);
      cdataElem.appendChild(reqElem2);
      cdataElem.appendChild(reqElem3);
      input[0] = new SOAPBodyElement(cdataElem);
      Vector elems = (Vector) call.invoke(input);
      SOAPBodyElement elem = (SOAPBodyElement) elems.get(0);
      Element e = elem.getAsDOM();
      CMLBuilder cmlbuilder = new CMLBuilder();
      CMLElement cmlElement = (CMLElement) cmlbuilder.parseString(XMLUtils.ElementToString(e));
      if (cmlElement.getChildCount() > 0) {
        IFolder folder = NmrshiftdbUtils.createVirtualFolder();
        for (int i = 0; i < cmlElement.getChildCount(); i++) {
          net.bioclipse.specmol.Activator.getDefault()
              .getJavaSpecmolManager()
              .saveSpecmol(
                  new JumboSpecmol((CMLCml) cmlElement.getChildCMLElements().get(i)),
                  folder.getFile(
                      ((CMLMolecule)
                                  cmlElement
                                      .getChildCMLElements()
                                      .get(i)
                                      .getChildCMLElement("molecule", 0))
                              .getId()
                          + "."
                          + SpectrumEditor.CML_TYPE));
        }
      } else {
        MessageDialog.openInformation(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            "No results",
            "No spectra in NMRShiftDB for this structure!");
      }
    } catch (Exception ex) {
      LogUtils.handleException(ex, logger);
    }
    return true;
  }