File tree Expand file tree Collapse file tree
src/main/java/com/flowingcode/vaadin/addons/demo Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,14 +43,15 @@ private Tab[] createTabs(List<SourceCodeTab> sourceCodeTabs) {
4343 private Tab createTab (SourceCodeTab sourceCodeTab ) {
4444 String url = sourceCodeTab .getUrl ();
4545 String language = sourceCodeTab .getLanguage ();
46-
4746 String caption = sourceCodeTab .getCaption ();
47+
48+ String filename = getFilename (url );
4849 if (caption == null ) {
49- caption = url . replaceAll ( ".*/" , "" ) ;
50+ caption = filename ;
5051 }
5152
5253 if (language == null ) {
53- String ext = url . replaceAll ( ".* \\ ." , "" );
54+ String ext = getExtension ( filename );
5455 switch (ext ) {
5556 case "java" :
5657 language = "java" ;
@@ -76,6 +77,16 @@ private Tab createTab(SourceCodeTab sourceCodeTab) {
7677 return tab ;
7778 }
7879
80+ private String getFilename (String url ) {
81+ int i = url .lastIndexOf ('/' );
82+ return i >= 0 ? url .substring (i + 1 ) : url ;
83+ }
84+
85+ private String getExtension (String filename ) {
86+ int i = filename .lastIndexOf ('.' );
87+ return i >= 0 ? filename .substring (i + 1 ) : filename ;
88+ }
89+
7990 private void onTabSelected (Tab tab ) {
8091 String url = (String ) ComponentUtil .getData (tab , DATA_URL );
8192 String language = (String ) ComponentUtil .getData (tab , DATA_LANGUAGE );
You can’t perform that action at this time.
0 commit comments