Example usage for org.apache.wicket.util.string Strings lastPathComponent

List of usage examples for org.apache.wicket.util.string Strings lastPathComponent

Introduction

In this page you can find the example usage for org.apache.wicket.util.string Strings lastPathComponent.

Prototype

public static String lastPathComponent(final String path, final char separator) 

Source Link

Document

Gets the last path component of a path using a given separator.

Usage

From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.forms.ScenarioForm.java

License:Apache License

public ScenarioForm(String id, final ModalWindow window) {
    super(id, new CompoundPropertyModel<Scenario>(new Scenario()));

    add(new Label("addScenarioHeader", ResourceUtils.getModel("pageTitle.addScenario")));

    final FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);//from  www .jav a2 s .  c o  m
    add(feedback);

    setMultiPart(true);

    Person owner = getModel().getObject().getPerson();
    if (owner == null)
        owner = EEGDataBaseSession.get().getLoggedUser();

    getModel().getObject().setPerson(owner);

    List<ResearchGroup> choices = researchGroupFacade.getResearchGroupsWhereAbleToWriteInto(owner);
    if (choices == null || choices.isEmpty())
        choices = Arrays.asList(getModel().getObject().getResearchGroup());

    DropDownChoice<ResearchGroup> groups = new DropDownChoice<ResearchGroup>("researchGroup", choices,
            new ChoiceRenderer<ResearchGroup>("title"));
    groups.setRequired(true);

    TextField<String> title = new TextField<String>("title");
    title.setLabel(ResourceUtils.getModel("label.scenarioTitle"));
    title.setRequired(true);
    // title.add(new TitleExistsValidator());

    TextField<Integer> length = new TextField<Integer>("scenarioLength", Integer.class);
    length.setRequired(true);
    length.add(RangeValidator.minimum(0));

    TextArea<String> description = new TextArea<String>("description");
    description.setRequired(true);
    description.setLabel(ResourceUtils.getModel("label.scenarioDescription"));

    final WebMarkupContainer fileContainer = new WebMarkupContainer("contailer");
    fileContainer.setVisibilityAllowed(false);
    fileContainer.setOutputMarkupPlaceholderTag(true);

    /*
     * TODO file field for xml was not visible in old portal. I dont know why. So I hided it but its implemented and not tested.
     */
    // hidded line in old portal
    final DropDownChoice<ScenarioSchemas> schemaList = new DropDownChoice<ScenarioSchemas>("schemaList",
            new Model<ScenarioSchemas>(), scenariosFacade.getListOfScenarioSchemas(),
            new ChoiceRenderer<ScenarioSchemas>("schemaName", "schemaId"));
    schemaList.setOutputMarkupPlaceholderTag(true);
    schemaList.setRequired(true);
    schemaList.setLabel(ResourceUtils.getModel("label.scenarioSchema"));
    schemaList.setVisibilityAllowed(false);

    final FileUploadField file = new FileUploadField("file", new ListModel<FileUpload>());
    file.setOutputMarkupId(true);
    file.setLabel(ResourceUtils.getModel("description.fileType.dataFile"));
    file.setOutputMarkupPlaceholderTag(true);

    // hidded line in old portal
    final FileUploadField xmlfile = new FileUploadField("xmlfile", new ListModel<FileUpload>());
    xmlfile.setOutputMarkupId(true);
    xmlfile.setLabel(ResourceUtils.getModel("label.xmlDataFile"));
    xmlfile.setOutputMarkupPlaceholderTag(true);
    xmlfile.setVisibilityAllowed(false);

    // hidded line in old portal
    final RadioGroup<Boolean> schema = new RadioGroup<Boolean>("schema", new Model<Boolean>(Boolean.FALSE));
    schema.add(new Radio<Boolean>("noschema", new Model<Boolean>(Boolean.FALSE), schema));
    schema.add(new Radio<Boolean>("fromschema", new Model<Boolean>(Boolean.TRUE), schema));
    schema.setOutputMarkupPlaceholderTag(true);
    schema.setVisibilityAllowed(false);
    schema.add(new AjaxFormChoiceComponentUpdatingBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            schemaList.setVisibilityAllowed(schema.getModelObject());
            xmlfile.setRequired(!xmlfile.isRequired());

            target.add(xmlfile);
            target.add(schemaList);
        }
    });

    CheckBox privateCheck = new CheckBox("privateScenario");
    final CheckBox dataAvailable = new CheckBox("dataAvailable", new Model<Boolean>());
    dataAvailable.add(new AjaxFormComponentUpdatingBehavior("onChange") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {

            fileContainer.setVisibilityAllowed(dataAvailable.getModelObject());
            file.setRequired(!file.isRequired());
            target.add(fileContainer);
        }
    });

    fileContainer.add(file, xmlfile, schema, schemaList);

    add(groups, title, length, description, privateCheck, dataAvailable, fileContainer);

    add(new AjaxButton("submitForm", this) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            FileUpload uploadedFile = file.getFileUpload();
            Scenario scenario = ScenarioForm.this.getModelObject();

            if (!scenariosFacade.canSaveTitle(scenario.getTitle(), scenario.getScenarioId())) {
                error(ResourceUtils.getString("error.titleAlreadyInDatabase"));
                target.add(feedback);
                return;
            } else {
                // loading non-XML scenario file
                if ((uploadedFile != null) && (!(uploadedFile.getSize() == 0))) {

                    String name = uploadedFile.getClientFileName();
                    // when uploading from localhost some browsers will specify the entire path, we strip it
                    // down to just the file name
                    name = Strings.lastPathComponent(name, '/');
                    name = Strings.lastPathComponent(name, '\\');

                    // File uploaded
                    String filename = name.replace(" ", "_");
                    scenario.setScenarioName(filename);

                    scenario.setMimetype(uploadedFile.getContentType());
                    try {
                        scenario.setFileContentStream(uploadedFile.getInputStream());
                    } catch (IOException e) {
                        log.error(e.getMessage(), e);
                        error("Error while saving data.");
                        target.add(feedback);
                    }
                }

                // Creating new
                scenariosFacade.create(scenario);

                /*
                 * clean up after upload file, and set model to null or will be problem with page serialization when redirect start - DON'T DELETE IT !
                 */
                ScenarioForm.this.setModelObject(null);

                window.close(target);
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {

            target.add(feedback);
        }
    });

    add(new AjaxButton("closeForm", ResourceUtils.getModel("button.close")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            window.close(target);
        }
    }.setDefaultFormProcessing(false));

    setOutputMarkupId(true);
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.scenarios.form.ScenarioForm.java

