cmsjsploader.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,284 行 · 第 1/4 页
JAVA
1,284 行
* @param updatedFiles a set of already updated jsp files
* @return the parsed JSP content
*/
private String parseJspCmsTag(String content, CmsFlexController controller, Set updatedFiles) {
// check if a JSP directive occurs in the file
int i1 = content.indexOf(DIRECTIVE_START);
if (i1 < 0) {
// no directive occurs
return content;
}
StringBuffer buf = new StringBuffer(content.length());
int p0 = 0, i2 = 0, slen = DIRECTIVE_START.length(), elen = DIRECTIVE_END.length();
while (i1 >= 0) {
// parse the file and replace JSP filename references
i2 = content.indexOf(DIRECTIVE_END, i1 + slen);
if (i2 < 0) {
// wrong syntax (missing end directive) - let the JSP compiler produce the error message
return content;
} else if (i2 > i1) {
String directive = content.substring(i1 + slen, i2);
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_DIRECTIVE_DETECTED_3,
DIRECTIVE_START,
directive,
DIRECTIVE_END));
}
int t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0;
while (directive.charAt(t1) == ' ') {
t1++;
}
String argument = null;
if (directive.startsWith("cms", t1)) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_X_DIRECTIVE_DETECTED_1, "cms"));
}
t2 = directive.indexOf("file", t1 + 3);
t5 = 4;
}
if (t2 > 0) {
String sub = directive.substring(t2 + t5);
char c1 = sub.charAt(t3);
while ((c1 == ' ') || (c1 == '=') || (c1 == '"')) {
c1 = sub.charAt(++t3);
}
t4 = t3;
while (c1 != '"') {
c1 = sub.charAt(++t4);
}
if (t4 > t3) {
argument = sub.substring(t3, t4);
}
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_DIRECTIVE_ARG_1, argument));
}
}
if (argument != null) {
// try to update the referenced file
String jspname = updateJsp(argument, controller, updatedFiles);
if (jspname != null) {
directive = jspname;
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_DIRECTIVE_CHANGED_3,
DIRECTIVE_START,
directive,
DIRECTIVE_END));
}
}
// cms directive was found
buf.append(content.substring(p0, i1));
buf.append(directive);
p0 = i2 + elen;
i1 = content.indexOf(DIRECTIVE_START, p0);
} else {
// cms directive was not found
buf.append(content.substring(p0, i1 + slen));
buf.append(directive);
p0 = i2;
i1 = content.indexOf(DIRECTIVE_START, p0);
}
}
}
if (i2 > 0) {
// the content of the JSP was changed
buf.append(content.substring(p0, content.length()));
content = buf.toString();
}
return content;
}
/**
* Parses the JSP content for the <code><%page pageEncoding="..." %></code> tag
* and ensures that the JSP page encoding is set according to the OpenCms
* "content-encoding" property value of the JSP.<p>
*
* @param content the JSP content to parse
* @param encoding the encoding to use for the JSP
* @param isHardInclude indicated if this page is actually a "hard" include with <code><%@ include file="..." ></code>
* @return the parsed JSP content
*/
private String parseJspEncoding(String content, String encoding, boolean isHardInclude) {
// check if a JSP directive occurs in the file
int i1 = content.indexOf(DIRECTIVE_START);
if (i1 < 0) {
// no directive occurs
if (isHardInclude) {
return content;
}
}
StringBuffer buf = new StringBuffer(content.length() + 64);
int p0 = 0, i2 = 0, slen = DIRECTIVE_START.length();
boolean found = false;
if (i1 < 0) {
// no directive found at all, append content to buffer
buf.append(content);
}
while (i1 >= 0) {
// parse the file and set/replace page encoding
i2 = content.indexOf(DIRECTIVE_END, i1 + slen);
if (i2 < 0) {
// wrong syntax (missing end directive) - let the JSP compiler produce the error message
return content;
} else if (i2 > i1) {
String directive = content.substring(i1 + slen, i2);
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_DIRECTIVE_DETECTED_3,
DIRECTIVE_START,
directive,
DIRECTIVE_END));
}
int t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0;
while (directive.charAt(t1) == ' ') {
t1++;
}
String argument = null;
if (directive.startsWith("page", t1)) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_X_DIRECTIVE_DETECTED_1, "page"));
}
t2 = directive.indexOf("pageEncoding", t1 + 4);
t5 = 12;
if (t2 > 0) {
found = true;
}
}
if (t2 > 0) {
String sub = directive.substring(t2 + t5);
char c1 = sub.charAt(t3);
while ((c1 == ' ') || (c1 == '=') || (c1 == '"')) {
c1 = sub.charAt(++t3);
}
t4 = t3;
while (c1 != '"') {
c1 = sub.charAt(++t4);
}
if (t4 > t3) {
argument = sub.substring(t3, t4);
}
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_DIRECTIVE_ARG_1, argument));
}
}
if (argument != null) {
// a pageEncoding setting was found, changes have to be made
String pre = directive.substring(0, t2 + t3 + t5);
String suf = directive.substring(t2 + t3 + t5 + argument.length());
// change the encoding
directive = pre + encoding + suf;
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_DIRECTIVE_CHANGED_3,
DIRECTIVE_START,
directive,
DIRECTIVE_END));
}
}
buf.append(content.substring(p0, i1 + slen));
buf.append(directive);
p0 = i2;
i1 = content.indexOf(DIRECTIVE_START, p0);
}
}
if (i2 > 0) {
// the content of the JSP was changed
buf.append(content.substring(p0, content.length()));
}
if (found) {
content = buf.toString();
} else if (!isHardInclude) {
// encoding setting was not found
// if this is not a "hard" include then add the encoding to the top of the page
// checking for the hard include is important to prevent errors with
// multiple page encoding settings if a templete is composed from several hard included elements
// this is an issue in Tomcat 4.x but not 5.x
StringBuffer buf2 = new StringBuffer(buf.length() + 32);
buf2.append("<%@ page pageEncoding=\"");
buf2.append(encoding);
buf2.append("\" %>");
buf2.append(buf);
content = buf2.toString();
}
return content;
}
/**
* Parses the JSP content for includes and replaces all OpenCms VFS
* path information with information for the real FS.<p>
*
* @param content the JSP content to parse
* @param controller the current JSP controller
* @param updatedFiles a set of already updated files
* @return the parsed JSP content
*/
private String parseJspIncludes(String content, CmsFlexController controller, Set updatedFiles) {
// check if a JSP directive occurs in the file
int i1 = content.indexOf(DIRECTIVE_START);
if (i1 < 0) {
// no directive occurs
return content;
}
StringBuffer buf = new StringBuffer(content.length());
int p0 = 0, i2 = 0, slen = DIRECTIVE_START.length();
while (i1 >= 0) {
// parse the file and replace JSP filename references
i2 = content.indexOf(DIRECTIVE_END, i1 + slen);
if (i2 < 0) {
// wrong syntax (missing end directive) - let the JSP compiler produce the error message
return content;
} else if (i2 > i1) {
String directive = content.substring(i1 + slen, i2);
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_DIRECTIVE_DETECTED_3,
DIRECTIVE_START,
directive,
DIRECTIVE_END));
}
int t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0;
while (directive.charAt(t1) == ' ') {
t1++;
}
String argument = null;
if (directive.startsWith("include", t1)) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_X_DIRECTIVE_DETECTED_1, "include"));
}
t2 = directive.indexOf("file", t1 + 7);
t5 = 6;
} else if (directive.startsWith("page", t1)) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_X_DIRECTIVE_DETECTED_1, "page"));
}
t2 = directive.indexOf("errorPage", t1 + 4);
t5 = 11;
}
if (t2 > 0) {
String sub = directive.substring(t2 + t5);
char c1 = sub.charAt(t3);
while ((c1 == ' ') || (c1 == '=') || (c1 == '"')) {
c1 = sub.charAt(++t3);
}
t4 = t3;
while (c1 != '"') {
c1 = sub.charAt(++t4);
}
if (t4 > t3) {
argument = sub.substring(t3, t4);
}
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_DIRECTIVE_ARG_1, argument));
}
}
if (argument != null) {
// a file was found, changes have to be made
String pre = directive.substring(0, t2 + t3 + t5);
String suf = directive.substring(t2 + t3 + t5 + argument.length());
// now try to update the referenced file
String jspname = updateJsp(argument, controller, updatedFiles);
if (jspname != null) {
// only change something in case no error had occured
directive = pre + jspname + suf;
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_DIRECTIVE_CHANGED_3,
DIRECTIVE_START,
directive,
DIRECTIVE_END));
}
}
}
buf.append(content.substring(p0, i1 + slen));
buf.append(directive);
p0 = i2;
i1 = content.indexOf(DIRECTIVE_START, p0);
}
}
if (i2 > 0) {
// the content of the JSP was changed
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?