Console: Move readme files to war

This commit is contained in:
zzz
2020-12-22 09:50:02 -05:00
parent 387e513949
commit e20a19c358
23 changed files with 93 additions and 29 deletions

View File

@@ -140,7 +140,7 @@
<copy file="src/edu/internet2/ndt/locale/Tcpbw100_msgs_nl_NL.properties" tofile="build/obj/edu/internet2/ndt/locale/Tcpbw100_msgs_nl.properties" />
<copy file="src/edu/internet2/ndt/locale/Tcpbw100_msgs_pt_BR.properties" tofile="build/obj/edu/internet2/ndt/locale/Tcpbw100_msgs_pt.properties" />
<copy file="src/edu/internet2/ndt/locale/Tcpbw100_msgs_ru_RU.properties" tofile="build/obj/edu/internet2/ndt/locale/Tcpbw100_msgs_ru.properties" />
<jar destfile="./build/routerconsole.jar" basedir="./build/obj" excludes="net/i2p/router/web/helpers/* net/i2p/router/web/servlets/*">
<jar destfile="./build/routerconsole.jar" basedir="./build/obj" excludes="net/i2p/router/web/helpers/**/* net/i2p/router/web/servlets/**/* net/i2p/router/web/resources/**/*">
<manifest>
<!-- DTG added in 0.8.4, not in the classpath for very old installs, before we changed wrapper.config to specify * -->
<!-- very old installs don't have i2psnark,jstl,standard in the classpath... not added in WebAppConfiguration any more -->
@@ -338,10 +338,13 @@
<target name="war" depends="precompilejsp, warUpToDate, listChangedFiles2" unless="war.uptodate" >
<!-- set if unset -->
<property name="workspace.changes.w.tr" value="" />
<!-- Don't include the css in the war, the main build.xml will copy it to docs/themes/console/ -->
<copy file="../jsp/themes/console/images/favicon.ico" tofile="../jsp/favicon.ico" />
<mkdir dir="build/obj/net/i2p/router/web/resources" />
<copy todir="build/obj/net/i2p/router/web/resources" >
<fileset dir="../resources" />
</copy>
<war destfile="build/routerconsole.war" webxml="../jsp/web-out.xml"
basedir="../jsp/" excludes="web.xml, *.css, **/*.java, *.jsp, *.jsi, web-fragment.xml, web-out.xml">
basedir="../jsp/" excludes="web.xml, **/*.java, *.jsp, *.jsi, web-fragment.xml, web-out.xml">
<manifest>
<attribute name="Implementation-Version" value="${full.version}" />
<attribute name="Built-By" value="${build.built-by}" />
@@ -351,7 +354,7 @@
<attribute name="X-Compile-Source-JDK" value="${javac.version}" />
<attribute name="X-Compile-Target-JDK" value="${javac.version}" />
</manifest>
<classes dir="./build/obj" includes="net/i2p/router/web/helpers/* net/i2p/router/web/servlets/*" />
<classes dir="./build/obj" includes="net/i2p/router/web/helpers/* net/i2p/router/web/servlets/* net/i2p/router/web/resources/**/*" />
</war>
<delete file="../jsp/favicon.ico" />
</target>

View File

@@ -1,6 +1,10 @@
package net.i2p.router.web;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Locale;
import net.i2p.util.FileUtil;
@@ -12,12 +16,16 @@ public class ContentHelper extends HelperBase {
private String _lang;
/**
* Caution, use absolute paths only, do not assume files are in CWD
* Caution, use absolute paths only for getContent() and getTextContent(),
* do not assume files are in CWD.
* Use relative path for getResource().
*/
public void setPage(String page) { _page = page; }
public void setStartAtBeginning(String moo) {
_startAtBeginning = Boolean.parseBoolean(moo);
}
public void setLang(String l) {
/*****
if((_lang == null || !_lang.equals(l)) && (l != null)) {
@@ -106,4 +114,61 @@ public class ContentHelper extends HelperBase {
return newname;
return _page;
}
/**
* Convert file.ext to file_lang.ext if it exists.
* Get lang from the cgi lang param, then properties, then from the default locale.
* _context must be set to check the property.
* @return "" on error
* @since 0.9.49
*/
public String getResource() {
if (_page == null || _page.contains(".."))
return "";
String lang = _lang;
String page = null;
int lastdot = _page.lastIndexOf('.');
if (lastdot <= 0) {
page = _page;
} else {
if (lang == null || lang.length() <= 0) {
if (_context != null)
lang = _context.getProperty(Messages.PROP_LANG);
if (lang == null || lang.length() <= 0) {
lang = Locale.getDefault().getLanguage();
if (lang == null || lang.length() <= 0)
page = _page;
}
}
}
if (page == null) {
if (lang.equals("en"))
page = _page;
else
page = _page.substring(0, lastdot) + '_' + lang + _page.substring(lastdot);
}
InputStream is = ContentHelper.class.getResourceAsStream("/net/i2p/router/web/resources/" + page);
if (is == null) {
is = ContentHelper.class.getResourceAsStream("/net/i2p/router/web/resources/" + _page);
if (is == null)
return "";
}
BufferedReader in = null;
StringBuilder buf = new StringBuilder(20000);
try {
in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String line = null;
int i = 0;
while ( (line = in.readLine()) != null) {
buf.append(line);
if (_maxLines > 0 && ++i >= _maxLines)
break;
}
} catch (IOException ioe) {
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
try { is.close(); } catch (IOException ioe) {}
}
return buf.toString();
}
}