@Test public void TestProgramLinkConversion() throws InvalidMarkupException { assertEquals("<link class=\"Class\" program=\"program.exe\">", FolioLinkUtils.translate(new FolioToken("<PL:Class:\"program.exe\">")).toTokenString()); assertEquals("<link class=\"Class\" href=\"www.program.exe\">", FolioLinkUtils.translate(new FolioToken("<PL:Class:\"www.program.exe\">")).toTokenString()); assertEquals("<link class=\"Class\" href=\"mailto:hello\">", FolioLinkUtils.translate(new FolioToken("<PL:Class:\"mailto:hello\">")).toTokenString()); assertEquals("<link class=\"c\" href=\"www.domain.com\">", FolioLinkUtils.translate(new FolioToken("<PL:c:\"www.domain.com\">")).toTokenString()); assertEquals("<link class=\"c\" program=\"www.temp\\hello.exe\">", FolioLinkUtils.translate(new FolioToken("<PL:c:\"www.temp\\hello.exe\">")).toTokenString()); assertEquals("<link class=\"c\" program=\"www.exe\">", FolioLinkUtils.translate(new FolioToken("<PL:c:\"www.exe\">")).toTokenString()); assertEquals("<link class=\"c\" program=\"C:\\temp.txt\">", FolioLinkUtils.translate(new FolioToken("<PL:c:\"C:\\temp.txt\">")).toTokenString()); }
public static SlxToken translate(FolioToken t) throws InvalidMarkupException { if (t.matches("UL")) { System.out.println("User link (unsupported Folio token):"); System.out.println(t.text); return FolioSlxTranslator.tryCommentOut(t, "UL"); } if (isClosingLinkTag(t)) return new SlxToken("</link>"); else if (isOpeningLinkTag(t)) { if (t.count() < 2 && !t.matches("UL")) throw new InvalidMarkupException("All links (PL, WW, QL, JL, PX, OL, DL, ML) except User Link (UL) must provide at least 2 arguments.", t); SlxToken st = new SlxToken("<link>").set("class", t.get(0)); if (t.matches("WW|PL")) { String cmd = t.get(1); if (t.matches("WW") || isUrl(cmd)) st.set("href", cmd.trim()); else st.set("program", cmd); if (t.count() > 2) throw new InvalidMarkupException("WW, PL, and DL links can only have 2 arguments.", t); } else if (t.matches("QL")) { st.set("query", t.get(1)); int ix = 2; while (ix < t.count()) { String opt = t.get(ix); if (opt.equalsIgnoreCase("RH")) st.set("showOnlyHitRecords", "true"); else if (st.get("infobase") == null) st.set("infobase", opt); else throw new InvalidMarkupException("Unrecognized option " + opt, t); ix++; } } else if (t.matches("OL")) { st.set("objectName", t.get(1)); int ix = 2; while (ix < t.count()) { String opt = t.get(ix); if (opt.equalsIgnoreCase("ZM")) st.set("zoomFit", "true"); else { if (st.get("infobase") == null && opt.toLowerCase().contains(".nfo")) st.set("infobase", opt); else if (st.get("className") == null) st.set("className", opt); else if (st.get("infobase") == null) st.set("infobase", opt); else throw new InvalidMarkupException("Unrecognized option " + opt, t); } ix++; } } else if (t.matches("DL")) { st.set("dataLink", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("WW, PL, and DL links can only have 2 arguments.", t); } else if (t.matches("ML")) { st.set("menu", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("ML (Menu links) can only have 2 arguments.", t); } else if (t.matches("PX")) { st.set("popupTitle", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("PX (Named popup links) can only have 2 arguments.", t); } else if (t.matches("JL")) { st.set("jumpDestination", "_" + t.get(1)); if (t.count() > 2) st.set("infobase", t.get(2)); if (t.count() > 3) throw new InvalidMarkupException("JL (Jump link) may only have 3 arguments." + t.text); } else if (t.matches("EN")) { st.set("query", t.get(1)); if (t.count() == 5) { st.set("popupWidth", t.get(2)); st.set("popupHeight", t.get(3)); st.set("title", t.get(4)); } else if (t.count() == 3) { st.set("title", t.get(2)); } else if (t.count() > 2) { throw new InvalidMarkupException("EN (End note link) may only have 2, 3, or 5 arguments" + t.text); } } else { throw new InvalidMarkupException("Link not supported: " + t.text); } return st; } return null; }
FolioLinkUtils { public static SlxToken translate(FolioToken t) throws InvalidMarkupException { if (t.matches("UL")) { System.out.println("User link (unsupported Folio token):"); System.out.println(t.text); return FolioSlxTranslator.tryCommentOut(t, "UL"); } if (isClosingLinkTag(t)) return new SlxToken("</link>"); else if (isOpeningLinkTag(t)) { if (t.count() < 2 && !t.matches("UL")) throw new InvalidMarkupException("All links (PL, WW, QL, JL, PX, OL, DL, ML) except User Link (UL) must provide at least 2 arguments.", t); SlxToken st = new SlxToken("<link>").set("class", t.get(0)); if (t.matches("WW|PL")) { String cmd = t.get(1); if (t.matches("WW") || isUrl(cmd)) st.set("href", cmd.trim()); else st.set("program", cmd); if (t.count() > 2) throw new InvalidMarkupException("WW, PL, and DL links can only have 2 arguments.", t); } else if (t.matches("QL")) { st.set("query", t.get(1)); int ix = 2; while (ix < t.count()) { String opt = t.get(ix); if (opt.equalsIgnoreCase("RH")) st.set("showOnlyHitRecords", "true"); else if (st.get("infobase") == null) st.set("infobase", opt); else throw new InvalidMarkupException("Unrecognized option " + opt, t); ix++; } } else if (t.matches("OL")) { st.set("objectName", t.get(1)); int ix = 2; while (ix < t.count()) { String opt = t.get(ix); if (opt.equalsIgnoreCase("ZM")) st.set("zoomFit", "true"); else { if (st.get("infobase") == null && opt.toLowerCase().contains(".nfo")) st.set("infobase", opt); else if (st.get("className") == null) st.set("className", opt); else if (st.get("infobase") == null) st.set("infobase", opt); else throw new InvalidMarkupException("Unrecognized option " + opt, t); } ix++; } } else if (t.matches("DL")) { st.set("dataLink", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("WW, PL, and DL links can only have 2 arguments.", t); } else if (t.matches("ML")) { st.set("menu", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("ML (Menu links) can only have 2 arguments.", t); } else if (t.matches("PX")) { st.set("popupTitle", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("PX (Named popup links) can only have 2 arguments.", t); } else if (t.matches("JL")) { st.set("jumpDestination", "_" + t.get(1)); if (t.count() > 2) st.set("infobase", t.get(2)); if (t.count() > 3) throw new InvalidMarkupException("JL (Jump link) may only have 3 arguments." + t.text); } else if (t.matches("EN")) { st.set("query", t.get(1)); if (t.count() == 5) { st.set("popupWidth", t.get(2)); st.set("popupHeight", t.get(3)); st.set("title", t.get(4)); } else if (t.count() == 3) { st.set("title", t.get(2)); } else if (t.count() > 2) { throw new InvalidMarkupException("EN (End note link) may only have 2, 3, or 5 arguments" + t.text); } } else { throw new InvalidMarkupException("Link not supported: " + t.text); } return st; } return null; } }
FolioLinkUtils { public static SlxToken translate(FolioToken t) throws InvalidMarkupException { if (t.matches("UL")) { System.out.println("User link (unsupported Folio token):"); System.out.println(t.text); return FolioSlxTranslator.tryCommentOut(t, "UL"); } if (isClosingLinkTag(t)) return new SlxToken("</link>"); else if (isOpeningLinkTag(t)) { if (t.count() < 2 && !t.matches("UL")) throw new InvalidMarkupException("All links (PL, WW, QL, JL, PX, OL, DL, ML) except User Link (UL) must provide at least 2 arguments.", t); SlxToken st = new SlxToken("<link>").set("class", t.get(0)); if (t.matches("WW|PL")) { String cmd = t.get(1); if (t.matches("WW") || isUrl(cmd)) st.set("href", cmd.trim()); else st.set("program", cmd); if (t.count() > 2) throw new InvalidMarkupException("WW, PL, and DL links can only have 2 arguments.", t); } else if (t.matches("QL")) { st.set("query", t.get(1)); int ix = 2; while (ix < t.count()) { String opt = t.get(ix); if (opt.equalsIgnoreCase("RH")) st.set("showOnlyHitRecords", "true"); else if (st.get("infobase") == null) st.set("infobase", opt); else throw new InvalidMarkupException("Unrecognized option " + opt, t); ix++; } } else if (t.matches("OL")) { st.set("objectName", t.get(1)); int ix = 2; while (ix < t.count()) { String opt = t.get(ix); if (opt.equalsIgnoreCase("ZM")) st.set("zoomFit", "true"); else { if (st.get("infobase") == null && opt.toLowerCase().contains(".nfo")) st.set("infobase", opt); else if (st.get("className") == null) st.set("className", opt); else if (st.get("infobase") == null) st.set("infobase", opt); else throw new InvalidMarkupException("Unrecognized option " + opt, t); } ix++; } } else if (t.matches("DL")) { st.set("dataLink", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("WW, PL, and DL links can only have 2 arguments.", t); } else if (t.matches("ML")) { st.set("menu", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("ML (Menu links) can only have 2 arguments.", t); } else if (t.matches("PX")) { st.set("popupTitle", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("PX (Named popup links) can only have 2 arguments.", t); } else if (t.matches("JL")) { st.set("jumpDestination", "_" + t.get(1)); if (t.count() > 2) st.set("infobase", t.get(2)); if (t.count() > 3) throw new InvalidMarkupException("JL (Jump link) may only have 3 arguments." + t.text); } else if (t.matches("EN")) { st.set("query", t.get(1)); if (t.count() == 5) { st.set("popupWidth", t.get(2)); st.set("popupHeight", t.get(3)); st.set("title", t.get(4)); } else if (t.count() == 3) { st.set("title", t.get(2)); } else if (t.count() > 2) { throw new InvalidMarkupException("EN (End note link) may only have 2, 3, or 5 arguments" + t.text); } } else { throw new InvalidMarkupException("Link not supported: " + t.text); } return st; } return null; }  }
FolioLinkUtils { public static SlxToken translate(FolioToken t) throws InvalidMarkupException { if (t.matches("UL")) { System.out.println("User link (unsupported Folio token):"); System.out.println(t.text); return FolioSlxTranslator.tryCommentOut(t, "UL"); } if (isClosingLinkTag(t)) return new SlxToken("</link>"); else if (isOpeningLinkTag(t)) { if (t.count() < 2 && !t.matches("UL")) throw new InvalidMarkupException("All links (PL, WW, QL, JL, PX, OL, DL, ML) except User Link (UL) must provide at least 2 arguments.", t); SlxToken st = new SlxToken("<link>").set("class", t.get(0)); if (t.matches("WW|PL")) { String cmd = t.get(1); if (t.matches("WW") || isUrl(cmd)) st.set("href", cmd.trim()); else st.set("program", cmd); if (t.count() > 2) throw new InvalidMarkupException("WW, PL, and DL links can only have 2 arguments.", t); } else if (t.matches("QL")) { st.set("query", t.get(1)); int ix = 2; while (ix < t.count()) { String opt = t.get(ix); if (opt.equalsIgnoreCase("RH")) st.set("showOnlyHitRecords", "true"); else if (st.get("infobase") == null) st.set("infobase", opt); else throw new InvalidMarkupException("Unrecognized option " + opt, t); ix++; } } else if (t.matches("OL")) { st.set("objectName", t.get(1)); int ix = 2; while (ix < t.count()) { String opt = t.get(ix); if (opt.equalsIgnoreCase("ZM")) st.set("zoomFit", "true"); else { if (st.get("infobase") == null && opt.toLowerCase().contains(".nfo")) st.set("infobase", opt); else if (st.get("className") == null) st.set("className", opt); else if (st.get("infobase") == null) st.set("infobase", opt); else throw new InvalidMarkupException("Unrecognized option " + opt, t); } ix++; } } else if (t.matches("DL")) { st.set("dataLink", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("WW, PL, and DL links can only have 2 arguments.", t); } else if (t.matches("ML")) { st.set("menu", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("ML (Menu links) can only have 2 arguments.", t); } else if (t.matches("PX")) { st.set("popupTitle", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("PX (Named popup links) can only have 2 arguments.", t); } else if (t.matches("JL")) { st.set("jumpDestination", "_" + t.get(1)); if (t.count() > 2) st.set("infobase", t.get(2)); if (t.count() > 3) throw new InvalidMarkupException("JL (Jump link) may only have 3 arguments." + t.text); } else if (t.matches("EN")) { st.set("query", t.get(1)); if (t.count() == 5) { st.set("popupWidth", t.get(2)); st.set("popupHeight", t.get(3)); st.set("title", t.get(4)); } else if (t.count() == 3) { st.set("title", t.get(2)); } else if (t.count() > 2) { throw new InvalidMarkupException("EN (End note link) may only have 2, 3, or 5 arguments" + t.text); } } else { throw new InvalidMarkupException("Link not supported: " + t.text); } return st; } return null; }  static boolean isOpeningLinkTag(FolioToken t); static boolean isClosingLinkTag(FolioToken t); static SlxToken translate(FolioToken t); static String translateToFolio(SlxToken t, CssClassCleaner css); }
FolioLinkUtils { public static SlxToken translate(FolioToken t) throws InvalidMarkupException { if (t.matches("UL")) { System.out.println("User link (unsupported Folio token):"); System.out.println(t.text); return FolioSlxTranslator.tryCommentOut(t, "UL"); } if (isClosingLinkTag(t)) return new SlxToken("</link>"); else if (isOpeningLinkTag(t)) { if (t.count() < 2 && !t.matches("UL")) throw new InvalidMarkupException("All links (PL, WW, QL, JL, PX, OL, DL, ML) except User Link (UL) must provide at least 2 arguments.", t); SlxToken st = new SlxToken("<link>").set("class", t.get(0)); if (t.matches("WW|PL")) { String cmd = t.get(1); if (t.matches("WW") || isUrl(cmd)) st.set("href", cmd.trim()); else st.set("program", cmd); if (t.count() > 2) throw new InvalidMarkupException("WW, PL, and DL links can only have 2 arguments.", t); } else if (t.matches("QL")) { st.set("query", t.get(1)); int ix = 2; while (ix < t.count()) { String opt = t.get(ix); if (opt.equalsIgnoreCase("RH")) st.set("showOnlyHitRecords", "true"); else if (st.get("infobase") == null) st.set("infobase", opt); else throw new InvalidMarkupException("Unrecognized option " + opt, t); ix++; } } else if (t.matches("OL")) { st.set("objectName", t.get(1)); int ix = 2; while (ix < t.count()) { String opt = t.get(ix); if (opt.equalsIgnoreCase("ZM")) st.set("zoomFit", "true"); else { if (st.get("infobase") == null && opt.toLowerCase().contains(".nfo")) st.set("infobase", opt); else if (st.get("className") == null) st.set("className", opt); else if (st.get("infobase") == null) st.set("infobase", opt); else throw new InvalidMarkupException("Unrecognized option " + opt, t); } ix++; } } else if (t.matches("DL")) { st.set("dataLink", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("WW, PL, and DL links can only have 2 arguments.", t); } else if (t.matches("ML")) { st.set("menu", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("ML (Menu links) can only have 2 arguments.", t); } else if (t.matches("PX")) { st.set("popupTitle", t.get(1)); if (t.count() > 2) throw new InvalidMarkupException("PX (Named popup links) can only have 2 arguments.", t); } else if (t.matches("JL")) { st.set("jumpDestination", "_" + t.get(1)); if (t.count() > 2) st.set("infobase", t.get(2)); if (t.count() > 3) throw new InvalidMarkupException("JL (Jump link) may only have 3 arguments." + t.text); } else if (t.matches("EN")) { st.set("query", t.get(1)); if (t.count() == 5) { st.set("popupWidth", t.get(2)); st.set("popupHeight", t.get(3)); st.set("title", t.get(4)); } else if (t.count() == 3) { st.set("title", t.get(2)); } else if (t.count() > 2) { throw new InvalidMarkupException("EN (End note link) may only have 2, 3, or 5 arguments" + t.text); } } else { throw new InvalidMarkupException("Link not supported: " + t.text); } return st; } return null; }  static boolean isOpeningLinkTag(FolioToken t); static boolean isClosingLinkTag(FolioToken t); static SlxToken translate(FolioToken t); static String translateToFolio(SlxToken t, CssClassCleaner css);  }