Search in sources :

Example 61 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class AbstractExtension method getActionExtensionSecurityCallback.

/**
 * returns the defined securityCallback, if none was defined a default SecurityCallback is returned
 */
public ActionExtensionSecurityCallback getActionExtensionSecurityCallback() {
    ActionExtensionSecurityCallback securityCallback = null;
    if (secCallbackName != null) {
        // try to lazy instantiate the callback Object
        Class<?> cclazz;
        Exception re = null;
        try {
            cclazz = Thread.currentThread().getContextClassLoader().loadClass(secCallbackName);
            Object o = cclazz.newInstance();
            securityCallback = (ActionExtensionSecurityCallback) o;
        } catch (ClassNotFoundException e) {
            re = e;
        } catch (SecurityException e) {
            re = e;
        } catch (IllegalArgumentException e) {
            re = e;
        } catch (InstantiationException e) {
            re = e;
        } catch (IllegalAccessException e) {
            re = e;
        } finally {
            if (re != null) {
                throw new AssertException("Could not create ActionExtensionSecurityCallback via reflection. classname: " + secCallbackName, re);
            }
        }
    } else {
        // load a default callback
        ActionExtensionSecurityCallback aescDefault = new ActionExtensionSecurityCallback() {

            @Override
            public boolean isAllowedToLaunchActionController(UserRequest ureq) {
                return true;
            }
        };
        securityCallback = aescDefault;
    }
    return securityCallback;
}
Also used : AssertException(org.olat.core.logging.AssertException) ActionExtensionSecurityCallback(org.olat.core.extensions.action.ActionExtensionSecurityCallback) AssertException(org.olat.core.logging.AssertException) UserRequest(org.olat.core.gui.UserRequest)

Example 62 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class Form method create.

/**
 * create a new form, where the caller is attached as component listener.
 * Caller receives form validation success or failure events.
 *
 * @param name
 * @param translator
 * @param rootFormContainer if null the default layout is choosen, otherwise
 *          the given layouting container is taken.
 * @param listener the component listener of this form, typically the caller
 * @return
 */
public static Form create(String id, String name, FormItemContainer formLayout, Controller listener) {
    Form form = new Form();
    // this is where the formitems go to
    form.formLayout = formLayout;
    form.formLayout.setRootForm(form);
    form.formListeners = new ArrayList<FormBasicController>(1);
    if (listener instanceof FormBasicController) {
        form.formListeners.add((FormBasicController) listener);
    }
    Translator translator = formLayout.getTranslator();
    if (translator == null) {
        throw new AssertException("please provide a translator in the FormItemContainer <" + formLayout.getName() + ">");
    }
    // renders header + <formLayout> + footer of html form
    form.formWrapperComponent = new FormWrapperContainer(id, name, translator, form);
    form.formWrapperComponent.addListener(listener);
    // form.formWrapperComponent.put(formLayout.getComponent().getComponentName(), formLayout.getComponent());
    // generate name for form and dispatch uri hidden field
    form.formName = Form.FORMID + form.formWrapperComponent.getDispatchID();
    form.dispatchFieldId = form.formName + "_dispatchuri";
    form.eventFieldId = form.formName + "_eventval";
    return form;
}
Also used : AssertException(org.olat.core.logging.AssertException) Translator(org.olat.core.gui.translator.Translator)

Example 63 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class Form method evalFormRequest.

/**
 * @param ureq
 */
