List of usage examples for org.jdom2 Document setRootElement
public Document setRootElement(Element rootElement)
Element
for the Document
. From source file:de.sub.goobi.helper.tasks.ProcessSwapInTask.java
License:Open Source License
/** * Aufruf als Thread ================================================================ *//*from ww w . j a v a 2 s . co m*/ @SuppressWarnings("deprecation") @Override public void run() { setStatusProgress(5); String swapPath = null; // ProzessDAO dao = new ProzessDAO(); String processDirectory = ""; if (ConfigurationHelper.getInstance().isUseSwapping()) { swapPath = ConfigurationHelper.getInstance().getSwapPath(); } else { setStatusMessage("swapping not activated"); setStatusProgress(-1); return; } if (swapPath == null || swapPath.length() == 0) { setStatusMessage("no swappingPath defined"); setStatusProgress(-1); return; } Path swapFile = Paths.get(swapPath); if (!StorageProvider.getInstance().isFileExists(swapFile)) { setStatusMessage("Swap folder does not exist or is not mounted"); setStatusProgress(-1); return; } try { processDirectory = getProzess().getProcessDataDirectoryIgnoreSwapping(); // TODO: Don't catch Exception (the super class) } catch (Exception e) { logger.warn("Exception:", e); setStatusMessage( "Error while getting process data folder: " + e.getClass().getName() + " - " + e.getMessage()); setStatusProgress(-1); return; } Path fileIn = Paths.get(processDirectory); Path fileOut = Paths.get(swapPath + getProzess().getId() + FileSystems.getDefault().getSeparator()); if (!StorageProvider.getInstance().isFileExists(fileOut)) { setStatusMessage(getProzess().getTitel() + ": swappingOutTarget does not exist"); setStatusProgress(-1); return; } if (!StorageProvider.getInstance().isFileExists(fileIn)) { setStatusMessage(getProzess().getTitel() + ": process data folder does not exist"); setStatusProgress(-1); return; } SAXBuilder builder = new SAXBuilder(); Document docOld; try { Path swapLogFile = Paths.get(processDirectory, "swapped.xml"); docOld = builder.build(swapLogFile.toFile()); // TODO: Don't catch Exception (the super class) } catch (Exception e) { logger.warn("Exception:", e); setStatusMessage("Error while reading swapped.xml in process data folder: " + e.getClass().getName() + " - " + e.getMessage()); setStatusProgress(-1); return; } /* * --------------------- alte Checksummen in HashMap schreiben ------------------- */ setStatusMessage("reading checksums"); Element rootOld = docOld.getRootElement(); HashMap<String, String> crcMap = new HashMap<String, String>(); // TODO: Don't use Iterators for (Iterator<Element> it = rootOld.getChildren("file").iterator(); it.hasNext();) { Element el = it.next(); crcMap.put(el.getAttribute("path").getValue(), el.getAttribute("crc32").getValue()); } StorageProvider.getInstance().deleteDataInDir(fileIn); /* * --------------------- Dateien kopieren und Checksummen ermitteln ------------------- */ Document doc = new Document(); Element root = new Element("goobiArchive"); doc.setRootElement(root); /* * --------------------- Verzeichnisse und Dateien kopieren und anschliessend den Ordner leeren ------------------- */ setStatusProgress(50); try { setStatusMessage("copying process files"); Helper.copyDirectoryWithCrc32Check(fileOut, fileIn, swapPath.length(), root); } catch (IOException e) { logger.warn("IOException:", e); setStatusMessage("IOException in copyDirectory: " + e.getMessage()); setStatusProgress(-1); return; } setStatusProgress(80); /* * --------------------- Checksummen vergleichen ------------------- */ setStatusMessage("checking checksums"); // TODO: Don't use Iterators for (Iterator<Element> it = root.getChildren("file").iterator(); it.hasNext();) { Element el = it.next(); String newPath = el.getAttribute("path").getValue(); String newCrc = el.getAttribute("crc32").getValue(); if (crcMap.containsKey(newPath)) { if (!crcMap.get(newPath).equals(newCrc)) { setLongMessage(getLongMessage() + "File " + newPath + " has different checksum<br/>"); } crcMap.remove(newPath); } } setStatusProgress(85); /* * --------------------- prfen, ob noch Dateien fehlen ------------------- */ setStatusMessage("checking missing files"); if (crcMap.size() > 0) { for (String myFile : crcMap.keySet()) { setLongMessage(getLongMessage() + "File " + myFile + " is missing<br/>"); } } setStatusProgress(90); /* in Prozess speichern */ StorageProvider.getInstance().deleteDir(fileOut); try { setStatusMessage("saving process"); Process myProzess = ProcessManager.getProcessById(getProzess().getId()); myProzess.setSwappedOutGui(false); ProcessManager.saveProcess(myProzess); } catch (DAOException e) { setStatusMessage("DAOException while saving process: " + e.getMessage()); logger.warn("DAOException:", e); setStatusProgress(-1); return; } setStatusMessage("done"); setStatusProgress(100); }
From source file:de.sub.goobi.helper.tasks.ProcessSwapOutTask.java
License:Open Source License
/** * Aufruf als Thread ================================================================ *//*from w ww. j a va 2s . c om*/ @SuppressWarnings("deprecation") @Override public void run() { setStatusProgress(5); Helper help = new Helper(); String swapPath = null; // ProzessDAO dao = new ProzessDAO(); String processDirectory = ""; if (ConfigurationHelper.getInstance().isUseSwapping()) { swapPath = ConfigurationHelper.getInstance().getSwapPath(); } else { setStatusMessage("swapping not activated"); setStatusProgress(-1); return; } if (swapPath == null || swapPath.length() == 0) { setStatusMessage("no swappingPath defined"); setStatusProgress(-1); return; } Path swapFile = Paths.get(swapPath); if (!StorageProvider.getInstance().isFileExists(swapFile)) { setStatusMessage("Swap folder does not exist or is not mounted"); setStatusProgress(-1); return; } try { processDirectory = getProzess().getProcessDataDirectoryIgnoreSwapping(); //TODO: Don't catch Exception (the super class) } catch (Exception e) { logger.warn("Exception:", e); setStatusMessage( "Error while getting process data folder: " + e.getClass().getName() + " - " + e.getMessage()); setStatusProgress(-1); return; } Path fileIn = Paths.get(processDirectory); Path fileOut = Paths.get(swapPath + getProzess().getId() + FileSystems.getDefault().getSeparator()); if (StorageProvider.getInstance().isFileExists(fileOut)) { setStatusMessage(getProzess().getTitel() + ": swappingOutTarget already exists"); setStatusProgress(-1); return; } try { StorageProvider.getInstance().createDirectories(fileOut); } catch (IOException e1) { logger.error(e1); } /* --------------------- * Xml-Datei vorbereiten * -------------------*/ Document doc = new Document(); Element root = new Element("goobiArchive"); doc.setRootElement(root); Element source = new Element("source").setText(fileIn.toString()); Element target = new Element("target").setText(fileOut.toString()); Element title = new Element("title").setText(getProzess().getTitel()); Element mydate = new Element("date").setText(new Date().toString()); root.addContent(source); root.addContent(target); root.addContent(title); root.addContent(mydate); /* --------------------- * Verzeichnisse und Dateien kopieren und anschliessend den Ordner leeren * -------------------*/ setStatusProgress(50); try { setStatusMessage("copying process folder"); Helper.copyDirectoryWithCrc32Check(fileIn, fileOut, help.getGoobiDataDirectory().length(), root); } catch (IOException e) { logger.warn("IOException:", e); setStatusMessage("IOException in copyDirectory: " + e.getMessage()); setStatusProgress(-1); return; } setStatusProgress(80); StorageProvider.getInstance().deleteDataInDir(fileIn); /* --------------------- * xml-Datei schreiben * -------------------*/ Format format = Format.getPrettyFormat(); format.setEncoding("UTF-8"); try { setStatusMessage("writing swapped.xml"); XMLOutputter xmlOut = new XMLOutputter(format); FileOutputStream fos = new FileOutputStream( processDirectory + FileSystems.getDefault().getSeparator() + "swapped.xml"); xmlOut.output(doc, fos); fos.close(); //TODO: Don't catch Exception (the super class) } catch (Exception e) { logger.warn("Exception:", e); setStatusMessage(e.getClass().getName() + " in xmlOut.output: " + e.getMessage()); setStatusProgress(-1); return; } setStatusProgress(90); /* in Prozess speichern */ try { setStatusMessage("saving process"); Process myProzess = ProcessManager.getProcessById(getProzess().getId()); myProzess.setSwappedOutGui(true); ProcessManager.saveProcess(myProzess); } catch (DAOException e) { setStatusMessage("DAOException while saving process: " + e.getMessage()); logger.warn("DAOException:", e); setStatusProgress(-1); return; } setStatusMessage("done"); setStatusProgress(100); }
From source file:de.tu_dortmund.ub.api.daia.DaiaEndpoint.java
License:Open Source License
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String ips = request.getHeader("X-Forwarded-For"); boolean isTUintern = false; boolean isUBintern = false; boolean is52bIBA = false; try {//from ww w . j a v a 2s. co m if (ips != null) { String[] ranges = config.getProperty("service.iprange.tu").split("\\|"); for (String range : ranges) { if (ips.matches(range)) { isTUintern = true; break; } } String[] exceptions = config.getProperty("service.iprange.tu.exceptions").split("\\|"); if (isTUintern) { for (String exception : exceptions) { if (ips.matches(exception)) { isTUintern = false; break; } } } ranges = config.getProperty("service.iprange.ub").split("\\|"); for (String range : ranges) { if (ips.matches(range)) { isUBintern = true; break; } } exceptions = config.getProperty("service.iprange.ub.exceptions").split("\\|"); if (isUBintern) { for (String exception : exceptions) { if (ips.matches(exception)) { isUBintern = false; break; } } } ranges = config.getProperty("service.iprange.ub.52bIBAs").split("\\|"); exceptions = config.getProperty("service.iprange.ub.52bIBAs.exceptions").split("\\|"); String tmp[] = ips.split(", "); for (int i = 1; i < 3; i++) { try { String ip = tmp[tmp.length - i]; for (String range : ranges) { if (ip.matches(range)) { is52bIBA = true; break; } } if (exceptions.length > 0) { if (is52bIBA) { for (String exception : exceptions) { if (ip.matches(exception)) { is52bIBA = false; break; } } } } } catch (Exception e) { } } } } catch (Exception e) { this.logger.error(e.getMessage(), e.getCause()); } this.logger.info("[" + this.config.getProperty("service.name") + "] " + "Where is it from? " + request.getHeader("X-Forwarded-For") + ", " + isTUintern + ", " + isUBintern + ", " + is52bIBA); response.setHeader("Access-Control-Allow-Origin", config.getProperty("Access-Control-Allow-Origin")); try { String format = "html"; if (request.getParameter("format") != null && !request.getParameter("format").equals("")) { format = request.getParameter("format"); } else { Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerNameKey = headerNames.nextElement(); if (headerNameKey.equals("Accept")) { this.logger.debug("headerNameKey = " + request.getHeader(headerNameKey)); if (request.getHeader(headerNameKey).contains("text/html")) { format = "html"; } else if (request.getHeader(headerNameKey).contains("application/xml")) { format = "xml"; } else if (request.getHeader(headerNameKey).contains("application/json")) { format = "json"; } } } } if (format.equals("")) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid {FORMAT} requested."); } else if (request.getParameter("id") == null || request.getParameter("id").equals("")) { this.logger.debug("Query: " + request.getQueryString()); if (format.equals("html")) { response.sendRedirect(this.config.getProperty("service.doc")); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Usage: http://api.ub-tu-dortmund.de.de/daia/?id={ID}&format={FORMAT}."); } } else { if (request.getParameter("id").contains(":")) { String[] tmp = request.getParameter("id").split(":"); this.logger.debug("id = " + request.getParameter("id") + "' - " + new Date()); String idtype = tmp[0]; String localpart = ""; if (tmp.length > 1) { for (int i = 1; i < tmp.length; i++) { localpart += tmp[i]; if (i < tmp.length - 1) { localpart += ":"; } } } if (!(idtype.equals("ilsid") || idtype.equals("isbn") || idtype.equals("issn") || idtype.equals("verbundid") || idtype.equals("eki") || idtype.equals("zdbid"))) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid {IDTYPE} requested."); } else { try { // Wenn via META-INF/services eine Implementierung zum interface "IntegratedLibrarySystem" erfolgt ist, dann frage das System ab. if (Lookup.lookupAll(IntegratedLibrarySystem.class).size() > 0) { IntegratedLibrarySystem integratedLibrarySystem = Lookup .lookup(IntegratedLibrarySystem.class); // init ILS integratedLibrarySystem.init(this.config); ArrayList<de.tu_dortmund.ub.api.daia.ils.model.Document> documents = null; documents = integratedLibrarySystem.items(idtype, localpart); if (documents != null && documents.size() > 0) { ArrayList<de.tu_dortmund.ub.api.daia.model.Document> daiaDocuments = new ArrayList<de.tu_dortmund.ub.api.daia.model.Document>(); ArrayList<Integer> indexToRemove = new ArrayList<Integer>(); for (de.tu_dortmund.ub.api.daia.ils.model.Document document : documents) { if (document == null) { // Wie kann das sein? this.logger.error( "document = null for '" + idtype + ":" + localpart + "'"); } else { if (document.getItem() == null || (document.getItem() != null && document.getItem().size() == 0) || (document.getErschform() != null && document.getErschform().equals("p") && document.getVeroefart() != null && !document.getVeroefart().equals("da")) || (document.getErschform() != null && document.getErschform().equals("z"))) { // TODO 2015-03-06: HttpClient-Aufruf an den OpenURL-DaiaService if (Lookup.lookupAll(JournalOnlinePrintService.class).size() > 0) { String issn = null; if (document.getIssnprint() != null) { issn = document.getIssnprint().replaceAll("ISSN ", ""); } else if (document.getIssn() != null) { issn = document.getIssn(); } else if (document.getIssnwww() != null) { issn = document.getIssnwww().replaceAll("ISSN ", ""); } this.logger.debug("JOP mit ISSN = " + issn); this.logger.debug("JOP mit ZDB-ID = " + document.getZdbid()); if (issn != null) { JournalOnlinePrintService journalOnlinePrintService = Lookup .lookup(JournalOnlinePrintService.class); // init JOP journalOnlinePrintService.init(this.config); // get items ArrayList<de.tu_dortmund.ub.api.daia.jop.model.Document> jopDocuments = journalOnlinePrintService .items("issn", issn); if (jopDocuments != null && jopDocuments.size() > 0) { de.tu_dortmund.ub.api.daia.model.Document daiaDocument = new de.tu_dortmund.ub.api.daia.model.Document(); if (idtype.equals("verbundid")) { //daiaDocument.setId(this.config.getProperty("daia.document.baseurl") + localpart); //daiaDocument.setHref(this.config.getProperty("daia.document.baseurl") + localpart); daiaDocument.setId(document.getId()); daiaDocument.setHref(document.getHref()); } else if (idtype.equals("issn")) { if (jopDocuments.get(0).getId() != null) { daiaDocument.setId(jopDocuments.get(0).getId()); } else { daiaDocument.setId("urn:issn:" + localpart); } if (jopDocuments.get(0).getHref() != null) { daiaDocument .setId(jopDocuments.get(0).getHref()); } } else { if (jopDocuments.get(0).getId() != null) { daiaDocument.setId(jopDocuments.get(0).getId()); } else { daiaDocument.setId(this.config.getProperty( "daia.document.baseurl") + localpart); } if (jopDocuments.get(0).getHref() != null) { daiaDocument .setId(jopDocuments.get(0).getHref()); } else { daiaDocument.setHref(this.config.getProperty( "daia.document.baseurl") + localpart); } } // print if (jopDocuments.get(0).getItem() != null && jopDocuments.get(0).getItem().size() > 0) { daiaDocument.setItem(jopDocuments.get(0).getItem()); } // digital if (jopDocuments.get(0).isExistsDigitalItems() && Lookup .lookupAll(LinkResolver.class).size() > 0) { String openurl = ""; if (document.getMediatype() != null && document.getMediatype().equals("g")) { this.logger.debug( "document.getMediatype().equals(\"g\")"); openurl += "&rft.genre=journal&rft.eissn=" + issn; if (document.getIssnprint() != null) { if (document.getIssnprint() .startsWith("ISSN ")) { openurl += "&rft.issn=" + document .getIssnprint() .replaceAll("ISSN ", ""); } else { openurl += "&rft.issn=" + document.getIssnprint(); } } } else { if (document.getIssnprint() != null) { if (document.getIssnprint() .startsWith("ISSN ")) { openurl += "&rft.genre=journal&rft.issn=" + document.getIssnprint() .replaceAll("ISSN ", ""); } else { openurl += "&rft.genre=journal&rft.issn=" + document.getIssnprint(); } openurl += "&rft.eissn=" + document.getIssn(); } else if (document.getIssnwww() != null) { if (document.getIssnwww() .startsWith("ISSN ")) { openurl += "&rft.genre=journal&rft.eissn=" + document.getIssnwww() .replaceAll("ISSN ", ""); } else { openurl += "&rft.genre=journal&rft.eissn=" + document.getIssnwww(); } openurl += "&rft.issn=" + document.getIssn(); } else { openurl += "&rft.genre=journal&&rft.issn=" + document.getIssn(); } // TODO reicht das aus? //openurl += "&rft.genre=journal&&rft.issn=" + issn; } LinkResolver linkResolver = Lookup .lookup(LinkResolver.class); // init Linkresolver linkResolver.init(this.config); // get items ArrayList<de.tu_dortmund.ub.api.daia.model.Document> linkresolverDocument = linkResolver .items("openurl", openurl); if (linkresolverDocument != null && linkresolverDocument.size() > 0) { this.logger.debug(linkresolverDocument.get(0) .getItem().size() + ", " + jopDocuments.get(0) .getCountDigitlItems()); } if (linkresolverDocument != null && linkresolverDocument.size() > 0 && linkresolverDocument.get(0).getItem() .size() >= jopDocuments.get(0) .getCountDigitlItems()) { if (daiaDocument.getItem() == null || daiaDocument.getItem().size() == 0) { daiaDocument.setItem(linkresolverDocument .get(0).getItem()); } else { daiaDocument.getItem() .addAll(linkresolverDocument.get(0) .getItem()); } } else { this.logger.debug("Ja, der Fall ist das!"); openurl = ""; if (document.getIssnprint() != null) { if (document.getIssnprint() .startsWith("ISSN ")) { openurl += "&rft.genre=journal&&rft.issn=" + document.getIssnprint() .replaceAll("ISSN ", ""); } } else if (document.getIssnwww() != null) { if (document.getIssnwww() .startsWith("ISSN ")) { openurl += "&rft.genre=journal&&rft.issn=" + document.getIssnwww() .replaceAll("ISSN ", ""); } } if (!openurl.equals("")) { // get items linkresolverDocument = linkResolver .items("openurl", openurl); if (linkresolverDocument != null && linkresolverDocument .size() > 0) { this.logger.debug(linkresolverDocument .get(0).getItem().size() + ", " + jopDocuments.get(0) .getCountDigitlItems()); } if (linkresolverDocument != null && linkresolverDocument.size() > 0 && linkresolverDocument.get(0) .getItem() .size() >= jopDocuments .get(0) .getCountDigitlItems()) { if (daiaDocument.getItem() == null || daiaDocument.getItem() .size() == 0) { daiaDocument.setItem( linkresolverDocument.get(0) .getItem()); } else { daiaDocument.getItem() .addAll(linkresolverDocument .get(0).getItem()); } } else { // TODO Ticket 11679 // E-Mail an katalogplus@ub.tu-dortmund.de mit Betreff-Prefix [Content] boolean isNatLic = true; if (isNatLic) { if (!issn.equals("")) { // request JOP again with only ISSN jopDocuments = journalOnlinePrintService .eonly("issn", issn); if (jopDocuments != null && jopDocuments .size() > 0) { this.logger .debug("JOP hits: " + jopDocuments .size()); if (daiaDocument .getItem() == null || daiaDocument .getItem() .size() == 0) { daiaDocument.setItem( jopDocuments .get(0) .getItem()); } else { daiaDocument.getItem() .addAll(jopDocuments .get(0) .getItem()); } } } else { if (daiaDocument .getItem() == null || daiaDocument .getItem() .size() == 0) { daiaDocument = null; } } } else { if (daiaDocument.getItem() == null || daiaDocument.getItem() .size() == 0) { daiaDocument = null; } } } } else { //daiaDocument = null; /* TODO tue nix? */ if (daiaDocument.getItem() == null || daiaDocument.getItem() .size() == 0) { if (daiaDocument.getItem() == null) { daiaDocument.setItem( new ArrayList<Item>()); } daiaDocument .setItem(linkresolverDocument .get(0).getItem()); } else { daiaDocument.getItem() .addAll(linkresolverDocument .get(0).getItem()); } } } } if (daiaDocument != null) { daiaDocuments.add(daiaDocument); } } } else if (document.getZdbid() != null) { this.logger.info("Bin drin!"); JournalOnlinePrintService journalOnlinePrintService = Lookup .lookup(JournalOnlinePrintService.class); // init JOP journalOnlinePrintService.init(this.config); // get items ArrayList<de.tu_dortmund.ub.api.daia.jop.model.Document> jopDocuments = journalOnlinePrintService .items("zdbid", document.getZdbid()); if (jopDocuments != null) { this.logger.info( "jopDocuments.size()=" + jopDocuments.size()); } if (jopDocuments != null && jopDocuments.size() > 0) { de.tu_dortmund.ub.api.daia.model.Document daiaDocument = new de.tu_dortmund.ub.api.daia.model.Document(); if (jopDocuments.get(0).getId() != null) { daiaDocument.setId(jopDocuments.get(0).getId()); } else { daiaDocument.setId(this.config .getProperty("daia.document.baseurl") + document.getZdbid()); } if (jopDocuments.get(0).getHref() != null) { daiaDocument.setHref(jopDocuments.get(0).getHref()); } else { daiaDocument.setHref(this.config .getProperty("daia.document.baseurl") + document.getZdbid()); } // print if (jopDocuments.get(0).getItem() != null && jopDocuments.get(0).getItem().size() > 0) { daiaDocument.setItem(jopDocuments.get(0).getItem()); } // digital - nicht mglich, da ISSN fehlt this.logger.info( "jopDocuments.get(0).isExistsDigitalItems()=" + jopDocuments.get(0) .isExistsDigitalItems()); if (jopDocuments.get(0).isExistsDigitalItems()) { jopDocuments = journalOnlinePrintService .eonly("zdbid", document.getZdbid()); if (jopDocuments != null && jopDocuments.size() > 0) { if (daiaDocument.getItem() == null || daiaDocument.getItem().size() == 0) { daiaDocument.setItem( jopDocuments.get(0).getItem()); } else { daiaDocument.getItem().addAll( jopDocuments.get(0).getItem()); } } } daiaDocuments.add(daiaDocument); } } else { // evtl. Serienaufnahme indexToRemove.add(documents.indexOf(document)); } } } else { de.tu_dortmund.ub.api.daia.model.Document daiaDocument = new de.tu_dortmund.ub.api.daia.model.Document(); daiaDocument.setId(document.getId()); daiaDocument.setHref(document.getHref()); if (document.getErschform() != null && document.getErschform().equals("p") && document.getVeroefart() != null && document.getVeroefart().equals("da")) { // TODO inhaltlich falsch if (document.getLokaleurl() != null && !document.getLokaleurl().equals("")) { //this.logger.info(document.getItem().size() + " Items"); document.getItem().get(0) .setHref(document.getLokaleurl().get(0)); } else if (document.getUrl() != null && !document.getUrl().equals("")) { document.getItem().get(0).setHref(document.getUrl().get(0)); } } daiaDocument.setItem(document.getItem()); String editionStatement = ""; if (document.getAusgabe() != null && !document.getAusgabe().equals("")) { editionStatement += document.getAusgabe() + ". "; } if (document.getErschjahr() != null && !document.getErschjahr().equals("")) { editionStatement += document.getErschjahr(); } if (document.getUmfang() != null && !document.getUmfang().equals("")) { editionStatement += ". - " + document.getUmfang(); } daiaDocument.setEdition(editionStatement); daiaDocuments.add(daiaDocument); } } } if (indexToRemove.size() > 0) { for (Integer i : indexToRemove) { documents.remove(Integer.valueOf(i)); } } if (daiaDocuments.size() > 0) { Daia daia = new Daia(); daia.setVersion(this.config.getProperty("daia.version")); daia.setSchema(this.config.getProperty("daia.schema")); GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(new java.util.Date().getTime()); try { DatatypeFactory df = DatatypeFactory.newInstance(); daia.setTimestamp(df.newXMLGregorianCalendar(gc).toString()); } catch (DatatypeConfigurationException dce) { this.logger.error("ERROR: Service unavailable."); } Institution institution = new Institution(); institution.setId(this.config.getProperty("daia.institution.id")); institution.setHref(this.config.getProperty("daia.institution.href")); institution.setContent(this.config.getProperty("daia.institution.content")); daia.setInstitution(institution); daia.setDocument(daiaDocuments); // Ausgabe this.logger.debug("format = " + format); // HTML-Ausgabe via XSLT if (format.equals("html")) { try { JAXBContext context = JAXBContext.newInstance(Daia.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse StringWriter stringWriter = new StringWriter(); m.marshal(daia, stringWriter); Document doc = new SAXBuilder() .build(new StringReader(stringWriter.toString())); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", "de"); parameters.put("isTUintern", Boolean.toString(isTUintern)); parameters.put("isUBintern", Boolean.toString(isUBintern)); parameters.put("is52bIBA", Boolean.toString(is52bIBA)); this.logger.debug("idtype = " + idtype); parameters.put("id", idtype + ":" + localpart); ObjectMapper mapper = new ObjectMapper(); StringWriter json = new StringWriter(); mapper.writeValue(json, daia); parameters.put("json", json.toString()); String html = htmlOutputter(doc, this.config.getProperty("linkresolver.html.xslt"), parameters); response.setContentType("text/html;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println(html); } catch (PropertyException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (JDOMException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(Daia.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse response.setContentType("application/xml;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); m.marshal(daia, response.getWriter()); } catch (PropertyException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { ObjectMapper mapper = new ObjectMapper(); response.setContentType("application/json;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); mapper.writeValue(response.getWriter(), daia); } // RDF-Ausgabe mit XSLT auf XML-Ausgabe if (format.equals("rdf")) { try { JAXBContext context = JAXBContext.newInstance(Daia.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse response.setContentType("application/xml;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); StringWriter xml = new StringWriter(); m.marshal(daia, xml); XMLOutputter out = new XMLOutputter(); out.output( new SAXBuilder().build(new StringReader(xmlOutputter( new SAXBuilder() .build(new StringReader(xml.toString())), config.getProperty("xslt_xml2rdf"), null))), response.getWriter()); } catch (JDOMException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (PropertyException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } } else { // Document not found if (format.equals("html")) { try { JAXBContext context = JAXBContext.newInstance(Daia.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse Document doc = new Document(); doc.setRootElement(new Element("daia")); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", "de"); parameters.put("isTUintern", Boolean.toString(isTUintern)); parameters.put("isUBintern", Boolean.toString(isUBintern)); parameters.put("is52bIBA", Boolean.toString(is52bIBA)); parameters.put("id", idtype + ":" + localpart); String html = htmlOutputter(doc, this.config.getProperty("linkresolver.html.xslt"), parameters); response.setContentType("text/html;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println(html); } catch (PropertyException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message. Message is 'Document not found'."); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message. Message is 'Document not found'."); } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Document not found."); } } } else { // Document not found if (format.equals("html")) { try { JAXBContext context = JAXBContext.newInstance(Daia.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse Document doc = new Document(); doc.setRootElement(new Element("daia")); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", "de"); parameters.put("isTUintern", Boolean.toString(isTUintern)); parameters.put("isUBintern", Boolean.toString(isUBintern)); parameters.put("is52bIBA", Boolean.toString(is52bIBA)); parameters.put("id", idtype + ":" + localpart); String html = htmlOutputter(doc, this.config.getProperty("linkresolver.html.xslt"), parameters); response.setContentType("text/html;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println(html); } catch (PropertyException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message. Message is 'Document not found'."); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message. Message is 'Document not found'."); } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Document not found."); } } } else { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Service unavailable (ILS): No ILS configured!"); } } catch (ILSException e) { e.printStackTrace(); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Service unavailable (ILS)."); } catch (LinkResolverException e) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Service unavailable (LinkResolver)."); } catch (JOPException e) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Service unavailable (JOP)."); } } } } } catch (Exception e) { e.printStackTrace(); this.logger.error(new Date() + "[DAIA] Exception: " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + " Service unavailable."); this.logger.error(e.getMessage(), e.getCause()); for (StackTraceElement stackTraceElement : e.getStackTrace()) { this.logger.error("\t" + stackTraceElement.toString()); } Mailer mailer = new Mailer(this.config.getProperty("service.mailer.conf")); try { String referer = "'none'"; if (request.getHeader("referer") != null) { referer = request.getHeader("referer"); } mailer.postMail( "[DAIA] Exception: " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + " Service unavailable.", e.getMessage() + "\n" + request.getRequestURL() + "\n" + ips + "\n" + referer + "\n" + "\n" + e.getCause().toString()); } catch (MessagingException e1) { this.logger.error(e1.getMessage(), e1.getCause()); } response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Service unavailable."); } }
From source file:de.unirostock.sems.cbarchive.web.dataholder.MetaObjectDataholder.java
License:Open Source License
/** * Generates a temporarily id for the meta entry *//*from w w w. j a v a 2s .c o m*/ @JsonIgnore public void generateId() { Element xmlElement = metaObject.getXmlDescription(); String xmlString = null; try { Document doc = new Document(); doc.setRootElement(xmlElement.clone()); xmlString = Utils.prettyPrintDocument(doc); } catch (IOException | TransformerException e) { LOGGER.error(e, "Can't generate xml from meta object to generate meta id"); return; } id = Tools.generateHashId(xmlString); // LOGGER.debug("generated ID: ", id); }
From source file:devicerestmodel.services.ResourceBase.java
private void addGetResourceXML(final String path, final DevicePropertyNode element) { final Resource.Builder resourceBuilder = Resource.builder(); resourceBuilder.path(path);//www . jav a 2s . c o m final ResourceMethod.Builder methodBuilder = resourceBuilder.addMethod("GET"); methodBuilder.produces(MediaType.APPLICATION_XML) .handledBy(new Inflector<ContainerRequestContext, Response>() { @Override public Response apply(ContainerRequestContext containerRequestContext) { try { if (containerRequestContext.getMethod().equals("GET")) { System.out.println("Got a GET for " + path); LoggerOut.println("Get a GET for " + path); Document myDocument = new Document(); myDocument.setRootElement(element.getXml(containerRequestContext)); return Response.ok().type(MediaType.APPLICATION_XML) .entity(MdUtil.document2XmlString(myDocument)).build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } } catch (Exception ex) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } }); final Resource resource = resourceBuilder.build(); registerResources(resource); }
From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.configuration.ConfigProgramPathsChipSeq.java
License:Open Source License
public void exportToXML(File output) throws IOException { Document configurationFile = new Document(); Comment comment = new Comment(COMMENT_CHIPSEQ); configurationFile.addContent(comment); Element configData = new Element(CONFIG_DATA); configurationFile.setRootElement(configData); Element bwaPath = new Element(BWA_PATH); bwaPath.addContent(this.getBwaPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(bwaPath); Element samtoolsPath = new Element(SAMTOOLS_PATH); samtoolsPath.addContent(this.getSamtoolsPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(samtoolsPath); Element picardPath = new Element(PICARD_PATH); picardPath.addContent(this.getPicardPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(picardPath); Element MACSPath = new Element(MACS_PATH); MACSPath.addContent(this.getMacsPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(MACSPath); Element PythonPath = new Element(PYTHON_PATH); PythonPath.addContent(this.getPythonPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(PythonPath); Element BEDToolsPath = new Element(BED_TOOLS_PATH); BEDToolsPath.addContent(this.getBedtoolsPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(BEDToolsPath); Element CCATPath = new Element(CCAT_PATH); CCATPath.addContent(this.getCcatPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(CCATPath); Element BedgraphtoWigPath = new Element(BGTW_PATH); BedgraphtoWigPath.addContent(this.getBedgraphtobigwigPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(BedgraphtoWigPath); Element IDRPath = new Element(IDR_PATH); IDRPath.addContent(this.getIdrPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(IDRPath); Element PeakAnnotatorPath = new Element(PEAKANNOTATOR_PATH); PeakAnnotatorPath.addContent(this.getPeakannotatorPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(PeakAnnotatorPath); Element fastqcPath = new Element(FASTQC_PATH); fastqcPath.addContent(this.getFastqcPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(fastqcPath); if (!this.getNthr().equals(nthr_DV)) { Element nthr = new Element(NTHR); nthr.addContent(String.valueOf(this.getNthr())); configurationFile.getRootElement().addContent(nthr); }//from ww w.ja va 2s. c o m if (!this.getJavaRam().equals(javaRam_DV)) { Element javaRam = new Element(JAVA_RAM); javaRam.addContent(this.getJavaRam()); configurationFile.getRootElement().addContent(javaRam); } Element queueSystem = new Element(QUEUE_SYSTEM); queueSystem.addContent(this.getQueueSystem().getDisplayName()); configurationFile.getRootElement().addContent(queueSystem); if (!this.getQueueName().equals(queueName_DV)) { Element queueName = new Element(QUEUE_NAME); queueName.addContent(this.getQueueName()); configurationFile.getRootElement().addContent(queueName); } if (!this.getMulticoreName().equals(multicoreName_DV)) { Element multicoreName = new Element(MULTICORE_NAME); multicoreName.addContent(this.getMulticoreName()); configurationFile.getRootElement().addContent(multicoreName); } if (!this.getMulticoreNumber().equals(multicoreNumber_DV)) { Element multicoreNumber = new Element(MULTICORE_NUMBER); multicoreNumber.addContent(String.valueOf(this.getMulticoreNumber())); configurationFile.getRootElement().addContent(multicoreNumber); } XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(configurationFile, new FileWriter(output)); // xmlOutput.output(configurationFile, new FileWriter(new File(output.getAbsolutePath()+".test"))); }
From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.configuration.ConfigProgramPathsCNV.java
License:Open Source License
public void exportToXML(File output) throws IOException { Document configurationFile = new Document(); Comment comment = new Comment(COMMENT_VARIANT_CALLER); configurationFile.addContent(comment); Element configData = new Element(CONFIG_DATA); configurationFile.setRootElement(configData); Element bwaPath = new Element(BWA_PATH); bwaPath.addContent(this.getBwaPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(bwaPath); Element samtoolsPath = new Element(SAMTOOLS_PATH); samtoolsPath.addContent(this.getSamtoolsPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(samtoolsPath); Element gatkpath = new Element(GATK_PATH); gatkpath.addContent(this.getGatkpath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(gatkpath); Element picardPath = new Element(PICARD_PATH); picardPath.addContent(this.getPicardPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(picardPath); Element BFASTPath = new Element(BFAST_PATH); BFASTPath.addContent(this.getBfastPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(BFASTPath); Element BEDToolsPath = new Element(BED_TOOLS_PATH); BEDToolsPath.addContent(this.getBedtoolsPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(BEDToolsPath); Element CONTRAPath = new Element(CONTRA_PATH); CONTRAPath.addContent(this.getContraPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(CONTRAPath); Element fastqcPath = new Element(FASTQC_PATH); fastqcPath.addContent(this.getFastqcPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(fastqcPath); if (!this.getNthr().equals(nthr_DV)) { Element nthr = new Element(NTHR); nthr.addContent(String.valueOf(this.getNthr())); configurationFile.getRootElement().addContent(nthr); }/* w w w . j a va 2 s.c om*/ if (!this.getJavaRam().equals(javaRam_DV)) { Element javaRam = new Element(JAVA_RAM); javaRam.addContent(this.getJavaRam()); configurationFile.getRootElement().addContent(javaRam); } Element queueSystem = new Element(QUEUE_SYSTEM); queueSystem.addContent(this.getQueueSystem().getDisplayName()); configurationFile.getRootElement().addContent(queueSystem); if (!this.getQueueName().equals(queueName_DV)) { Element queueName = new Element(QUEUE_NAME); queueName.addContent(this.getQueueName()); configurationFile.getRootElement().addContent(queueName); } if (!this.getMulticoreName().equals(multicoreName_DV)) { Element multicoreName = new Element(MULTICORE_NAME); multicoreName.addContent(this.getMulticoreName()); configurationFile.getRootElement().addContent(multicoreName); } if (!this.getMulticoreNumber().equals(multicoreNumber_DV)) { Element multicoreNumber = new Element(MULTICORE_NUMBER); multicoreNumber.addContent(String.valueOf(this.getMulticoreNumber())); configurationFile.getRootElement().addContent(multicoreNumber); } XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(configurationFile, new FileWriter(output)); }
From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.configuration.ConfigProgramPathsMethylation.java
License:Open Source License
public void exportToXML(File output) throws IOException { Document configurationFile = new Document(); Comment comment = new Comment(COMMENT_METHYLATION); configurationFile.addContent(comment); Element configData = new Element(CONFIG_DATA); configurationFile.setRootElement(configData); Element bismarkPath = new Element(BISMARK_PATH); bismarkPath.addContent(this.getBismarkPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(bismarkPath); Element bowtiePath = new Element(BOWTIE_PATH); bowtiePath.addContent(this.getBowtiePath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(bowtiePath); Element picardPath = new Element(PICARD_PATH); picardPath.addContent(this.getPicardPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(picardPath); Element BEDToolsPath = new Element(BED_TOOLS_PATH); BEDToolsPath.addContent(this.getBedtoolsPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(BEDToolsPath); Element fastxPath = new Element(FASTX_PATH); fastxPath.addContent(this.getFastxPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(fastxPath); Element filoPath = new Element(FILO_PATH); filoPath.addContent(this.getFiloPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(filoPath); Element fastqcPath = new Element(FASTQC_PATH); fastqcPath.addContent(this.getFastqcPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(fastqcPath); if (!this.getNthr().equals(nthr_DV)) { Element nthr = new Element(NTHR); nthr.addContent(String.valueOf(this.getNthr())); configurationFile.getRootElement().addContent(nthr); }/*from w ww. j a v a2 s . c o m*/ if (!this.getJavaRam().equals(javaRam_DV)) { Element javaRam = new Element(JAVA_RAM); javaRam.addContent(this.getJavaRam()); configurationFile.getRootElement().addContent(javaRam); } Element queueSystem = new Element(QUEUE_SYSTEM); queueSystem.addContent(this.getQueueSystem().getDisplayName()); configurationFile.getRootElement().addContent(queueSystem); if (!this.getQueueName().equals(queueName_DV)) { Element queueName = new Element(QUEUE_NAME); queueName.addContent(this.getQueueName()); configurationFile.getRootElement().addContent(queueName); } if (!this.getMulticoreName().equals(multicoreName_DV)) { Element multicoreName = new Element(MULTICORE_NAME); multicoreName.addContent(this.getMulticoreName()); configurationFile.getRootElement().addContent(multicoreName); } if (!this.getMulticoreNumber().equals(multicoreNumber_DV)) { Element multicoreNumber = new Element(MULTICORE_NUMBER); multicoreNumber.addContent(String.valueOf(this.getMulticoreNumber())); configurationFile.getRootElement().addContent(multicoreNumber); } XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(configurationFile, new FileWriter(output)); }
From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.configuration.ConfigProgramPathsSNV.java
License:Open Source License
public void exportToXML(File output) throws IOException { Document configurationFile = new Document(); Comment comment = new Comment(COMMENT_VARIANT_CALLER); configurationFile.addContent(comment); Element configData = new Element(CONFIG_DATA); configurationFile.setRootElement(configData); Element bwaPath = new Element(BWA_PATH); bwaPath.addContent(this.getBwaPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(bwaPath); Element samtoolsPath = new Element(SAMTOOLS_PATH); samtoolsPath.addContent(this.getSamtoolsPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(samtoolsPath); Element gatkpath = new Element(GATK_PATH); gatkpath.addContent(this.getGatkpath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(gatkpath); Element picardPath = new Element(PICARD_PATH); picardPath.addContent(this.getPicardPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(picardPath); Element BFASTPath = new Element(BFAST_PATH); BFASTPath.addContent(this.getBfastPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(BFASTPath); Element fastqcPath = new Element(FASTQC_PATH); fastqcPath.addContent(this.getFastqcPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(fastqcPath); if (!this.getNthr().equals(nthr_DV)) { Element nthr = new Element(NTHR); nthr.addContent(String.valueOf(this.getNthr())); configurationFile.getRootElement().addContent(nthr); }/*from w w w. j a v a 2 s. c o m*/ if (!this.getJavaRam().equals(javaRam_DV)) { Element javaRam = new Element(JAVA_RAM); javaRam.addContent(this.getJavaRam()); configurationFile.getRootElement().addContent(javaRam); } Element queueSystem = new Element(QUEUE_SYSTEM); queueSystem.addContent(this.getQueueSystem().getDisplayName()); configurationFile.getRootElement().addContent(queueSystem); if (!this.getQueueName().equals(queueName_DV)) { Element queueName = new Element(QUEUE_NAME); queueName.addContent(this.getQueueName()); configurationFile.getRootElement().addContent(queueName); } if (!this.getMulticoreName().equals(multicoreName_DV)) { Element multicoreName = new Element(MULTICORE_NAME); multicoreName.addContent(this.getMulticoreName()); configurationFile.getRootElement().addContent(multicoreName); } if (!this.getMulticoreNumber().equals(multicoreNumber_DV)) { Element multicoreNumber = new Element(MULTICORE_NUMBER); multicoreNumber.addContent(String.valueOf(this.getMulticoreNumber())); configurationFile.getRootElement().addContent(multicoreNumber); } XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(configurationFile, new FileWriter(output)); }
From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.experiments.ChipSeqExperiment.java
License:Open Source License
public void generateXMLConfigurationFile(File output) throws IOException { Document configurationFile = new Document(); Element configData = new Element(CONFIG_DATA); configurationFile.setRootElement(configData); configData.setAttribute(ExperimentUtils.BRANCH, ExperimentUtils.BRANCH_CHIPSEQ); Element genRef = new Element(GENREF); genRef.addContent(this.getGenRefPath().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(genRef); Element plattform = new Element(PLATTFORM); plattform.addContent(this.getPlattform().getDisplayName()); configurationFile.getRootElement().addContent(plattform); if (!this.checkCasava.equals(checkCasava_DV)) { Element checkCasava = new Element(CHECKCASAVA); checkCasava.addContent(this.getCheckCasava().toString()); configurationFile.getRootElement().addContent(checkCasava); }/*from w w w . j ava 2 s.c o m*/ Element dirOutBase = new Element(DIROUTBASE); dirOutBase.addContent(this.getDirOutBase().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(dirOutBase); Element projectId = new Element(PROJECTID); projectId.addContent(this.getProjectId()); configurationFile.getRootElement().addContent(projectId); if (!this.getUserName().equals(userName_DV)) { Element userName = new Element(USERNAME); userName.addContent(this.getUserName()); configurationFile.getRootElement().addContent(userName); } Element inDirPreProcess = new Element(INDIRPREPROCESS); inDirPreProcess.addContent(this.getDataInDirpreProcess().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(inDirPreProcess); for (CSExperiment experiment : this.getExperiments()) { Element chipSeqExperiment = new Element(EXPERIMENT); for (ChipSeqUnit csUnit : experiment.getChipSeqUnits()) { Element csUnitElement = new Element(CHIPSEQUNIT); Sample sampleTreatment = csUnit.getSampleTreatment(); Element sampleTreatmentElement = new Element(SAMPLE_TREATMENT); Element sampleName = new Element(SAMPLE_NAME); sampleName.addContent(sampleTreatment.getSampleName()); sampleTreatmentElement.addContent(sampleName); Element sampleFiles = new Element(SAMPLE_FILES); sampleFiles.addContent(sampleTreatment.getSampleFiles()); sampleTreatmentElement.addContent(sampleFiles); Element sampleSuffix = new Element(SAMPLE_SUFFIX); sampleSuffix.addContent(sampleTreatment.getSampleSuffix()); sampleTreatmentElement.addContent(sampleSuffix); Element sampleType = new Element(SAMPLE_TYPE); sampleType.addContent(sampleTreatment.getSampleType().getDisplayName()); sampleTreatmentElement.addContent(sampleType); csUnitElement.addContent(sampleTreatmentElement); Sample sampleInput = csUnit.getSampleInput(); if (sampleInput.checkSample()) { Element sampleInputElement = new Element(SAMPLE_INPUT); Element sampleInputName = new Element(SAMPLE_NAME); sampleInputName.addContent(sampleInput.getSampleName()); sampleInputElement.addContent(sampleInputName); Element sampleInputFiles = new Element(SAMPLE_FILES); sampleInputFiles.addContent(sampleInput.getSampleFiles()); sampleInputElement.addContent(sampleInputFiles); Element sampleInputSuffix = new Element(SAMPLE_SUFFIX); sampleInputSuffix.addContent(sampleInput.getSampleSuffix()); sampleInputElement.addContent(sampleInputSuffix); Element sampleInputType = new Element(SAMPLE_TYPE); sampleInputType.addContent(sampleInput.getSampleType().getDisplayName()); sampleInputElement.addContent(sampleInputType); csUnitElement.addContent(sampleInputElement); } chipSeqExperiment.addContent(csUnitElement); } Element replicatesFlag = new Element(REPLICATES_FLAG); replicatesFlag.addContent(experiment.isReplicatesFlag() ? "1" : "0"); chipSeqExperiment.addContent(replicatesFlag); configurationFile.getRootElement().addContent(chipSeqExperiment); } Element chromSize = new Element(CHROMSIZE); chromSize.addContent(this.getChromSize().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(chromSize); if (!this.getPeakAnalysisType().equals(peakAnalysisType_DV)) { Element peakAnalysis = new Element(PEAKANALYSIS); peakAnalysis.addContent(this.getPeakAnalysisType().getDisplayName()); configurationFile.getRootElement().addContent(peakAnalysis); } if (this.getCcatConfigFile() != ccatConfigFile_DV) { Element ccaConfigFile = new Element(CCAT_CONFIG_FILE); ccaConfigFile.addContent(this.getCcatConfigFile().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(ccaConfigFile); } if (!this.getMacsExtraArgs().equals(macsExtraArgs_DV)) { Element macsExtraArgs = new Element(MACS_EXTRAARGS); macsExtraArgs.addContent(this.getMacsExtraArgs()); configurationFile.getRootElement().addContent(macsExtraArgs); } if (!this.getFastqc().equals(fastqc_DV)) { Element fastqc = new Element(FASTQC); fastqc.addContent(this.getFastqc().toString()); configurationFile.getRootElement().addContent(fastqc); } if (this.getAnnotFile() != annotFile_DV) { Element annotFile = new Element(ANNOTFILE); annotFile.addContent(this.getAnnotFile().getFile().getAbsolutePath()); configurationFile.getRootElement().addContent(annotFile); } if (!this.getQueueSGEProject().equals(queueSGEProject_DV)) { Element queueProject = new Element(QUEUESGEPROJECT); queueProject.addContent(this.getQueueSGEProject().toString()); configurationFile.getRootElement().addContent(queueProject); } XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(configurationFile, new FileWriter(output)); }