Projects >> zk >>b395d2353014cf46dcb788c629f8eb793ace02a2

Chunk
Conflicting content
package org.zkoss.zk.fn;

import org.zkoss.zk.ui.Executions;
<<<<<<< HEAD
=======
import org.zkoss.zk.ui.UiException;
import org.zkoss.zk.ui.util.Configuration;
import org.zkoss.zk.ui.util.ThemeProvider;
import org.zkoss.zk.ui.sys.PageCtrl;
import org.zkoss.zk.ui.sys.ExecutionsCtrl;
import org.zkoss.zk.ui.metainfo.LanguageDefinition;
import org.zkoss.zk.ui.http.WebManager;
import org.zkoss.zk.ui.http.ExecutionImpl;
import org.zkoss.zk.ui.impl.Attributes;
import org.zkoss.zk.au.AuResponse;
import org.zkoss.zk.device.Device;
import org.zkoss.zk.device.Devices;
>>>>>>> fdcb7f50da9c90bcecbad6f1db1a342f0b76bdc0

/**
 * Utilities for using XEL in ZUL.
Solution content
package org.zkoss.zk.fn;

import org.zkoss.zk.ui.Executions;

/**
 * Utilities for using XEL in ZUL.
File
ZkFns.java
Developer's decision
Version 1
Kind of conflict
Import
Chunk
Conflicting content
 *
 * @author tomyeh
 */
<<<<<<< HEAD
public class ZkFns {
	protected ZkFns() {}

=======
public class ZkFns extends DspFns {
	private static final Log log = Log.lookup(ZkFns.class);

	/** Denotes whether style sheets are generated for this request. */
	private static final String ATTR_LANG_CSS_GENED
		= "javax.zkoss.zk.lang.css.generated";
		//Naming with javax to be able to shared among portlets
	/** Denotes whether JavaScripts are generated for this request. */
	private static final String ATTR_LANG_JS_GENED
		= "javax.zkoss.zk.lang.js.generated";
		//Naming with javax to be able to shared among portlets
	/** Denotes whether JavaScripts are generated for this request. */
	private static final String ATTR_DESKTOP_INFO_GENED
		= "javax.zkoss.zk.desktopInfo.generated";
	/** Denotes whether the unavailable message is generated for this request. */
	private static final String ATTR_UNAVAILABLE_GENED
		= "javax.zkoss.zk.unavail.generated";

	protected ZkFns() {}

	/** Redraw the specified component into the specified out.
	 *
	 * @param comp the component. If null, nothing happens
	 * @param out the output. If null, the current output
	 * will be used.
	 */
	public static final void redraw(Component comp, Writer out)
	throws IOException {
		if (comp == null)
			return; //nothing to do
		if (out == null)
			out = getCurrentOut();
		try {
			comp.redraw(out);
		} catch (Throwable ex) {
			//Commons-el sometime eat exception, so show more info to debug
			log.realCauseBriefly("Failed to redraw "+comp, ex);
			if (ex instanceof IOException)
				throw (IOException)ex;
			throw UiException.Aide.wrap(ex);
		}
	}
	/** Returns the current writer to generate the output.
	 * @since 3.0.0
	 */
	public static final Writer getCurrentOut() throws IOException {
		return ServletFns.getCurrentOut();
	}

	/** Returns JavaScript for handling the specified response.
	 */
	public static final
	String outResponseJavaScripts(Collection responses) {
		if (responses == null || responses.isEmpty()) return "";

		final StringBuffer sb = new StringBuffer(256)
			.append("\n\n").toString();
	}