public void evalFormRequest(UserRequest ureq) {
    // Initialize temporary request parameters
    if (isMultipartEnabled() && isMultipartContent(ureq.getHttpReq())) {
        doInitRequestMultipartDataParameter(ureq);
    } else {
        doInitRequestParameter(ureq);
    }
    String dispatchUri = getRequestParameter("dispatchuri");
    String dispatchAction = getRequestParameter("dispatchevent");
    boolean invalidDispatchUri = dispatchUri == null || dispatchUri.equals(FORM_UNDEFINED);
    boolean invalidDispatchAct = dispatchAction == null || dispatchAction.equals(FORM_UNDEFINED);
    // see also OLAT-3141
    boolean implicitFormSubmit = false;
    if (invalidDispatchAct && invalidDispatchUri) {
        // case if:
        // enter was pressed in Safari / IE
        // crawler tries form links
        SubmitFormComponentVisitor efcv = new SubmitFormComponentVisitor();
        new FormComponentTraverser(efcv, formLayout, false).visitAll(ureq);
        Submit submitFormItem = efcv.getSubmit();
        if (submitFormItem != null) {
            // if we have submit form item
            // assume a click on this item
            dispatchUri = FormBaseComponentIdProvider.DISPPREFIX + submitFormItem.getComponent().getDispatchID();
            action = FormEvent.ONCLICK;
        } else {
            // instead of
            // throw new AssertException("You have an input field but no submit item defined! this is no good if enter is pressed.");
            // assume a desired implicit form submit
            // see also OLAT-3141
            implicitFormSubmit = true;
        }
    } else {
        try {
            action = Integer.valueOf(dispatchAction);
        } catch (Exception e) {
            throw new InvalidRequestParameterException();
        }
    }
    hasAlreadyFired = false;
    isValidAndSubmitted = false;
    // 
    // step 1: call evalFormRequest(ureq) on each FormComponent this gives
    // ....... for each element the possibility to intermediate save a value.
    // ....... As a sideeffect the formcomponent to be dispatched is found.
    EvaluatingFormComponentVisitor efcv = new EvaluatingFormComponentVisitor(dispatchUri);
    FormComponentTraverser ct = new FormComponentTraverser(efcv, formLayout, false);
    ct.visitAll(ureq);
    // step 2: dispatch to the form component
    // ......... only one component to be dispatched can be found, e.g. clicked
    // ......... element....................................................
    // ......... dispatch changes server model -> rerendered
    // ......... dispatch may also request a form validation by
    // ......... calling the submit
    FormItem dispatchFormItem = efcv.getDispatchToComponent();
    // .......... the code goes further with step 3.........................
    if (implicitFormSubmit) {
        // implicit Submit (Press Enter without on a Field without submit item.)
        // see also OLAT-3141
        submit(ureq);
    } else {
        if (dispatchFormItem == null) {
            // source not found. This "never happens". Try to produce some hints.
            String fbc = new String();
            for (FormBasicController i : formListeners) {
                if (fbc.length() > 0) {
                    fbc += ",";
                }
                fbc += (i.getClass().getName());
            }
            log.warn("OLAT-5061: Could not determine request source in FlexiForm >" + formName + "<. Check >" + fbc + "<", null);
            // TODO: what now?
            // Assuming the same as "implicitFormSubmit" for now.
            submit(ureq);
        } else {
            // ****************************************
            // explicit Submit or valid form dispatch *
            // ****************************************
            dispatchFormItem.doDispatchFormRequest(ureq);
            // step 3: find parent container of dispatched component
            // .......... check dependency rules
            // .......... apply dependency rules
            FindParentFormComponentVisitor fpfcv = new FindParentFormComponentVisitor(dispatchFormItem);
            ct = new FormComponentTraverser(fpfcv, formLayout, false);
            ct.visitAll(ureq);
            fpfcv.getParent().evalDependencyRuleSetFor(ureq, dispatchFormItem);
        }
    }
    // 
    action = -1;
    // End of request dispatch: cleanup temp files: ureq requestParams and multipart files
    doClearRequestParameterAndMultipartData();
}
Also used : FormComponentTraverser(org.olat.core.util.component.FormComponentTraverser) FormItem(org.olat.core.gui.components.form.flexible.FormItem) Submit(org.olat.core.gui.components.form.flexible.elements.Submit) AssertException(org.olat.core.logging.AssertException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 64 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class SimpleStackedPanel method popContent.

@Override
public void popContent() {
    int stackHeight = stackList.size();
    if (stackHeight < 1)
        throw new AssertException("stack was empty!");
    if (curContent == null)
        throw new AssertException("stackHeight not zero, but curContent was null!");
    // remove the top component
    stackList.remove(stackHeight - 1);
    if (stackHeight == 1) {
        // after pop, the content is null
        curContent = null;
    } else {
        // stackHeight > 1
        curContent = stackList.get(stackHeight - 2);
    }
    setDirty(true);
}
Also used : AssertException(org.olat.core.logging.AssertException)

Example 65 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class HtmlStaticPageComponent method setCurrentURI.

/**
 * Sets the start html page, may be null
 *
 * @param currentURI The currentURI to set
 */
public void setCurrentURI(String currentURI) {
    if (!isFileTypeSupported(currentURI)) {
        throw new AssertException("can only accept files which are inline renderable(.html, .htm, .txt), but given filename is:" + currentURI);
    }
    this.currentURI = currentURI;
    setDirty(true);
    VFSItem sourceItem = null;
    if (rootContainer != null)
        sourceItem = rootContainer.resolve(currentURI);
    if (sourceItem == null || (sourceItem instanceof VFSContainer)) {
        jsOnLoad = null;
        htmlHead = null;
        htmlContent = "File not found: " + currentURI;
        return;
    }
    getFileContent((VFSLeaf) sourceItem);
}
Also used : AssertException(org.olat.core.logging.AssertException) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

AssertException (org.olat.core.logging.AssertException)364 IOException (java.io.IOException)38 File (java.io.File)28 Identity (org.olat.core.id.Identity)28 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)24 Controller (org.olat.core.gui.control.Controller)22 OLATResourceable (org.olat.core.id.OLATResourceable)22 RepositoryEntry (org.olat.repository.RepositoryEntry)22 WindowControl (org.olat.core.gui.control.WindowControl)20 UnsupportedEncodingException (java.io.UnsupportedEncodingException)18 JSONException (org.json.JSONException)18 BusinessGroup (org.olat.group.BusinessGroup)18 JSONObject (org.json.JSONObject)16 UserRequest (org.olat.core.gui.UserRequest)16 VFSContainer (org.olat.core.util.vfs.VFSContainer)16 VFSItem (org.olat.core.util.vfs.VFSItem)16 Date (java.util.Date)14 Properties (java.util.Properties)14 Property (org.olat.properties.Property)14