//we preserve this method for backward compatibility (since some developers
//might have old version core.dsp.tld
}
<<<<<<< HEAD
=======
/** Returns the content of the specified condition
* that will be placed inside the header element
* of the specified page.
* For HTML, the header element is the HEAD element.
* @param before whether to return the headers that shall be shown
* before ZK's CSS/JS headers.
* If true, only the headers that shall be shown before (such as meta)
* are returned.
* If true, only the headers that shall be shown after (such as link)
* are returned.
* @since 3.6.1
*/
public static final String outHeaders(Page page, boolean before) {
return ((PageCtrl)page).getHeaders(before);
}
/** @deprecated As of release 3.6.1, replaced with {@link #outHeaders(Page,boolean)}.
*/
public static final String outHeaders(Page page) {
return outHeaders(page, true) + outHeaders(page, false);
}
/** Returns the content that will be generated
* as the attributes of the root element of the specified page.
* For HTML, the root element is the HTML element.
*/
public static final String outRootAttributes(Page page) {
return ((PageCtrl)page).getRootAttributes();
}
/** Returns the content type (never null).
* @since 3.0.0
*/
public static final String outContentType(Page page) {
String contentType = ((PageCtrl)page).getContentType();
if (contentType == null) {
contentType = page.getDesktop().getDevice().getContentType();
if (contentType == null) contentType = "";
}
final int j = contentType.indexOf(';');
if (j < 0) {
final String cs = page.getDesktop().getWebApp()
.getConfiguration().getResponseCharset();
if (cs != null && cs.length() > 0)
contentType += ";charset=" + cs;
}
return contentType;
}
/** Returns the doc type, or null if not available.
* It is null or <!DOCTYPE ...>.
* @since 3.0.0
*/
public static final String outDocType(Page page) {
final String docType = ((PageCtrl)page).getDocType();
return trimAndLF(docType != null ?
docType: page.getDesktop().getDevice().getDocType());
}
/** Trims and appends a linefeed if necessary.
*/
private static final String trimAndLF(String s) {
if (s != null) {
s = s.trim();
final int len = s.length();
if (len > 0 && s.charAt(len-1) != '\n')
s += '\n';
}
return s;
}
/** Returns the first line to be generated to the output,
* or null if no special first line.
*/
public static final String outFirstLine(Page page) {
return trimAndLF(((PageCtrl)page).getFirstLine());
}
/** Returns the attributes to render a page.
* Used only in HTML devices.
* @since 3.0.6
*/
public static final String outPageAttrs(Page page) {
final Desktop desktop = page.getDesktop();
final PageCtrl pageCtrl = (PageCtrl)page;
final Component owner = pageCtrl.getOwner();
boolean contained = false; //included by non-ZK servlet
if (owner == null) {
//Bug 2001707: Don't use exec.isIncluded() though
//exec.getNativeRequest reutrns the original request
//(while ServletFns.getCurrentRequest returns the 'real' one
//-- for page.dsp, it is different due to being included).
//WebLogic's request.getAttribute (which Servlets.include
//depends on) returns the same set of attributes for both
// the 'real' request and the original request.
final Execution exec = Executions.getCurrent();
contained = exec != null
&& exec.getAttribute("org.zkoss.zk.ui.page.included") != null;
}
final ServletRequest request = ServletFns.getCurrentRequest();
WebManager.setRequestLocal(request, ATTR_DESKTOP_INFO_GENED, Boolean.TRUE);
//prepare style
String style = page.getStyle();
if (style == null || style.length() == 0) {
String wd = null, hgh = null;
if (owner instanceof HtmlBasedComponent) {
final HtmlBasedComponent hbc = (HtmlBasedComponent)owner;
wd = hbc.getWidth(); //null if not set
hgh = hbc.getHeight(); //null if not set
}
final StringBuffer sb = new StringBuffer(32);
HTMLs.appendStyle(sb, "width", wd != null ? wd: "100%");
HTMLs.appendStyle(sb, "height",
hgh != null ? hgh: contained ? null: "100%");
style = sb.toString();
}
final StringBuffer sb = new StringBuffer(100)
.append(" class=\"zk\"");
HTMLs.appendAttribute(sb, "id", page.getUuid());
HTMLs.appendAttribute(sb, "z.dtid", desktop.getId());
HTMLs.appendAttribute(sb, "style", style);
HTMLs.appendAttribute(sb, "z.zidsp", contained ? "ctpage": "page");
if (owner == null)
HTMLs.appendAttribute(sb, "z.au", desktop.getUpdateURI(null));
return sb.toString();
}
/** Returns the desktop info to render a desktop.
* It must be called if {@link #outPageAttrs} might not be called.
* On the other hand, {@link #outDesktopInfo} does nothing if
* {@link #outPageAttrs} was called.
*
* It is OK to call both {@link #outPageAttrs}
* and {@link #outDesktopInfo}.
* @since 3.5.0.
*/
public static final String outDesktopInfo(Desktop desktop) {
final ServletRequest request = ServletFns.getCurrentRequest();
if (WebManager.getRequestLocal(request, ATTR_DESKTOP_INFO_GENED) != null)
return ""; //nothing to generate
WebManager.setRequestLocal(request, ATTR_DESKTOP_INFO_GENED, Boolean.TRUE);
return "\n";
}
/** Generates and returns the ZK specific HTML tags for
* a desktop (never null).
*
* For each desktop, we have to generate a set of HTML tags
* to load ZK Client engine, style sheets and so on.
* For ZUL pages, it is generated automatically by page.dsp.
* However, for ZHTML pages, we have to generate these tags
* with special component such as org.zkoss.zhtml.Head, such that
* the result HTML page is legal.
*
* @return the string holding the HTML tags, or an empty string if already generated.
* @since 3.5.0
*/
public static String outZkHtmlTags() {
final Execution exec = Executions.getCurrent();
return exec != null ? outZkHtmlTags(exec, null, null): "";
}
/*package*/ static final
String outZkHtmlTags(Execution exec, WebApp wapp, String deviceType) {
final ServletRequest request = ServletFns.getCurrentRequest();
if (WebManager.getRequestLocal(request, "zkHtmlTagsGened") != null)
return null;
WebManager.setRequestLocal(request, "zkHtmlTagsGened", Boolean.TRUE);
final StringBuffer sb = new StringBuffer(512).append('\n')
.append(outLangStyleSheets(exec, wapp, deviceType))
.append(outLangJavaScripts(exec, wapp, deviceType));
final Desktop desktop = exec.getDesktop();
if (desktop != null)
sb.append(outDesktopInfo(desktop));
final String ATTR_RESPONSES = "zk_argResponses";
sb.append(outResponseJavaScripts(
(Collection)exec.getAttribute(ATTR_RESPONSES)));
exec.removeAttribute(ATTR_RESPONSES);
return sb.toString();
}
/**
* Removes the class and style attributes from the specified one.
*
* For example, if attrs is href="a" class="c",
* then the output will be href="a"
*
* @param attrs the attributes to filter
* @since 3.5.0
*/
public static final String noCSSAttrs(String attrs) {
if (attrs == null || attrs.length() == 0) return attrs;
final String CSS = "class=\"";
final String STYLE = "style=\"";
StringBuffer sb = null;
int start = attrs.indexOf(CSS);
if (start >= 0) {
sb = new StringBuffer(attrs);
int end = sb.indexOf("\"", start + CSS.length());
if (end >= 0)
sb.delete(start, end + 1);
start = sb.indexOf(STYLE);
} else {
start = attrs.indexOf(STYLE);
}
if (start >= 0) {
if (sb == null) sb = new StringBuffer(attrs);
int end = sb.indexOf("\"", start + STYLE.length());
if (end >= 0)
sb.delete(start, end + 1);
}
return sb != null ? sb.toString(): attrs;
}
/** Returns only the class and style attributes of the specified one.
*
* For example, if attrs is href="a" class="c",
* then the output will be class="c"
*
* @param attrs the attributes to filter
* @since 3.5.0
*/
public static final String outCSSAttrs(String attrs) {
if (attrs == null || attrs.length() == 0) return attrs;
final String CSS = "class=\"";
final String STYLE = "style=\"";
StringBuffer sb = null;
int start = attrs.indexOf(CSS);
if (start >= 0) {
int end = attrs.indexOf("\"", start + CSS.length());
if (end >= 0)
sb = new StringBuffer().append(' ')
.append(attrs.substring(start, end + 1));
}
start = attrs.indexOf(STYLE);
if (start >= 0) {
int end = attrs.indexOf("\"", start + STYLE.length());
if (end >= 0) {
if (sb == null) sb = new StringBuffer();
sb.append(' ').append(attrs.substring(start, end + 1));
}
}
return sb != null ? sb.toString(): "";
}
>>>>>>> b0aa70a0b7812860ccfa61c5b016192d718c682e
} |