/
StatusServletUtils.java
98 lines (84 loc) · 3.96 KB
/
StatusServletUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2019 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
package org.pentaho.di.www;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
public class StatusServletUtils {
public static final String RESOURCES_PATH = "/content/common-ui/resources/themes";
public static final String STATIC_PATH = "/static";
public static final String PENTAHO_ROOT = "/pentaho";
public static String getPentahoStyles( String root ) {
StringBuilder sb = new StringBuilder();
String themeName = "ruby"; // default pentaho theme
String themeCss = "globalRuby.css";
String mantleThemeCss = "mantleRuby.css";
try {
String relativePathSeparator = ".." + File.separator + ".." + File.separator;
// Read in currently set theme from pentaho.xml file
String themeSetting = relativePathSeparator
+ "pentaho-solutions" + File.separator + "system" + File.separator + "pentaho.xml";
File f = new File( themeSetting );
// Check if file exists (may be different location depending on how server was started)
if ( !f.exists() ) {
relativePathSeparator = ".." + File.separator;
}
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbFactory.newDocumentBuilder();
Document doc = db.parse( f );
themeName = doc.getElementsByTagName( "default-theme" ).item( 0 ).getTextContent();
// Get theme CSS file
String themeDirStr = relativePathSeparator
+ "pentaho-solutions" + File.separator + "system" + File.separator
+ "common-ui" + File.separator + "resources" + File.separator
+ "themes" + File.separator + themeName + File.separator;
File themeDir = new File( themeDirStr );
for ( File fName : themeDir.listFiles() ) {
if ( fName.getName().contains( ".css" ) ) {
themeCss = fName.getName();
break;
}
}
// webapps folder will always be one directory closer to default directory, need to update relative path string
relativePathSeparator = relativePathSeparator.replaceFirst( "(\\.\\.\\\\)", "" );
// Get mantle theme CSS file
String mantleThemeDirStr = relativePathSeparator + "webapps" + root + File.separator + "mantle" + File.separator
+ "themes" + File.separator + themeName + File.separator;
File mantleThemeDir = new File( mantleThemeDirStr );
for ( File fName : mantleThemeDir.listFiles() ) {
if ( fName.getName().contains( ".css" ) ) {
mantleThemeCss = fName.getName();
break;
}
}
} catch ( Exception ex ) {
// log here
}
sb.append( "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + root
+ "/content/common-ui/resources/themes/" + themeName + "/" + themeCss + "\"/>" );
sb.append( "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + root
+ "/mantle/themes/" + themeName + "/" + mantleThemeCss + "\"/>" );
sb.append( "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + root + "/mantle/MantleStyle.css\"/>" );
return sb.toString();
}
}