Package org.zkoss.zk.ui.util

Examples of org.zkoss.zk.ui.util.Configuration


  public void onClose(Event evt) {
    if (evt.getData() == null)
      _result.clear();
    else {
      final Desktop desktop = Executions.getCurrent().getDesktop();
      final Configuration config = desktop .getWebApp().getConfiguration();
      if (!config.isEventThreadEnabled())
        Events.postEvent(new UploadEvent(Events.ON_UPLOAD, (Component)desktop.getAttribute(ATTR_FILEUPLOAD_TARGET), getResult()));
    }
    detach();
  }
View Full Code Here


    Servlets.setBrowserIdentifier(new BrowserIdentifier());
      //plugin device-dependent browser identifier

    //load config as soon as possible since it might set some system props
    final Configuration config = new Configuration();
    final ConfigParser parser = new ConfigParser();

    //load metainfo/zk/config.xml
    try {
      parser.parseConfigXml(config);
    } catch (Throwable ex) {
      log.error("Unable to load metainfo/zk/config.xml", ex);
    }

    //load metainfo/zk/zk.xml
    try {
      final ClassLocator loc = new ClassLocator();
      for (Enumeration en = loc.getResources("metainfo/zk/zk.xml");
      en.hasMoreElements();) {
        final URL cfgUrl = (URL)en.nextElement();
        try {
          parser.parse(cfgUrl, config, loc);
        } catch (Throwable ex) {
          log.error("Unable to load "+cfgUrl, ex);
        }
      }
    } catch (Throwable ex) {
      log.error("Unable to load metainfo/zk/zk.xml", ex);
    }

    //load /WEB-INF/zk.xml
    try {
      final URL cfgUrl = _ctx.getResource("/WEB-INF/zk.xml");
      if (cfgUrl != null)
        parser.parse(cfgUrl, config, new ServletContextLocator(_ctx));
    } catch (Throwable ex) {
      log.error("Unable to load /WEB-INF/zk.xml", ex);
    }

    //after zk.xml is loaded since it depends on the configuration
    _cwr = ClassWebResource.getInstance(_ctx, _updateURI);
    _cwr.setCompress(new String[] {"js", "css", "html", "xml"});
    String s = Library.getProperty("org.zkoss.web.util.resource.dir");
    if (s != null && s.length() > 0) {
      if (s.charAt(0) != '/') s = '/' + s;
      _cwr.setExtraLocator(new ServletContextLocator(_ctx, null, s));
    }

    Labels.register(new ServletLabelLocator(_ctx));
    Labels.setVariableResolver(new ServletLabelResovler());

    //create a WebApp instance
    final Class cls = config.getWebAppClass();
    if (cls == null) {
      _wapp = new SimpleWebApp();
    } else {
      try {
        _wapp = (WebApp)cls.newInstance();
      } catch (Exception ex) {
        throw UiException.Aide.wrap(ex, "Unable to construct "+cls);
      }
    }
    ((WebAppCtrl)_wapp).init(_ctx, config);

    _cwr.setEncodeURLPrefix(getCWRURLPrefix());
    _cwr.setDebugJS(config.isDebugJS());
    _cwr.addExtendlet("wpd", new WpdExtendlet()); //add after _cwr.setDebugJS (since it calls back)
    _cwr.addExtendlet("wcs", new WcsExtendlet());

    //Register resource processors for each extension
    //FUTURE: Extendlet can be specified in zk.xml
