public String getPreviousStage(String currStage) { if (currStage == null) { return null; } int ind = currStage.indexOf(":"); Version v = new Version(currStage.substring(0, ind)); int lind = Integer.parseInt(currStage.substring(ind + 1)); java.util.List<WhatsNewItem> its = this.items.get(v); if (its == null) { return null; } lind--; if (lind > -1) { return v.getVersion() + ":" + lind; } Version p = this.items.lowerKey(v); if (p == null) { return null; } java.util.List<WhatsNewItem> pits = this.items.get(p); if (pits != null) { return p.getVersion() + ":" + (pits.size() - 1); } return null; }
public String getNextStage(String currStage) { if (currStage == null) { return this.getStartStage(); } int ind = currStage.indexOf(":"); Version v = new Version(currStage.substring(0, ind)); int lind = Integer.parseInt(currStage.substring(ind + 1)); java.util.List<WhatsNewItem> its = this.items.get(v); if (its == null) { return null; } lind++; if (lind <= (its.size() - 1)) { return v.getVersion() + ":" + lind; } Version n = this.items.higherKey(v); if (n == null) { return null; } java.util.List<WhatsNewItem> nits = this.items.get(n); if (nits != null) { return n.getVersion() + ":0"; } return null; }
public WhatsNew(AbstractProjectViewer pv, boolean onlyShowCurrentVersion) throws GeneralException { super(pv); String wn = Environment.getProperty(Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME); if (wn == null) { wn = "0"; } // Get the current whats new version (i.e. old). Version lastWhatsNewVersion = new Version(wn); boolean betasAllowed = Environment.getUserProperties() .getPropertyAsBoolean(Constants.OPTIN_TO_BETA_VERSIONS_PROPERTY_NAME); try { String whatsNew = Environment.getResourceFileAsString(Constants.WHATS_NEW_FILE); // Load up all the whats new for greater versions. Element root = JDOMUtils.getStringAsElement(whatsNew); java.util.List verEls = JDOMUtils.getChildElements(root, XMLConstants.version, false); // Assume they are in the right order // TODO: Enforce the order and/or sort. for (int i = 0; i < verEls.size(); i++) { Element vEl = (Element) verEls.get(i); String id = JDOMUtils.getAttributeValue(vEl, XMLConstants.id, true); Version v = new Version(id); /* if ((v.isBeta ()) && (!betasAllowed) ) { // Ignore, the user isn't interested in betas. continue; } */ if ((lastWhatsNewVersion.isNewer(v)) || ((onlyShowCurrentVersion) && (v.isSame(Environment.getQuollWriterVersion())))) { String c = WhatsNewComponentProvider.class.getName(); int ind = c.lastIndexOf("."); if (ind > 0) { c = c.substring(0, ind); } WhatsNewComponentProvider compProv = null; String cl = JDOMUtils.getAttributeValue(vEl, XMLConstants.clazz, false); if (!cl.equals("")) { Class clz = null; try { clz = Class.forName(cl); if (WhatsNewComponentProvider.class.isAssignableFrom(clz)) { compProv = (WhatsNewComponentProvider) clz.newInstance(); } } catch (Exception e) { } } // This is a version we are interested in. java.util.List itemEls = JDOMUtils.getChildElements(vEl, WhatsNewItem.XMLConstants.root, true); java.util.List<WhatsNewItem> its = new ArrayList(); for (int j = 0; j < itemEls.size(); j++) { Element itEl = (Element) itemEls.get(j); WhatsNewItem it = new WhatsNewItem(itEl, compProv, pv); if (it.onlyIfCurrentVersion) { if (!Environment.getQuollWriterVersion().isSame(v)) { continue; } } if ((it.description == null) && (it.component == null)) { Environment.logMessage( "Whats new item has no description or component, referenced by: " + JDOMUtils.getPath(itEl)); continue; } its.add(it); } if (its.size() > 0) { this.items.put(v, its); } } } } catch (Exception e) { throw new GeneralException("Unable to init whats new", e); } }