List of usage examples for org.dom4j Element elementText
String elementText(QName qname);
From source file:me.zhuoran.crawler4j.crawler.config.XmlLoader.java
License:Apache License
/** * Load and parse the crawler4j.xml to get all crawlers. * @return WebCrawler instance list;//from w ww. ja v a 2s .com * @throws Exception */ @SuppressWarnings("unchecked") public List<WebCrawler> load() { List<WebCrawler> crawlers = new ArrayList<WebCrawler>(); SAXReader reader = new SAXReader(); try { InputStream is = this.getClass().getClassLoader().getResourceAsStream(DEFAULT_CONFIG_FILE); document = reader.read(is); Element root = document.getRootElement(); for (Iterator<Element> i = root.elementIterator(); i.hasNext();) { Element taskElement = i.next(); String name = taskElement.elementText("name"); long delay = Long.parseLong(taskElement.elementText("delay")); String url = taskElement.elementText("url"); String parserName = taskElement.elementText("parser").trim(); String defaultCharset = taskElement.elementText("charset"); String pageNoStr = taskElement.elementText("max_page"); String crawlerName = taskElement.elementText("crawler"); String nextPageRegex = taskElement.elementText("next_page_key"); String extractLinksElementId = taskElement.elementText("extract_links_elementId"); Class<Parser> c = (Class<Parser>) Class.forName(parserName); Parser parser = c.newInstance(); if (parser == null) { throw new IllegalArgumentException("parser must not be null!"); } int maxPageNo = 1; if (StringUtils.isNotEmpty(pageNoStr)) { maxPageNo = Integer.parseInt(pageNoStr); } CrawlerConfig config = new CrawlerConfig(name, defaultCharset, url, delay, maxPageNo, nextPageRegex, extractLinksElementId, parserName, crawlerName, parser); WebCrawler crawler = null; //get WebCrawler instance throw reflection if (StringUtils.isBlank(crawlerName)) { crawler = new DefaultWebCrawler(config); } else { crawler = (WebCrawler) Reflections.constructorNewInstance(crawlerName, new Class[] { CrawlerConfig.class }, new CrawlerConfig[] { config }); } crawlers.add(crawler); } } catch (Throwable e) { logger.error(e.getMessage(), e); } return crawlers; }
From source file:mesquite.chromaseq.lib.SequenceProfile.java
License:Open Source License
public boolean readXML(String contents) { Element root = XMLUtil.getRootXMLElementFromString("mesquite", contents); if (root == null) return false; Element sequenceProfileElement = root.element("sequenceProfile"); if (sequenceProfileElement != null) { Element versionElement = sequenceProfileElement.element("version"); if (versionElement == null || !versionElement.getText().equals("1")) { return false; }//from w ww.j ava 2 s.c o m Element boundedByTokens = sequenceProfileElement.element("boundedByTokens"); if (boundedByTokens == null) { return false; } name = boundedByTokens.elementText("name"); description = boundedByTokens.elementText("description"); location = boundedByTokens.elementText("location"); moltype = boundedByTokens.elementText("moltype"); productName = boundedByTokens.elementText("productName"); seqIDSuffix = boundedByTokens.elementText("seqIDSuffix"); note = boundedByTokens.elementText("note"); gcode = MesquiteInteger.fromString(boundedByTokens.elementText("gcode")); // CDS = MesquiteBoolean.fromTrueFalseString(boundedByTokens.elementText("CDS")); //translateSampleCodes = MesquiteBoolean.fromTrueFalseString(boundedByTokens.elementTextTrim("translateSampleCodes")); } else { return false; } return true; }
From source file:mesquite.chromaseq.SampleAndPrimerFileNameParser.ChromFileNameParsing.java
License:Open Source License
public boolean readXML(String contents) { Element root = XMLUtil.getRootXMLElementFromString("mesquite", contents); if (root == null) return false; Element chromFileNameParsingRules = root.element("chromFileNameParsingRules"); if (chromFileNameParsingRules != null) { Element versionElement = chromFileNameParsingRules.element("version"); if (versionElement == null || !versionElement.getText().equals("1")) { return false; }/* ww w .ja v a 2s. c om*/ Element boundedByTokens = chromFileNameParsingRules.element("boundedByTokens"); if (boundedByTokens == null) { return false; } name = boundedByTokens.elementText("name"); dnaCodeStartToken = boundedByTokens.elementText("dnaCodeStartToken"); dnaCodeEndToken = boundedByTokens.elementText("dnaCodeEndToken"); dnaCodeSuffixToken = boundedByTokens.elementText("dnaCodeSuffixToken"); dnaCodeRemovalToken = boundedByTokens.elementText("dnaCodeRemovalToken"); primerStartToken = boundedByTokens.elementText("primerStartToken"); primerEndToken = boundedByTokens.elementText("primerEndToken"); sampleCodeFirst = MesquiteBoolean.fromTrueFalseString(boundedByTokens.elementText("sampleCodeFirst")); //primerListPath = boundedByTokens.elementTextTrim("primerListPath"); //dnaNumberListPath = boundedByTokens.elementTextTrim("dnaNumberListPath"); //translateSampleCodes = MesquiteBoolean.fromTrueFalseString(boundedByTokens.elementTextTrim("translateSampleCodes")); } else { return false; } return true; /*Parser parser = new Parser(); Parser subParser = new Parser(); parser.setString(contents); boolean acceptableVersion = false; if (!parser.isXMLDocument(false)) // check if XML return false; if (!parser.resetToMesquiteTagContents()) // check if has mesquite tag return false; MesquiteString nextTag = new MesquiteString(); String tagContent = parser.getNextXMLTaggedContent(nextTag); if ("chromFileNameParsingRules".equalsIgnoreCase(nextTag.getValue())) { //make sure it has the right root tag parser.setString(tagContent); tagContent = parser.getNextXMLTaggedContent(nextTag); String subTagContent; while (!StringUtil.blank(tagContent)) { if ("version".equalsIgnoreCase(nextTag.getValue())) { if ("1".equalsIgnoreCase(tagContent)) acceptableVersion = true; else return false; } else if ("boundedByTokens".equalsIgnoreCase(nextTag.getValue()) && acceptableVersion) { subParser.setString(tagContent); subTagContent = subParser.getNextXMLTaggedContent(nextTag); while (!StringUtil.blank(nextTag.getValue())) { if ("name".equalsIgnoreCase(nextTag.getValue())) name = StringUtil.cleanXMLEscapeCharacters(subTagContent); else if ("dnaCodeStartToken".equalsIgnoreCase(nextTag.getValue())) dnaCodeStartToken = processTokenAfterRead(StringUtil.cleanXMLEscapeCharacters(subTagContent)); else if ("dnaCodeEndToken".equalsIgnoreCase(nextTag.getValue())) dnaCodeEndToken = processTokenAfterRead(StringUtil.cleanXMLEscapeCharacters(subTagContent)); else if ("dnaCodeSuffixToken".equalsIgnoreCase(nextTag.getValue())) dnaCodeSuffixToken = processTokenAfterRead(StringUtil.cleanXMLEscapeCharacters(subTagContent)); else if ("dnaCodeRemovalToken".equalsIgnoreCase(nextTag.getValue())) dnaCodeRemovalToken = processTokenAfterRead(StringUtil.cleanXMLEscapeCharacters(subTagContent)); else if ("primerStartToken".equalsIgnoreCase(nextTag.getValue())) primerStartToken = processTokenAfterRead(StringUtil.cleanXMLEscapeCharacters(subTagContent)); else if ("primerEndToken".equalsIgnoreCase(nextTag.getValue())) primerEndToken = processTokenAfterRead(StringUtil.cleanXMLEscapeCharacters(subTagContent)); else if ("sampleCodeFirst".equalsIgnoreCase(nextTag.getValue())) sampleCodeFirst = MesquiteBoolean.fromTrueFalseString(subTagContent); /* else if ("primerListPath".equalsIgnoreCase(nextTag.getValue())) primerListPath = StringUtil.cleanXMLEscapeCharacters(subTagContent); else if ("dnaNumberListPath".equalsIgnoreCase(nextTag.getValue())) dnaNumberListPath = StringUtil.cleanXMLEscapeCharacters(subTagContent); else if ("translateSampleCodes".equalsIgnoreCase(nextTag.getValue())) translateSampleCodes = MesquiteBoolean.fromTrueFalseString(subTagContent); / subTagContent = subParser.getNextXMLTaggedContent(nextTag); } } tagContent = parser.getNextXMLTaggedContent(nextTag); } } else return false; return true;*/ }
From source file:mesquite.lib.MesquiteXMLPreferencesModule.java
License:Open Source License
/** * Ideally this should not be static but since we don't always have control over the superclass, * make it available for classes that might otherwise not be able to use it due to inheritance * constraints//w ww . java 2 s.co m * @param prefsXML * @param provider * @param version * @param versionsMustMatch * @return */ public static boolean parseFullXMLDocument(String prefsXML, PropertyNamesProvider provider, int version, boolean versionsMustMatch) { Document doc = XMLUtil.getDocumentFromString(prefsXML); if (doc == null) { // not xml -- can't parse it return false; } Element rootElement = doc.getRootElement(); String shortClassName = getShortClassName(provider.getClass()); Element classElement = rootElement.element(shortClassName); if (classElement != null) { String versionString = classElement.elementText(VERSION); int versionInXml = MesquiteInteger.fromString(versionString); boolean acceptableVersion = (versionInXml == version || !versionsMustMatch); if (isCorrectRootTag(classElement.getName(), provider.getClass()) && acceptableVersion) { List prefsChildren = classElement.elements(PREFERENCE); for (Iterator iter = prefsChildren.iterator(); iter.hasNext();) { Element nextPreferenceElement = (Element) iter.next(); String key = nextPreferenceElement.attributeValue(KEY); String value = nextPreferenceElement.getText(); try { PropertyUtils.smartWrite(provider, key, value); } catch (Exception e) { MesquiteMessage.warnProgrammer("Could not write property value " + key + " for loading xml preferences on module: " + provider); } } return true; } } return false; }
From source file:mesquite.lib.PhoneHomeUtil.java
License:Open Source License
public static void readOldPhoneRecords(String path, ListableVector phoneRecords) { if (StringUtil.blank(path)) return;//from ww w. j av a 2s . c om String oldPhoneRecords = null; try { oldPhoneRecords = MesquiteFile.getFileContentsAsString(path, -1, 100, false); } catch (Exception e) { return; } if (StringUtil.blank(oldPhoneRecords)) return; Element root = XMLUtil.getRootXMLElementFromString("mesquite", oldPhoneRecords); if (root == null) return; Element messagesFromHome = root.element("phoneRecords"); if (messagesFromHome != null) { Element versionElement = messagesFromHome.element("version"); if (versionElement == null || !versionElement.getText().equals("1")) { return; } //let's get the phone records List noticesFromHomeList = messagesFromHome.elements("record"); for (Iterator iter = noticesFromHomeList.iterator(); iter.hasNext();) { // this is going through all of the notices Element messageElement = (Element) iter.next(); String moduleName = messageElement.elementText("module"); MesquiteModuleInfo mmi = MesquiteTrunk.mesquiteModulesInfoVector.findModule(MesquiteModule.class, moduleName); int lastVersionUsedInt = MesquiteInteger.fromString(messageElement.elementText("lastVersionUsed")); int lastNotice = MesquiteInteger.fromString(messageElement.elementText("lastNotice")); int lastNoticeForMyVersion = MesquiteInteger .fromString(messageElement.elementText("lastNoticeForMyVersion")); if (mmi != null && lastVersionUsedInt != getVersion(mmi)) lastNoticeForMyVersion = 0; int lastVersionNoticed = MesquiteInteger .fromString(messageElement.elementText("lastVersionNoticed")); int lastNewerVersionReported = MesquiteInteger .fromString(messageElement.elementText("lastNewerVersionReported")); PhoneHomeRecord phoneRecord = new PhoneHomeRecord(moduleName, lastVersionUsedInt, lastNotice, lastNoticeForMyVersion, lastVersionNoticed, lastNewerVersionReported); phoneRecords.addElement(phoneRecord, false); } } }
From source file:mesquite.lib.PhoneHomeUtil.java
License:Open Source License
private static String handleMessages(boolean adHoc, String noticesFromHome, MesquiteModuleInfo mmi, PhoneHomeRecord phoneHomeRecord, StringBuffer logBuffer) { /* String url = mmi.getHomePhoneNumber(); if (StringUtil.blank(url))/*from w ww.java 2s. c o m*/ return null; String noticesFromHome = null; try{ noticesFromHome = MesquiteFile.getURLContentsAsString(url, -1, false); } catch (Exception e) { return null; } if (StringUtil.blank(noticesFromHome)) return null; if (mmi.getModuleClass() == mesquite.Mesquite.class) phoneHomeSuccessful = true; */ int lastNoticeForMyVersion = phoneHomeRecord.getLastNoticeForMyVersion(); int lastNotice = phoneHomeRecord.getLastNotice(); int lastVersionNoticed = phoneHomeRecord.getLastVersionNoticed(); Element root = XMLUtil.getRootXMLElementFromString("mesquite", noticesFromHome); if (root == null) return null; Element messagesFromHome = root.element("MessagesFromHome"); if (messagesFromHome != null) { Element versionElement = messagesFromHome.element("version"); if (versionElement == null || !versionElement.getText().equals("1")) { return null; } StringBuffer notices = new StringBuffer(); MesquiteInteger countNotices = new MesquiteInteger(1); //let's get the notices List noticesFromHomeList = messagesFromHome.elements("notice"); for (Iterator iter = noticesFromHomeList.iterator(); iter.hasNext();) { // this is going through all of the notices Element messageElement = (Element) iter.next(); int forMesquiteVersionLessOrEqual = MesquiteInteger .fromString(messageElement.elementText("forMesquiteVersionLessOrEqual")); // notice is for this version and any previous version if (!MesquiteInteger.isCombinable(forMesquiteVersionLessOrEqual)) forMesquiteVersionLessOrEqual = MesquiteInteger .fromString(messageElement.elementText("forVersion")); // old name //NOTE: for adhoc requests forMesquiteVersionLessOrEqual is not used int forPackageVersionExactly = MesquiteInteger .fromString(messageElement.elementText("forPackageVersionExactly")); // notice is for this version and any previous version int forPackageVersionEqualOrGreater = MesquiteInteger .fromString(messageElement.elementText("forPackageVersionEqualOrGreater")); // notice is for this version and any previous version int forPackageVersionEqualOrLess = MesquiteInteger .fromString(messageElement.elementText("forPackageVersionEqualOrLess")); // notice is for this version and any previous version int forBuildNumberExactly = MesquiteInteger .fromString(messageElement.elementText("forBuildNumberExactly")); int forBuildNumberEqualOrGreater = MesquiteInteger .fromString(messageElement.elementText("forBuildNumberEqualOrGreater")); int forBuildNumberEqualOrLess = MesquiteInteger .fromString(messageElement.elementText("forBuildNumberEqualOrLess")); int noticeNumber = MesquiteInteger.fromString(messageElement.elementText("noticeNumber")); String hideFromDialogString = messageElement.elementText("hideFromDialog"); boolean hideFromDialog = false; if (hideFromDialogString != null && hideFromDialogString.equalsIgnoreCase("true")) hideFromDialog = true; String messageType = messageElement.elementText("messageType"); String message = messageElement.elementText("message"); Vector osVector = null; List osList = messageElement.elements("forOS"); for (Iterator i = osList.iterator(); i.hasNext();) { // this is going through all of the notices if (osVector == null) osVector = new Vector(); Element osElement = (Element) i.next(); String[] osStrings = new String[3]; osStrings[OS] = osElement.elementText("OS"); osStrings[OSVERSION] = osElement.elementText("OSVersion"); osStrings[JAVAVERSION] = osElement.elementText("JavaVersion"); osVector.addElement(osStrings); } //INSTALLER: recording update record for later use in dialog and in menu items. //vvvvvvvvvvvvvvvvvvvv====INSTALL/UPDATE SYSTEM ====vvvvvvvvvvvvvvvvvvvv ListableVector v = null; if (messageType.equalsIgnoreCase("update")) { v = new ListableVector(); String packageName = messageElement.elementText("packageName"); String versionNum = messageElement.elementText("updateVersion"); String uniqueLocation = messageElement.elementText("uniqueLocation"); String explanation = messageElement.elementText("explanation"); String updateOnly = messageElement.elementText("updateOnly"); String java = messageElement.elementText("java"); String requires = messageElement.elementText("requires"); String requiredPath = messageElement.elementText("requiredPath"); String beforeMessage = messageElement.elementText("beforeMessage"); String afterMessage = messageElement.elementText("afterMessage"); String uniqueID = MesquiteTrunk.getUniqueIDBase() + updateRecords.size(); v.addElement(new MesquiteString("uniqueID", uniqueID), false); v.addElement(new MesquiteString("identity", messageElement.elementText("identity")), false); v.addElement(new MesquiteString("packageName", packageName), false); v.addElement(new MesquiteString("explanation", explanation), false); if (updateOnly != null) v.addElement(new MesquiteString("updateOnly", updateOnly), false); if (requiredPath != null) v.addElement(new MesquiteString("requiredPath", requiredPath), false); if (requires != null) v.addElement(new MesquiteString("requires", requires), false); if (beforeMessage != null) v.addElement(new MesquiteString("beforeMessage", beforeMessage), false); if (afterMessage != null) v.addElement(new MesquiteString("afterMessage", afterMessage), false); v.addElement(new MesquiteString("updateVersion", versionNum), false); v.addElement(new MesquiteString("uniqueLocation", uniqueLocation), false); v.addElement(new ObjectContainer("install", messageElement.elements("install")), false); v.addElement(new MesquiteBoolean("isInstalled", false), false); if (java != null) v.addElement(new MesquiteString("java", java), false); String ux = XMLUtil.getElementAsXMLString(messageElement, "UTF-8", true); if (ux != null) { ux = "<updateXML>" + ux + "</updateXML>"; //strip for more compact file when viewed ux = StringUtil.replace(ux, "\n", null); ux = StringUtil.replace(ux, "\r", null); ux = StringUtil.replace(ux, "\t", null); ux = StringUtil.stripStuttered(ux, " "); v.addElement(new MesquiteString("updateXML", ux), false); } if (!adHoc) updateRecords.addElement(v); else adHocRecord = v; } //^^^^^^^^^^^^^^^^====install/update system ====^^^^^^^^^^^^^^^^ // process other notice tags here if they are present processSingleNotice(mmi, notices, hideFromDialog, countNotices, forMesquiteVersionLessOrEqual, noticeNumber, messageType, message, lastVersionNoticed, lastNoticeForMyVersion, lastNotice, phoneHomeRecord, osVector, forBuildNumberEqualOrGreater, forBuildNumberEqualOrLess, forBuildNumberExactly, forPackageVersionEqualOrGreater, forPackageVersionEqualOrLess, forPackageVersionExactly, v, adHoc); } //INSTALLER: here go through updateRecords to figure out which are already installed, which not; which have newer versions already installed, etc. refreshUpdateMenuItems(); // now see if there is a tag for the current release version Element currentReleaseVersion = messagesFromHome.element("currentReleaseVersion"); if (mmi != null && currentReleaseVersion != null) { String releaseString = ""; String releaseStringHTML = ""; String versionString = currentReleaseVersion.elementText("versionString"); String versionStringInstalled = null; if (mmi.getIsPackageIntro() && !StringUtil.blank(mmi.getPackageVersion())) versionStringInstalled = mmi.getPackageVersion(); else if (!StringUtil.blank(mmi.getVersion())) versionStringInstalled = mmi.getVersion(); String buildString = currentReleaseVersion.elementText("build"); boolean skip = false; if (versionStringInstalled != null && versionString != null && versionStringInstalled.equals(versionString)) { //same version if (mmi.getModuleClass() != mesquite.Mesquite.class || buildString == null || buildString.equals(Integer.toString(MesquiteModule.getBuildNumber()))) skip = true; //skip unless Mesquite and different build } if (!skip) { String URL = currentReleaseVersion.elementText("URL"); String downloadURL = currentReleaseVersion.elementText("downloadURL"); int releaseVersionInt = MesquiteInteger .fromString(currentReleaseVersion.elementText("version")); int userVersionInt = getVersion(mmi); String fromWhom = null; if (mmi.getModuleClass() == mesquite.Mesquite.class) fromWhom = "Mesquite"; else if (!StringUtil.blank(mmi.getPackageName())) fromWhom = mmi.getPackageName(); else fromWhom = mmi.getName(); if (!StringUtil.blank(versionString)) releaseString += "The current release version of " + fromWhom + " is " + versionString; if (!StringUtil.blank(buildString)) releaseString += " build " + buildString; if (!StringUtil.blank(releaseString)) { if (mmi.getIsPackageIntro()) { if (!StringUtil.blank(mmi.getPackageVersion())) releaseString += " (the version you have installed is " + mmi.getPackageVersion() + ")."; } else if (!StringUtil.blank(mmi.getVersion())) releaseString += " (the version you have installed is " + mmi.getVersion() + ")."; releaseStringHTML = releaseString; if (!StringUtil.blank(URL)) { releaseStringHTML += " <a href=\"" + URL + "\">Home page</a><BR>"; releaseString += " The home page is: " + URL + ". "; } if (!StringUtil.blank(downloadURL)) { releaseStringHTML += " <a href=\"" + downloadURL + "\">Download page</a>. You may also find an option to install this using Mesquite's automatic installation system (look in File menu under Available to Install or Update)."; releaseString += " The latest version is downloadable at: " + downloadURL + ". You may also be able to install this using Mesquite's automatic installation system (look in File menu under Available to Install or Update)."; } } if (MesquiteInteger.isCombinable(releaseVersionInt) && userVersionInt < releaseVersionInt) { if (phoneHomeRecord.getLastNewerVersionReported() < releaseVersionInt) { // we've not reported on this new version yet notices.append("\n" + releaseStringHTML); // there is a newer version that has been released phoneHomeRecord.setLastNewerVersionReported(releaseVersionInt); } if (logBuffer != null) logBuffer.append("\n" + releaseString); } } } // process other tags if they are there return notices.toString(); } return null; }
From source file:mesquite.lib.XMLUtil.java
License:Open Source License
public static void readXMLPreferences(MesquiteModule module, XMLPreferencesProcessor xmlPrefProcessor, String contents) {/*from w w w.j a v a 2 s . c o m*/ Element root = getRootXMLElementFromString("mesquite", contents); if (root == null) return; Element element = root.element(module.getXMLModuleName()); if (element != null) { Element versionElement = element.element("version"); if (versionElement == null) return; else { int version = MesquiteInteger.fromString(element.elementText("version")); boolean acceptableVersion = (module.getXMLPrefsVersion() == version || !module.xmlPrefsVersionMustMatch()); if (acceptableVersion) processPreferencesFromXML(xmlPrefProcessor, element); else return; } } }
From source file:mesquite.minimal.Installer.Installer.java
License:Open Source License
void readReceipts(String path) { String receiptsContents = null; try {// w w w.ja v a2 s. c o m receiptsContents = MesquiteFile.getFileContentsAsString(path, 2000000, 100, false); } catch (Exception e) { return; } if (StringUtil.blank(receiptsContents)) return; Element root = XMLUtil.getRootXMLElementFromString("mesquite", receiptsContents); if (root == null) return; List receipts = root.elements("installationReceipt"); boolean stillInstalled = true; for (Iterator iter = receipts.iterator(); iter.hasNext();) { // this is going through all of the notices Element messageElement = (Element) iter.next(); ListableVector v = new ListableVector(); v.addElement(new MesquiteString("identity", messageElement.elementText("identity")), false); v.addElement(new MesquiteString("updateVersion", messageElement.elementText("updateVersion")), false); List locs = messageElement.elements("location"); for (Iterator locsIter = locs.iterator(); locsIter.hasNext();) { // this is going through all of the notices Element locElement = (Element) locsIter.next(); String p = locElement.elementText("path"); if (!MesquiteFile.fileOrDirectoryExists(MesquiteTrunk.getRootPath() + p)) stillInstalled = false; v.addElement(new MesquiteString("location", locElement.elementText("path")), false); } v.addElement(new MesquiteString("explanation", messageElement.elementText("explanation")), false); v.addElement(new MesquiteString("packageName", messageElement.elementText("packageName")), false); v.addElement(new MesquiteString("uniqueLocation", messageElement.elementText("uniqueLocation")), false); Element elup = messageElement.element("updateXML"); if (elup != null) v.addElement( new MesquiteString("updateXML", clean(XMLUtil.getElementAsXMLString(elup, "UTF-8", true))), false); // v.addElement(new MesquiteString("updateXML", "<updateXML>\n" + XMLUtil.getElementAsXMLString(elup, "UTF-8", true) + "</updateXML>" ), false); if (!PhoneHomeUtil.alreadyInReceipts(v)) { if (stillInstalled) PhoneHomeUtil.installedReceipts.addElement(v); } } writeReceipts(); //rewrite into central }
From source file:mesquite.minimal.Installer.Installer.java
License:Open Source License
boolean applicableOS(Element installElement) { List osList = installElement.elements("forOS"); if (osList == null) return true; if (osList.size() == 0) return true; for (Iterator i = osList.iterator(); i.hasNext();) { // this is going through all of the notices Element osElement = (Element) i.next(); String os = osElement.elementText("os"); if (os == null) return true; String osVersion = osElement.elementText("osVersion"); String osArch = osElement.elementText("osArch"); boolean osArchMatches = (StringUtil.blank(osArch) || System.getProperty("os.arch").indexOf(osArch) >= 0); boolean osMatches = (StringUtil.blank(os) || System.getProperty("os.name").indexOf(os) >= 0 || (os.equalsIgnoreCase("other") && !MesquiteTrunk.isWindows() && !MesquiteTrunk.isMacOSX())); boolean osVersionMatches = (StringUtil.blank(osVersion) || System.getProperty("os.version").startsWith(osVersion)); if (osMatches && osVersionMatches && osArchMatches) return true; }//from w ww.ja v a 2 s . co m return false; }
From source file:mesquite.minimal.Installer.Installer.java
License:Open Source License
int install(Element installElement, ListableVector receipt) { if (!applicableOS(installElement)) return 1; //return true because not considered failure if inapplicable OS String url = installElement.elementText("url"); String fileName = installElement.elementText("file"); String pathInMesquiteFolder = installElement.elementText("location"); String locationInMesquiteFolder = installElement.elementText("location"); if (!StringUtil.blank(locationInMesquiteFolder)) locationInMesquiteFolder = locationInMesquiteFolder + MesquiteFile.fileSeparator; String directoryLocation = getRootPath() + locationInMesquiteFolder; if (pathInMesquiteFolder != null && pathInMesquiteFolder.equalsIgnoreCase(":query user")) { String dL = MesquiteFile.chooseDirectory("Choose location for " + fileName); if (dL != null) directoryLocation = dL + MesquiteFile.fileSeparator; else// ww w .ja v a2 s. co m directoryLocation = getRootPath(); } int version = MesquiteInteger.fromString(installElement.elementText("updateVersion")); String treatment = installElement.elementText("treatment"); String execute = installElement.elementText("execute"); String executeInMesquiteFolder = installElement.elementText("executeInMesquiteFolder"); String downloadAs = "installerDownload"; if (treatment == null || treatment.equalsIgnoreCase("asis")) downloadAs = fileName; String prevPackagePath = directoryLocation + fileName; String tempPackagePath = directoryLocation + fileName + "PREVIOUSVERSION"; File prevPackage = new File(prevPackagePath); boolean hadExisted = prevPackage.exists(); if (false && hadExisted) { String prevVString = MesquiteFile .getFileContentsAsString(getRootPath() + locationInMesquiteFolder + fileName + "/version.txt"); int prevVersion = MesquiteInteger.fromString(prevVString); if (false && prevVersion >= version) { if (!AlertDialog.query(containerOfModule(), "Replace?", "The version of the package " + fileName + " installed (" + prevVersion + ") is the same as or newer than the one to be downloaded (" + version + ") . Do you want to replace it with the one to be downloaded?")) { return -3; } } } if (url != null) { logln("Downloading installation file from " + url); if (!MesquiteFile.fileOrDirectoryExists(directoryLocation)) { MesquiteFile.createDirectory(directoryLocation); } if (hadExisted) { logln("Renaming old version of " + fileName + " to " + fileName + "PREVIOUSVERSION"); MesquiteFile.rename(prevPackagePath, tempPackagePath); } logln("Downloading installation file to " + directoryLocation + downloadAs); int response = MesquiteFile.downloadURLContents(url, directoryLocation + downloadAs, true, true); if (response == 1) { boolean fileReady = true; if (treatment != null && treatment.equalsIgnoreCase("unzip")) { logln("Unzipping installation file"); fileReady = unzip(directoryLocation, downloadAs); if (fileReady) MesquiteFile.deleteFile(directoryLocation + downloadAs); } if (fileReady) { logln("Installation of " + fileName + " was successful."); receipt.addElement(new MesquiteString("location", locationInMesquiteFolder + fileName), false); } else if (hadExisted) { logln("Installation unsuccessful; attempting to recover old version of " + fileName); MesquiteFile.rename(tempPackagePath, prevPackagePath); return -4; } } else { MesquiteFile.deleteFile(directoryLocation + downloadAs); return response; } } if (execute != null) { String shortEx = execute; if (execute.length() > 500) shortEx = execute.substring(0, 500); if (AlertDialog.query(containerOfModule(), "Execute Script?", "The installer has downloaded the following script to execute. Is it OK to execute it?\n" + shortEx)) { logln("Executing script"); if (!executeScriptString(execute, false)) { logln("Script execution unsuccessful"); return -5; } } } if (executeInMesquiteFolder != null) { String shortEx = executeInMesquiteFolder; if (executeInMesquiteFolder.length() > 500) shortEx = executeInMesquiteFolder.substring(0, 500); shortEx = "<first, change directories into Mesquite_Folder>\n" + shortEx; if (AlertDialog.query(containerOfModule(), "Execute Script?", "The installer has downloaded the following script to execute. Is it OK to execute it?\n" + shortEx)) { logln("Executing script"); if (!executeScriptString(executeInMesquiteFolder, true)) { logln("Script execution unsuccessful"); return -6; } } } return 1; }