List of usage examples for org.dom4j Element elementText
String elementText(QName qname);
From source file:mesquite.minimal.Installer.Installer.java
License:Open Source License
void cleanUp(Element installElement) { String pathInMesquiteFolder = installElement.elementText("location"); if (!StringUtil.blank(pathInMesquiteFolder)) pathInMesquiteFolder = pathInMesquiteFolder + "/"; String fileName = installElement.elementText("file"); File tempPackage = new File(getRootPath() + pathInMesquiteFolder + fileName + "PREVIOUSVERSION"); boolean hadExisted = tempPackage.exists(); if (hadExisted) { logln("Deleting old version of " + fileName); if (tempPackage.isDirectory()) MesquiteFile.deleteDirectory(getRootPath() + pathInMesquiteFolder + fileName + "PREVIOUSVERSION"); else//w ww. j a v a 2 s .c om MesquiteFile.deleteFile(getRootPath() + pathInMesquiteFolder + fileName + "PREVIOUSVERSION"); } }
From source file:mesquite.minimal.Installer.Installer.java
License:Open Source License
void reverse(Element installElement) { String pathInMesquiteFolder = installElement.elementText("location"); if (!StringUtil.blank(pathInMesquiteFolder)) pathInMesquiteFolder = pathInMesquiteFolder + "/"; String fileName = installElement.elementText("file"); String prevPackagePath = getRootPath() + pathInMesquiteFolder + fileName; String tempPackagePath = getRootPath() + pathInMesquiteFolder + fileName + "PREVIOUSVERSION"; File prevPackage = new File(prevPackagePath); File tempPackage = new File(tempPackagePath); boolean hadExisted = tempPackage.exists(); if (hadExisted) { logln("Installation unsuccessful; attempting to recover old version of " + fileName); if (prevPackage.isDirectory()) MesquiteFile.deleteDirectory(getRootPath() + pathInMesquiteFolder + fileName); else/*from w w w .j a v a2 s. c o m*/ MesquiteFile.deleteFile(getRootPath() + pathInMesquiteFolder + fileName); MesquiteFile.rename(tempPackagePath, prevPackagePath); } }
From source file:mesquite.minimal.Simplicity.Simplicity.java
License:Open Source License
StringArray importFile(String path, boolean isDefault) { if (!MesquiteFile.fileExists(path)) return null; String settingsXML = MesquiteFile.getFileContentsAsString(path); Element root = XMLUtil.getRootXMLElementFromString("mesquite", settingsXML); if (root == null) return null; Element element = root.element("simplicitySettings"); if (element != null) { Element versionElement = element.element("version"); if (versionElement == null) return null; else {// ww w.j a v a 2 s. co m int version = MesquiteInteger.fromString(element.elementText("version")); boolean acceptableVersion = version == 1; if (acceptableVersion) { String name = (element.elementText("name")); StringArray s = new StringArray(3); s.setName(name); s.setValue(XML, settingsXML); s.setValue(PATH, path); if (isDefault) s.setValue(DEFAULTORNOT, "default"); else s.setValue(DEFAULTORNOT, "nonDefault"); return s; } } } return null; }
From source file:mesquite.minimal.Simplicity.Simplicity.java
License:Open Source License
public void renameSettingsFile(int i, String newName) { if (!MesquiteInteger.isCombinable(i) || i < 0 || i >= InterfaceManager.settingsFiles.size()) return;/*from ww w . j av a2s . com*/ StringArray s = (StringArray) InterfaceManager.settingsFiles.elementAt(i); String path = s.getValue(PATH); String settingsXML = s.getValue(XML); Element root = XMLUtil.getRootXMLElementFromString("mesquite", settingsXML); if (root == null) return; Element element = root.element("simplicitySettings"); if (element != null) { Element versionElement = element.element("version"); if (versionElement == null) return; else { int version = MesquiteInteger.fromString(element.elementText("version")); boolean acceptableVersion = version == 1; if (acceptableVersion) { Element name = element.element("name"); Element settingsFile = DocumentHelper.createElement("mesquite"); Document doc = DocumentHelper.createDocument(settingsFile); Element hidden = DocumentHelper.createElement("simplicitySettings"); settingsFile.add(hidden); XMLUtil.addFilledElement(hidden, "version", "1"); XMLUtil.addFilledElement(hidden, "name", newName); Element hp = element.element("hiddenPackages"); element.remove(hp); hidden.add(hp); hp = element.element("hiddenMenuItems"); element.remove(hp); hidden.add(hp); hp = element.element("hiddenTools"); element.remove(hp); hidden.add(hp); s.setName(newName); MesquiteFile.putFileContents(path, XMLUtil.getDocumentAsXMLString(doc), false); } } } }
From source file:mesquite.minimal.Simplicity.Simplicity.java
License:Open Source License
public void loadSettingsFile(StringArray s) { if (s == null) return;/* www . j a va 2s . c o m*/ settingsLoaded = true; InterfaceManager.hiddenPackages.removeAllElements(false); InterfaceManager.hiddenMenuItems.removeAllElements(false); InterfaceManager.hiddenTools.removeAllElements(false); String settingsXML = s.getValue(XML); Element root = XMLUtil.getRootXMLElementFromString("mesquite", settingsXML); if (root == null) return; Element element = root.element("simplicitySettings"); if (element != null) { Element versionElement = element.element("version"); if (versionElement == null) return; else { int version = MesquiteInteger.fromString(element.elementText("version")); boolean acceptableVersion = version == 1; if (acceptableVersion) { String name = (element.elementText("name")); InterfaceManager.themeName = name; Element packages = element.element("hiddenPackages"); if (packages != null) { List packageElements = packages.elements("package"); for (Iterator iter = packageElements.iterator(); iter.hasNext();) { // this is going through all of the notices Element hiddenPackage = (Element) iter.next(); String pkg = hiddenPackage.element("name").getText(); InterfaceManager.addPackageToHidden(pkg, false); } } Element menuItems = element.element("hiddenMenuItems"); if (menuItems != null) { List menuElements = menuItems.elements("menuItem"); for (Iterator iter = menuElements.iterator(); iter.hasNext();) { // this is going through all of the notices Element hiddenM = (Element) iter.next(); String label = XMLUtil.getTextFromElement(hiddenM, "label"); String arguments = XMLUtil.getTextFromElement(hiddenM, "arguments"); String command = XMLUtil.getTextFromElement(hiddenM, "command"); String commandableClass = XMLUtil.getTextFromElement(hiddenM, "commandableClass"); String dutyClass = XMLUtil.getTextFromElement(hiddenM, "dutyClass"); InterfaceManager.hiddenMenuItems.addElement( new MenuVisibility(label, arguments, command, commandableClass, dutyClass), false); } } Element tools = element.element("hiddenTools"); if (tools != null) { List buttonElement = tools.elements("tool"); for (Iterator iter = buttonElement.iterator(); iter.hasNext();) { // this is going through all of the notices Element hiddenT = (Element) iter.next(); String n = XMLUtil.getTextFromElement(hiddenT, "name"); String d = XMLUtil.getTextFromElement(hiddenT, "description"); InterfaceManager.hiddenTools.addElement(new MesquiteString(n, d), false); } } storePreferences(); } } } InterfaceManager.reset(); }
From source file:mesquite.molec.lib.NCBIUtil.java
License:Open Source License
public static String[] requestGenBankAccessions(String eSearchResponse, int number) { if (eSearchResponse == null) return null; String[] accessions = new String[number]; Element gbSetElement = XMLUtil.getRootXMLElementFromString("GBSet", eSearchResponse); if (gbSetElement == null) return null; int count = 0; String s = ""; List gbSeqList = gbSetElement.elements("GBSeq"); for (Iterator iter = gbSeqList.iterator(); iter.hasNext();) { // this is going through all of the hits Element gbSeqElement = (Element) iter.next(); if (gbSeqElement != null) { if (count < accessions.length) { accessions[count] = gbSeqElement.elementText("GBSeq_primary-accession"); } else return accessions; count++;//from ww w . j a v a 2s . c om } } return accessions; }
From source file:mesquite.molec.lib.NCBIUtil.java
License:Open Source License
public static String getGenIDFromELinkResults(String response) { if (response == null) return null; Element eLinkResultElement = XMLUtil.getRootXMLElementFromString("eLinkResult", response); if (eLinkResultElement == null) return null; String s = ""; Element LinkSetElement = eLinkResultElement.element("LinkSet"); if (LinkSetElement != null) { // Element LinkSetDBElement = LinkSetElement.element("LinkSetDb"); List hitList = LinkSetElement.elements("LinkSetDb"); for (Iterator iter = hitList.iterator(); iter.hasNext();) { // this is going through all of the hits Element hitElement = (Element) iter.next(); if (hitElement != null) { String linkName = hitElement.elementText("LinkName"); if ("protein_nuccore_mrna".equalsIgnoreCase(linkName)) { Element LinkElement = hitElement.element("Link"); if (LinkElement != null) { s = LinkElement.elementText("Id"); return s; }//from w w w.j a v a2 s . c o m } } } } return null; }
From source file:musite.io.xml.PredictionResultXMLReader.java
License:Open Source License
public PredictionResult read(InputStream is) throws IOException { if (is == null) { throw new IllegalArgumentException(); }//from w w w .ja v a2 s.c o m final PredictionResult result = data == null ? new PredictionResultImpl() : data; ProteinsXMLReader proteinsReader = ProteinsXMLReader.createReader(result, false); proteinsReader.setRoot(root); ProteinResidueAnnotationReader annReader = new ProteinResidueAnnotationReader(); annReader.putAnnotationFieldReader(musite.prediction.PredictionResult.ANNOTATION_FIELD_SCORE, SimpleFieldXMLReader.createDoubleCollectionReader()); proteinsReader.putProteinFieldReader(musite.ResidueAnnotationUtil.RESIDUE_ANNOTATION, annReader); String path = "/model-list/model"; if (root != null) path = "/" + root + path; proteinsReader.addSaxReaderHandler(path, new ElementHandler() { public void onStart(ElementPath path) { } public void onEnd(ElementPath path) { Element elem = path.getCurrent(); String name = StringEscapeUtils.unescapeXml(elem.attributeValue("name")); PTM ptm = null; String strPTM = StringEscapeUtils.unescapeXml(elem.elementText("ptm")); if (strPTM != null) ptm = PTM.valueOf(strPTM); Set<AminoAcid> aas = null; String strAAs = StringEscapeUtils.unescapeXml(elem.elementText("amino-acids")); if (strAAs != null) { String[] strs = strAAs.replaceAll("\n", "").split(";"); int n = strs.length; aas = new HashSet(n); for (int i = 0; i < n; i++) { String str = strs[i].trim(); aas.add(AminoAcid.valueOf(str)); } } SpecificityEstimatorImpl si = null; String strSI = StringEscapeUtils.unescapeXml(elem.elementText("spec-estimate-data")); if (strSI != null) { String[] strs = strSI.replaceAll("\n", "").split(";"); List<Double> train = new ArrayList(); for (String str : strs) { train.add(Double.valueOf(str.trim())); } si = new SpecificityEstimatorImpl(train); } String comment = StringEscapeUtils.unescapeXml(elem.elementText("comment")); if (comment != null) comment = comment.replaceAll("%EOL%", "\n"); PredictionModelImpl model = new PredictionModelImpl.Builder().name(name).ptm(ptm).aminoAcids(aas) .specEstimator(si).comment(comment).build(); result.addModel(model); // prune the tree elem.detach(); } }); proteinsReader.read(is); return result; }
From source file:net.sf.cpsolver.ifs.example.tt.TimetableModel.java
License:Open Source License
public static TimetableModel loadFromXML(File inFile, boolean assign) throws IOException, DocumentException { Document document = (new SAXReader()).read(inFile); Element root = document.getRootElement(); if (!"Timetable".equals(root.getName())) { sLogger.error("Given XML file is not interactive timetabling problem."); return null; }/* ww w. j a v a 2s . co m*/ Element problem = root.element("Problem"); Element problemGen = problem.element("General"); TimetableModel m = new TimetableModel(Integer.parseInt(problemGen.elementText("DaysPerWeek")), Integer.parseInt(problemGen.elementText("SlotsPerDay"))); Element resources = problem.element("Resources"); HashMap<String, Resource> resTab = new HashMap<String, Resource>(); Element resEl = resources.element("Classrooms"); for (Iterator<?> i = resEl.elementIterator("Resource"); i.hasNext();) { Element el = (Element) i.next(); Resource r = new Resource(el.attributeValue("id"), Resource.TYPE_ROOM, el.elementText("Name")); Element pref = el.element("TimePreferences"); for (Iterator<?> j = pref.elementIterator("Soft"); j.hasNext();) r.addDiscouragedSlot(Integer.parseInt(((Element) j.next()).getText())); for (Iterator<?> j = pref.elementIterator("Hard"); j.hasNext();) r.addProhibitedSlot(Integer.parseInt(((Element) j.next()).getText())); m.addConstraint(r); resTab.put(r.getResourceId(), r); } resEl = resources.element("Teachers"); for (Iterator<?> i = resEl.elementIterator("Resource"); i.hasNext();) { Element el = (Element) i.next(); Resource r = new Resource(el.attributeValue("id"), Resource.TYPE_INSTRUCTOR, el.elementText("Name")); Element pref = el.element("TimePreferences"); for (Iterator<?> j = pref.elementIterator("Soft"); j.hasNext();) r.addDiscouragedSlot(Integer.parseInt(((Element) j.next()).getText())); for (Iterator<?> j = pref.elementIterator("Hard"); j.hasNext();) r.addProhibitedSlot(Integer.parseInt(((Element) j.next()).getText())); m.addConstraint(r); resTab.put(r.getResourceId(), r); } resEl = resources.element("Classes"); for (Iterator<?> i = resEl.elementIterator("Resource"); i.hasNext();) { Element el = (Element) i.next(); Resource r = new Resource(el.attributeValue("id"), Resource.TYPE_CLASS, el.elementText("Name")); Element pref = el.element("TimePreferences"); for (Iterator<?> j = pref.elementIterator("Soft"); j.hasNext();) r.addDiscouragedSlot(Integer.parseInt(((Element) j.next()).getText())); for (Iterator<?> j = pref.elementIterator("Hard"); j.hasNext();) r.addProhibitedSlot(Integer.parseInt(((Element) j.next()).getText())); m.addConstraint(r); resTab.put(r.getResourceId(), r); } resEl = resources.element("Special"); for (Iterator<?> i = resEl.elementIterator("Resource"); i.hasNext();) { Element el = (Element) i.next(); Resource r = new Resource(el.attributeValue("id"), Resource.TYPE_OTHER, el.elementText("Name")); Element pref = el.element("TimePreferences"); for (Iterator<?> j = pref.elementIterator("Soft"); j.hasNext();) r.addDiscouragedSlot(Integer.parseInt(((Element) j.next()).getText())); for (Iterator<?> j = pref.elementIterator("Hard"); j.hasNext();) r.addProhibitedSlot(Integer.parseInt(((Element) j.next()).getText())); m.addConstraint(r); resTab.put(r.getResourceId(), r); } Element actEl = problem.element("Activities"); HashMap<String, Activity> actTab = new HashMap<String, Activity>(); for (Iterator<?> i = actEl.elementIterator("Activity"); i.hasNext();) { Element el = (Element) i.next(); Activity a = new Activity(Integer.parseInt(el.elementText("Length")), el.attributeValue("id"), el.elementText("Name")); Element pref = el.element("TimePreferences"); for (Iterator<?> j = pref.elementIterator("Soft"); j.hasNext();) a.addDiscouragedSlot(Integer.parseInt(((Element) j.next()).getText())); for (Iterator<?> j = pref.elementIterator("Hard"); j.hasNext();) a.addProhibitedSlot(Integer.parseInt(((Element) j.next()).getText())); Element req = el.element("RequiredResources"); for (Iterator<?> j = req.elementIterator(); j.hasNext();) { Element rqEl = (Element) j.next(); if ("Resource".equals(rqEl.getName())) { a.addResourceGroup(resTab.get(rqEl.getText())); } else if ("Group".equals(rqEl.getName())) { if ("no".equalsIgnoreCase(rqEl.attributeValue("conjunctive")) || "false".equalsIgnoreCase(rqEl.attributeValue("conjunctive"))) { List<Resource> gr = new ArrayList<Resource>(); for (Iterator<?> k = rqEl.elementIterator("Resource"); k.hasNext();) gr.add(resTab.get(((Element) k.next()).getText())); a.addResourceGroup(gr); } else { for (Iterator<?> k = rqEl.elementIterator("Resource"); k.hasNext();) a.addResourceGroup(resTab.get(((Element) k.next()).getText())); } } } m.addVariable(a); a.init(); actTab.put(a.getActivityId(), a); } Element depEl = problem.element("Dependences"); for (Iterator<?> i = depEl.elementIterator("Dependence"); i.hasNext();) { Element el = (Element) i.next(); int type = Dependence.TYPE_NO_DEPENDENCE; String typeStr = el.elementText("Operator"); if ("After".equals(typeStr)) type = Dependence.TYPE_AFTER; else if ("Before".equals(typeStr)) type = Dependence.TYPE_BEFORE; else if ("After".equals(typeStr)) type = Dependence.TYPE_AFTER; else if ("Closely before".equals(typeStr)) type = Dependence.TYPE_CLOSELY_BEFORE; else if ("Closely after".equals(typeStr)) type = Dependence.TYPE_CLOSELY_AFTER; else if ("Concurrently".equals(typeStr)) type = Dependence.TYPE_CONCURRENCY; Dependence d = new Dependence(el.attributeValue("id"), type); d.addVariable(actTab.get(el.elementText("FirstActivity"))); d.addVariable(actTab.get(el.elementText("SecondActivity"))); m.addConstraint(d); } Element solEl = root.element("Solution"); if (solEl != null) { for (Iterator<?> i = solEl.elementIterator("Activity"); i.hasNext();) { Element el = (Element) i.next(); Activity a = actTab.get(el.attributeValue("id")); if (a == null) continue; int slot = Integer.parseInt(el.elementText("StartTime")); Element usResEl = el.element("UsedResources"); List<Resource> res = new ArrayList<Resource>(); for (Iterator<?> j = usResEl.elementIterator("Resource"); j.hasNext();) res.add(resTab.get(((Element) j.next()).getText())); for (Location loc : a.values()) { if (loc.getSlot() != slot || loc.getResources().length != res.size()) continue; boolean same = true; for (int j = 0; j < loc.getResources().length && same; j++) if (!res.get(j).equals(loc.getResources()[j])) same = false; if (!same) continue; a.setInitialAssignment(loc); if (assign) a.assign(0, loc); break; } } } return m; }
From source file:net.sf.jvifm.model.BookmarkManager.java
License:Open Source License
@SuppressWarnings("unchecked") private void init() { storePath = HomeLocator.getConfigHome() + File.separator + "bookmarks.xml"; SAXReader saxReader = new SAXReader(); File file = new File(storePath); Document document = null;//from w w w .j av a2 s. co m try { if (file.exists()) { FileInputStream is = new FileInputStream(file); InputStreamReader reader = new InputStreamReader(is, "UTF-8"); BufferedReader br = new BufferedReader(reader); document = saxReader.read(br); List elementList = document.selectNodes("//bookmark"); for (Iterator it = elementList.iterator(); it.hasNext();) { Element bookmarkElement = (Element) it.next(); String name = bookmarkElement.elementText("name"); String path = bookmarkElement.elementText("path"); String key = bookmarkElement.elementText("key"); Bookmark bookmark = new Bookmark(); bookmark.setPath(path); bookmark.setName(name); bookmark.setKey(key); if (key != null) { bookmarkMap.put(key, bookmark); } bookmarkList.add(bookmark); } reader.close(); is.close(); } } catch (Exception e) { e.printStackTrace(); } }