License:Apache License

public ScenarioForm(String id, IModel<Scenario> model, final FeedbackPanel feedback) {

    super(id, new CompoundPropertyModel<Scenario>(model));

    setMultiPart(true);// w ww.  j ava  2 s.  c  o  m

    Person owner = model.getObject().getPerson();
    if (owner == null) {
        owner = EEGDataBaseSession.get().getLoggedUser();
    }

    model.getObject().setPerson(owner);

    List<ResearchGroup> choices = researchGroupFacade.getResearchGroupsWhereAbleToWriteInto(owner);
    if (choices == null || choices.isEmpty()) {
        choices = Arrays.asList(model.getObject().getResearchGroup());
    }

    DropDownChoice<ResearchGroup> groups = new DropDownChoice<ResearchGroup>("researchGroup", choices,
            new ChoiceRenderer<ResearchGroup>("title"));
    groups.setRequired(true);

    TextField<String> title = new TextField<String>("title");
    title.setLabel(ResourceUtils.getModel("label.scenarioTitle"));
    title.setRequired(true);

    TextField<Integer> length = new TextField<Integer>("scenarioLength", Integer.class);
    length.setRequired(true);
    length.add(RangeValidator.minimum(0));

    TextArea<String> description = new TextArea<String>("description");
    description.setRequired(true);
    description.setLabel(ResourceUtils.getModel("label.scenarioDescription"));

    final WebMarkupContainer fileContainer = new WebMarkupContainer("contailer");
    fileContainer.setVisibilityAllowed(false);
    fileContainer.setOutputMarkupPlaceholderTag(true);

    /*
     * TODO file field for xml was not visible in old portal. I dont know why. So I hided it but its implemented and not tested.
     */
    // hidded line in old portal
    final DropDownChoice<ScenarioSchemas> schemaList = new DropDownChoice<ScenarioSchemas>("schemaList",
            new Model<ScenarioSchemas>(), scenariosFacade.getListOfScenarioSchemas(),
            new ChoiceRenderer<ScenarioSchemas>("schemaName", "schemaId"));
    schemaList.setOutputMarkupPlaceholderTag(true);
    schemaList.setRequired(true);
    schemaList.setLabel(ResourceUtils.getModel("label.scenarioSchema"));
    schemaList.setVisibilityAllowed(false);

    final FileUploadField file = new FileUploadField("file", new ListModel<FileUpload>());
    file.setOutputMarkupId(true);
    file.setLabel(ResourceUtils.getModel("description.fileType.dataFile"));
    file.setOutputMarkupPlaceholderTag(true);

    // hidded line in old portal
    final FileUploadField xmlfile = new FileUploadField("xmlfile", new ListModel<FileUpload>());
    xmlfile.setOutputMarkupId(true);
    xmlfile.setLabel(ResourceUtils.getModel("label.xmlDataFile"));
    xmlfile.setOutputMarkupPlaceholderTag(true);
    xmlfile.setVisibilityAllowed(false);

    // hidded line in old portal
    final RadioGroup<Boolean> schema = new RadioGroup<Boolean>("schema", new Model<Boolean>(Boolean.FALSE));
    schema.add(new Radio<Boolean>("noschema", new Model<Boolean>(Boolean.FALSE), schema));
    schema.add(new Radio<Boolean>("fromschema", new Model<Boolean>(Boolean.TRUE), schema));
    schema.setOutputMarkupPlaceholderTag(true);
    schema.setVisibilityAllowed(false);
    schema.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            schemaList.setVisibilityAllowed(schema.getModelObject());
            xmlfile.setRequired(!xmlfile.isRequired());

            target.add(xmlfile);
            target.add(schemaList);
        }
    });

    CheckBox privateCheck = new CheckBox("privateScenario");
    final CheckBox dataAvailable = new CheckBox("dataAvailable", new Model<Boolean>());
    dataAvailable.add(new AjaxFormComponentUpdatingBehavior("onChange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {

            fileContainer.setVisibilityAllowed(dataAvailable.getModelObject());
            file.setRequired(!file.isRequired());
            target.add(fileContainer);
        }
    });

    SubmitLink submit = new SubmitLink("submit") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {

            FileUpload uploadedFile = file.getFileUpload();
            Scenario scenario = ScenarioForm.this.getModelObject();

            if (!scenariosFacade.canSaveTitle(scenario.getTitle(), scenario.getScenarioId())) {
                error(ResourceUtils.getString("error.titleAlreadyInDatabase"));
                return;
            } else {
                // loading non-XML scenario file
                if ((uploadedFile != null) && (!(uploadedFile.getSize() == 0))) {

                    String name = uploadedFile.getClientFileName();
                    // when uploading from localhost some browsers will specify the entire path, we strip it
                    // down to just the file name
                    name = Strings.lastPathComponent(name, '/');
                    name = Strings.lastPathComponent(name, '\\');

                    // File uploaded
                    String filename = name.replace(" ", "_");
                    scenario.setScenarioName(filename);

                    scenario.setMimetype(uploadedFile.getContentType());
                    try {
                        scenario.setFileContentStream(uploadedFile.getInputStream());
                    } catch (IOException e) {
                        log.error(e.getMessage(), e);
                    }
                }

                if (scenario.getScenarioId() > 0) {
                    // Editing existing
                    // scenarioTypeDao.update(scenarioType);
                    scenariosFacade.update(scenario);
                } else {
                    // Creating new
                    scenariosFacade.create(scenario);
                }
                /*
                 * clean up after upload file, and set model to null or will be problem with page serialization when redirect start - DON'T DELETE IT !
                 */
                ScenarioForm.this.setModelObject(null);

                setResponsePage(ScenarioDetailPage.class,
                        PageParametersUtils.getDefaultPageParameters(scenario.getScenarioId()));
            }

        }
    };

    fileContainer.add(file, xmlfile, schema, schemaList);

    add(groups, title, length, description, privateCheck, dataAvailable, submit, fileContainer);
}

From source file:fiftyfive.wicket.test.dtd.XHtmlEntityResolver.java

License:Apache License

private String filename(String systemId) {
    return Strings.lastPathComponent(systemId, '/');
}