View Full Code Here

    _qs = getQueryString(request);

    if (deviceType != null && deviceType.length() != 0)
      setDeviceType(deviceType);

    final Configuration config = _wapp.getConfiguration();
    _exec = exec; //fake
    try {
      final WebAppCtrl wappc = (WebAppCtrl)_wapp;
      final DesktopCache dc = _sess != null ? wappc.getDesktopCache(_sess): null;
        //_sess is null if in a working thread
      final IdGenerator idgen = wappc.getIdGenerator();
      if (idgen != null)
        _id = idgen.nextDesktopId(this);
      if (_id == null)
        _id = nextDesktopId(dc);
      else if (idgen != null)
        ComponentsCtrl.checkUuid(_id);
      updateUuidPrefix();

      config.invokeDesktopInits(this, request); //it might throw exception
      if (exec != null && exec.isVoided()) return; //sendredirect or forward

      if (dc != null)
        dc.addDesktop(this); //add to cache after invokeDesktopInits

      final Monitor monitor = config.getMonitor();
      if (monitor != null) {
        try {
          monitor.desktopCreated(this);
        } catch (Throwable ex) {
          log.error(ex);
View Full Code Here

      final Execution oldexec = Executions.getCurrent();
      final Execution exec = new ExecutionImpl(
        _ctx, request, response, desktop, null);
      uieng.activate(exec);

      final Configuration config = wapp.getConfiguration();
      boolean err = false;
      try {
        config.invokeExecutionInits(exec, oldexec);
        desktopCtrl.invokeExecutionInits(exec, oldexec);

        media = desktopCtrl.getDownloadMedia(uuid, false);
        if (media != null) {
          download = true; //yes, it is for download
        } else {
          final Component comp = desktop.getComponentByUuid(uuid);
          final Object cc = ((ComponentCtrl)comp).getExtraCtrl();
          if (!(cc instanceof DynamicMedia))
            throw new ServletException(DynamicMedia.class+" must be implemented by getExtraCtrl() of "+comp);
          media = ((DynamicMedia)cc).getMedia(l >= 0 ? pi.substring(l): "");
          if (media == null) {
            response.sendError(response.SC_GONE, Messages.get(MZk.PAGE_NOT_FOUND, pi+" - "+comp));
            return;
          }
        }
      } catch (Throwable ex) {
        err = true;

        final List errs = new LinkedList();
        errs.add(ex);
        desktopCtrl.invokeExecutionCleanups(exec, oldexec, errs);
        config.invokeExecutionCleanups(exec, oldexec, errs);

        final StringBuffer errmsg = new StringBuffer(100);
        if (!errs.isEmpty()) {
          for (Iterator it = errs.iterator(); it.hasNext();) {
            final Throwable t = (Throwable)it.next();
            log.realCauseBriefly("Failed to load media, "+pi, t);
            errmsg.append('\n').append(Exceptions.getMessage(t));
          }
        }

        response.sendError(response.SC_GONE,
          Messages.get(MZk.PAGE_FAILED, new Object[] {pi, errmsg, ""}));
        return;
      } finally {
        if (!err) {
          desktopCtrl.invokeExecutionCleanups(exec, oldexec, null);
          config.invokeExecutionCleanups(exec, oldexec, null);
        }
        uieng.deactivate(exec);
      }
    } catch (ComponentNotFoundException ex) {
      //possible because view might be as late as origin comp is gone
View Full Code Here

    final String sid = request.getHeader("ZK-SID");
    if (sid != null) //Some client might not have ZK-SID
      response.setHeader("ZK-SID", sid);

    //parse commands
    final Configuration config = wapp.getConfiguration();
    final List aureqs;
    boolean keepAlive = false;
    try {
      final boolean timerKeepAlive = config.isTimerKeepAlive();
      aureqs = audec.decode(request, desktop);
      for (Iterator it = aureqs.iterator(); it.hasNext();) {
        final String cmdId = ((AuRequest)it.next()).getCommand();
        keepAlive = !(!timerKeepAlive && Events.ON_TIMER.equals(cmdId))
          && !"dummy".equals(cmdId);
          //dummy is used for PollingServerPush for piggyback
        if (keepAlive)
          break; //done
      }
    } catch (Throwable ex) {
      log.warningBriefly(ex);
      responseError(request, response, Exceptions.getMessage(ex));
      return;
    }

    if (aureqs.isEmpty()) {
      final String errmsg = "Illegal request: cmd required";
      log.debug(errmsg);
      responseError(request, response, errmsg);
      return;
    }

    sess.setAttribute(Attributes.GAE_FIX, new Integer(0)); //enforce GAE to write session
    ((SessionCtrl)sess).notifyClientRequest(keepAlive);

//    if (log.debugable()) log.debug("AU request: "+aureqs);
    final DesktopCtrl desktopCtrl = (DesktopCtrl)desktop;
    final Execution exec =
      new ExecutionImpl(_ctx, request, response, desktop, null);
    if (sid != null)
      ((ExecutionCtrl)exec).setRequestId(sid);

    final AuWriter out = AuWriters.newInstance();
    out.setCompress(_compress);
    out.open(request, response,
      desktop.getDevice().isSupported(Device.RESEND) ?
        getProcessTimeout(config.getResendDelay()): 0);
        //Note: getResendDelay() might return nonpositive
    try {
      wappc.getUiEngine().execUpdate(exec, aureqs, out);
    } catch (RequestOutOfSequenceException ex) {
      log.warning(ex.getMessage());
View Full Code Here

          if (log.debugable()) log.debug("Unknown file format: "+ctype);
        }
      } else if (ctypelc.startsWith("text/")) {
        String charset = getCharset(ctype);
        if (charset == null) {
          final Configuration conf = desktop.getWebApp().getConfiguration();
          final CharsetFinder chfd = conf.getUploadCharsetFinder();
          if (chfd != null)
            charset = chfd.getCharset(ctype,
              fi.isInMemory() ?
                new ByteArrayInputStream(fi.get()):
                fi.getInputStream());
          if (charset == null)
            charset = conf.getUploadCharset();
        }
        return fi.isInMemory() ?
          new AMedia(name, null, ctype, fi.getString(charset)):
          new ReaderMedia(name, null, ctype, fi, charset);
      }
View Full Code Here

    final ZkFileItemFactory fty = new ZkFileItemFactory(desktop, request, key);
    final ServletFileUpload sfu = new ServletFileUpload(fty);

    sfu.setProgressListener(fty.new ProgressCallback());

    final Configuration conf = desktop.getWebApp().getConfiguration();
    int maxsz = conf.getMaxUploadSize();
    try {
      maxsz = Integer.parseInt(request.getParameter("maxsize"));
    } catch (NumberFormatException e) {}
   
    sfu.setSizeMax(maxsz >= 0 ? 1024L*maxsz: -1);
View Full Code Here

*/
public class WebflowWebAppInit implements org.zkoss.zk.ui.util.WebAppInit {
  private static String RESOLVER_CLASS = org.zkoss.spring.DelegatingVariableResolver.RESOLVER_CLASS;
  private static String WEBFLOW_RESOLVER = "org.zkoss.spring.init.WebflowVariableResolver";
  public void init(WebApp wapp) throws Exception {
    final Configuration conf = wapp.getConfiguration();
    String classes = Library.getProperty(RESOLVER_CLASS);
    if (classes == null) {
      Library.setProperty(RESOLVER_CLASS, WEBFLOW_RESOLVER);
    } else {
      Library.setProperty(RESOLVER_CLASS, classes + ","+ WEBFLOW_RESOLVER);
View Full Code Here

   
  private void setupZkFlowListeners() {
    if (_webApp == null) {
      final WebManager webman = WebManager.getWebManager(getServletContext());
      _webApp = webman.getWebApp();
      Configuration conf = _webApp.getConfiguration();
      try {
        conf.addListener(ZkFlowControllerListener.class);
        conf.addListener(ZkFlowResourceListener.class);
      } catch (Exception e) {
        //log and ignore
            if (logger.isDebugEnabled()) {
                logger.debug("Added ZK Spring Listeners Failed: " + e);
            }
View Full Code Here

    if (classes == null) {
      Library.setProperty(RESOLVER_CLASS, CORE_RESOLVER);
    } else {
      Library.setProperty(RESOLVER_CLASS, classes + ","+ CORE_RESOLVER);
    }
    final Configuration conf = wapp.getConfiguration();
    //If user does not give UiFactoryClass in zk.xml
    if (conf.getUiFactoryClass() == null) {
      //<disable-event-thread/>
      conf.enableEventThread(false);
      //<ui-factory-class>org.zkoss.spring.bean.ZkSpringUiFactory</ui-factory-class>
      try {
        ((WebAppCtrl) wapp).setUiFactory(new ZkSpringUiFactory());
      } catch (AbstractMethodError ex) {
        //ignore
View Full Code Here

TOP

Related Classes of org.zkoss.zk.ui.util.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.