diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/MultiSourceCodeViewer.java b/src/main/java/com/flowingcode/vaadin/addons/demo/MultiSourceCodeViewer.java index a3e6e5b..42f7330 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/demo/MultiSourceCodeViewer.java +++ b/src/main/java/com/flowingcode/vaadin/addons/demo/MultiSourceCodeViewer.java @@ -43,14 +43,15 @@ private Tab[] createTabs(List sourceCodeTabs) { private Tab createTab(SourceCodeTab sourceCodeTab) { String url = sourceCodeTab.getUrl(); String language = sourceCodeTab.getLanguage(); - String caption = sourceCodeTab.getCaption(); + + String filename = getFilename(url); if (caption == null) { - caption = url.replaceAll(".*/", ""); + caption = filename; } if (language == null) { - String ext = url.replaceAll(".*\\.", ""); + String ext = getExtension(filename); switch (ext) { case "java": language = "java"; @@ -76,6 +77,16 @@ private Tab createTab(SourceCodeTab sourceCodeTab) { return tab; } + private String getFilename(String url) { + int i = url.lastIndexOf('/'); + return i >= 0 ? url.substring(i + 1) : url; + } + + private String getExtension(String filename) { + int i = filename.lastIndexOf('.'); + return i >= 0 ? filename.substring(i + 1) : filename; + } + private void onTabSelected(Tab tab) { String url = (String) ComponentUtil.getData(tab, DATA_URL); String language = (String) ComponentUtil.getData(tab, DATA_LANGUAGE);