	/** Returns HTML tags to include all JavaScript files and codes that are
	 * required when loading a ZUML page.
	 *
	 * 

Note: it assumes {@link Executions#getCurrent} is available. * *

FUTURE CONSIDERATION: we might generate the inclusion on demand * instead of all at once. * * @param dummy ignored since 3.0.6 (reserved for backward compatibility) */ public static final String outLangJavaScripts(String dummy) { return outLangJavaScripts(Executions.getCurrent(), null, null); } private static final String outLangJavaScripts(Execution exec, WebApp wapp, String deviceType) { final ServletRequest request = ServletFns.getCurrentRequest(); if (WebManager.getRequestLocal(request, ATTR_LANG_JS_GENED) != null) return ""; //nothing to generate WebManager.setRequestLocal(request, ATTR_LANG_JS_GENED, Boolean.TRUE); if (wapp == null) wapp = exec.getDesktop().getWebApp(); if (deviceType == null) deviceType = exec.getDesktop().getDeviceType(); final Configuration config = wapp.getConfiguration(); final StringBuffer sb = new StringBuffer(1536); final Set jses = new LinkedHashSet(32); for (Iterator it = LanguageDefinition.getByDeviceType(deviceType).iterator(); it.hasNext();) jses.addAll(((LanguageDefinition)it.next()).getJavaScripts()); for (Iterator it = jses.iterator(); it.hasNext();) append(sb, (JavaScript)it.next()); sb.append("\n\n"); final Device device = Devices.getDevice(deviceType); final String s = device.getEmbedded(); if (s != null) sb.append(s).append('\n'); return sb.toString(); } /** Generates the unavailable message in HTML tags, if any. * @since 3.5.2 */ public static String outHtmlUnavailable(Page page) { final ServletRequest request = ServletFns.getCurrentRequest(); if (WebManager.getRequestLocal(request, ATTR_UNAVAILABLE_GENED) != null) return ""; //nothing to generate WebManager.setRequestLocal(request, ATTR_UNAVAILABLE_GENED, Boolean.TRUE); final Device device = page.getDesktop().getDevice(); String s = device.getUnavailableMessage(); return s != null ? "": ""; } private static void append(StringBuffer sb, JavaScript js) { sb.append("\n"); } /** Returns HTML tags to include all style sheets that are * defined in all languages. * *

Note: it assumes {@link Executions#getCurrent} is available. * *

In addition to style sheets defined in lang.xml and lang-addon.xml, * it also include: *

    *
  1. The style sheet specified in the theme-uri parameter.
  2. *
* *

FUTURE CONSIDERATION: we might generate the inclusion on demand * instead of all at once. */ public static final String outLangStyleSheets() { return outLangStyleSheets(Executions.getCurrent(), null, null); } private static final String outLangStyleSheets(Execution exec, WebApp wapp, String deviceType) { final ServletRequest request = ServletFns.getCurrentRequest(); if (WebManager.getRequestLocal(request, ATTR_LANG_CSS_GENED) != null) return ""; //nothing to generate WebManager.setRequestLocal(request, ATTR_LANG_CSS_GENED, Boolean.TRUE); final StringBuffer sb = new StringBuffer(512); for (Iterator it = getStyleSheets(exec, wapp, deviceType).iterator(); it.hasNext();) append(sb, (StyleSheet)it.next(), exec, null); if (sb.length() > 0) sb.append('\n'); return sb.toString(); } /** Returns HTML tags to include style sheets of the specified device * of the current application. * *

Unlike {@link #outLangStyleSheets}, it uses the current * servlet context * to look for the style sheets. Thus, this method can be used even * if the current execution is not available ({@link Executions#getCurrent} * can be null). * *

In summary:
* {@link #outLangStyleSheets} is used to design the component * templates, while {@link DspFns#outDeviceStyleSheets} is used by DSP/JSP * that does nothing with ZUML pages (i.e., not part of an execution). * * @param exec the execution (never null) * @param wapp the Web application. * If null, exec.getDesktop().getWebApp() is used. * So you have to specify it if the execution is not associated * with desktop (a fake execution). * @param deviceType the device type, such as ajax. * If null, exec.getDesktop().getDeviceType() is used. * So you have to specify it if the execution is not associated * with desktop (a fake execution). */ /*package*/ static final String outDeviceStyleSheets(Execution exec, WebApp wapp, String deviceType) { final ServletRequest request = ServletFns.getCurrentRequest(); if (WebManager.getRequestLocal(request, ATTR_LANG_CSS_GENED) != null) return ""; //nothing to generate WebManager.setRequestLocal(request, ATTR_LANG_CSS_GENED, Boolean.TRUE); final StringBuffer sb = new StringBuffer(256); final List ss = getStyleSheets(exec, wapp, deviceType); for (Iterator it = ss.iterator(); it.hasNext();) append(sb, (StyleSheet)it.next(), exec, null); return sb.toString(); } /** Returns a list of {@link StyleSheet} that shall be generated * to the client for the specified execution. */ public static final List getStyleSheets(Execution exec) { final Desktop desktop = exec.getDesktop(); return getStyleSheets(exec, null, null); } private static final List getStyleSheets(Execution exec, WebApp wapp, String deviceType) { if (wapp == null) wapp = exec.getDesktop().getWebApp(); if (deviceType == null) deviceType = exec.getDesktop().getDeviceType(); final Configuration config = wapp.getConfiguration(); final Set disabled = config.getDisabledThemeURIs(); final List sses = new LinkedList(); //a list of StyleSheet for (Iterator it = LanguageDefinition.getByDeviceType(deviceType).iterator(); it.hasNext();) { final LanguageDefinition langdef = (LanguageDefinition)it.next(); for (Iterator e = langdef.getStyleSheets().iterator(); e.hasNext();) { final StyleSheet ss = (StyleSheet)e.next(); if (!disabled.contains(ss.getHref())) sses.add(ss); } } //Process configuration final ThemeProvider themeProvider = config.getThemeProvider(); if (themeProvider != null) { final List org = new LinkedList(); for (Iterator it = sses.iterator(); it.hasNext();) { final StyleSheet ss = (StyleSheet)it.next(); org.add(ss.getHref()); //we don't support getContent } final String[] hrefs = config.getThemeURIs(); for (int j = 0; j < hrefs.length; ++j) org.add(hrefs[j]); sses.clear(); final Collection res = themeProvider.getThemeURIs(exec, org); if (res != null) { for (Iterator it = res.iterator(); it.hasNext();) sses.add(new StyleSheet((String)it.next(), "text/css")); } } else { final String[] hrefs = config.getThemeURIs(); for (int j = 0; j < hrefs.length; ++j) sses.add(new StyleSheet(hrefs[j], "text/css")); } return sses; } private static void append(StringBuffer sb, StyleSheet ss, Execution exec, Page page) { String href = ss.getHref(); if (href != null) { try { if (exec != null) href = (String)exec.evaluate(page, href, String.class); if (href != null && href.length() > 0) sb.append("\n"); } catch (javax.servlet.ServletException ex) { throw new UiException(ex); } } else { sb.append("\n\n").append(ss.getContent()).append("\n"); } } >>>>>>> fdcb7f50da9c90bcecbad6f1db1a342f0b76bdc0 /** Converts the specified URI to absolute if necessary. * Refer to {@link org.zkoss.zk.ui.Execution#toAbsoluteURI}. *

Solution content
 *
 * @author tomyeh
 */
public class ZkFns {
	protected ZkFns() {}

	/** Converts the specified URI to absolute if necessary.
	 * Refer to {@link org.zkoss.zk.ui.Execution#toAbsoluteURI}.
	 *
File
ZkFns.java
Developer's decision
Version 1
Kind of conflict
Attribute
Class signature
Comment
Method declaration
Method invocation
Chunk
Conflicting content
	//we preserve this method for backward compatibility (since some developers
	//might have old version core.dsp.tld
	}
<<<<<<< HEAD
=======

	/** Returns the content that will be placed inside the header element
	 * of the specified page.
	 * For HTML, the header element is the HEAD element.
	 */
	public static final String outHeaders(Page page) {
		return ((PageCtrl)page).getHeaders();
	}
	/** 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. * *

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 null 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(): ""; } >>>>>>> fdcb7f50da9c90bcecbad6f1db1a342f0b76bdc0 }

Solution content
	//we preserve this method for backward compatibility (since some developers
	//might have old version core.dsp.tld
	}
}
File
ZkFns.java
Developer's decision
Version 1
Kind of conflict
Comment
Method declaration
Chunk
Conflicting content
			final int j = indexOfHead(sb);
			if (j >= 0) {
				zktagGened = true;
<<<<<<< HEAD
				final String zktags =
					HtmlPageRenders.outZkTags(Executions.getCurrent(), null, null);
=======
				final String zktags = ZkFns.outZkHtmlTags();
>>>>>>> fdcb7f50da9c90bcecbad6f1db1a342f0b76bdc0
				if (zktags != null)
					sb.insert(j, zktags);
			}
Solution content
			final int j = indexOfHead(sb);
			if (j >= 0) {
				zktagGened = true;
				final String zktags =
					HtmlPageRenders.outZkTags(Executions.getCurrent(), null, null);
				if (zktags != null)
					sb.insert(j, zktags);
			}
File
HtmlNativeComponent.java
Developer's decision
Version 1
Kind of conflict
Method invocation
Variable
Chunk
Conflicting content
		String moldURI = (String)params.remove("moldURI");
		if (moldURI == null) moldURI = (String)params.remove("mold-uri"); //backward comaptible (2.4.x)
		if (!isEmpty(moldURI)) {
<<<<<<< HEAD
			throw new UnsupportedOperationException("moldURI not supported in 5.0. Use lang-addon.xml instead");
=======
			String moldnm = (String)params.remove("moldName");
			if (moldnm == null) moldnm = (String)params.remove("mold-name"); //backward comaptible (2.4.x)
			noEL("moldName", moldnm, pi);
			compdef.addMold(isEmpty(moldnm) ? "default": moldnm,
				moldURI.startsWith("class:") ? moldURI: toAbsoluteURI(moldURI, true),
				(String)params.remove("z2cURI"));
>>>>>>> fdcb7f50da9c90bcecbad6f1db1a342f0b76bdc0
		}

		for (Iterator e = params.entrySet().iterator(); e.hasNext();) {
Solution content
		String moldURI = (String)params.remove("moldURI");
		if (moldURI == null) moldURI = (String)params.remove("mold-uri"); //backward comaptible (2.4.x)
		if (!isEmpty(moldURI)) {
			throw new UnsupportedOperationException("moldURI not supported in 5.0. Use lang-addon.xml instead");
		}

		for (Iterator e = params.entrySet().iterator(); e.hasNext();) {
File
Parser.java
Developer's decision
Version 1
Kind of conflict
Cast expression
Comment
If statement
Method invocation
Throw statement
Variable
Chunk
Conflicting content
		s.defaultWriteObject();

		s.writeObject(_langdef != null ? _langdef.getName(): null);
<<<<<<< HEAD
=======

		//write _molds
		for (Iterator it = _molds.entrySet().iterator(); it.hasNext();) {
			final Map.Entry me = (Map.Entry)it.next();
			s.writeObject(me.getKey());
			final Object o = me.getValue();
			if ((o instanceof java.io.Serializable)
			|| (o instanceof java.io.Externalizable)) {
				s.writeObject(o);
			} else {
				assert o instanceof ComponentRenderer: "Unexpected "+o;
				s.writeObject(o.getClass());
			}
		}

		//Note: _z2cs is serializable
		s.writeObject(null);
>>>>>>> fdcb7f50da9c90bcecbad6f1db1a342f0b76bdc0
	}
	private synchronized void readObject(java.io.ObjectInputStream s)
	throws java.io.IOException, ClassNotFoundException {
Solution content
		s.defaultWriteObject();

		s.writeObject(_langdef != null ? _langdef.getName(): null);
	}
	private synchronized void readObject(java.io.ObjectInputStream s)
	throws java.io.IOException, ClassNotFoundException {
File
ComponentDefinitionImpl.java
Developer's decision
Version 1
Kind of conflict
Comment
For statement
Method invocation