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

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

Introduction

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

Prototype

public static boolean isEmpty(final CharSequence string) 

Source Link

Document

Checks whether the string is considered empty.

Usage

From source file:org.hippoecm.frontend.plugins.cms.browse.section.SearchingSectionPlugin.java

License:Apache License

private void updateSearch(boolean forceQuery) {
    IModel<Node> model = folderService.getModel();
    String scope = "/";
    if (model instanceof JcrNodeModel) {
        scope = ((JcrNodeModel) model).getItemModel().getPath();
    }//from   w w w.  j  ava  2s.co m
    if (forceQuery || hasSearchResult()) {
        if (Strings.isEmpty(query)) {
            collection.setSearchResult(NO_RESULTS);
        } else {
            TextSearchBuilder sb = new TextSearchBuilder();
            sb.setScope(new String[] { scope });
            sb.setWildcardSearch(true);
            sb.setText(query);
            sb.setIncludePrimaryTypes(getPluginConfig().getStringArray("nodetypes"));
            collection.setSearchResult(sb.getResultModel());
        }
    }
}

From source file:org.hippoecm.frontend.plugins.console.menu.copy.CopyDialog.java

License:Apache License

@Override
public void onOk() {
    if (Strings.isEmpty(name)) {
        return;//from   w  w w. j  a  v a  2  s.c o m
    }
    final Node sourceNode = getOriginalModel().getObject();
    if (sourceNode == null) {
        return;
    }

    try {
        final Node parentNode = getParentDestNode();
        if (parentNode == null) {
            return;
        }
        JcrUtils.copy(sourceNode, name, parentNode);

        Node targetNode = JcrUtils.getNodeIfExists(parentNode, name);
        if (targetNode != null) {
            if (generate) {
                targetNode.accept(new GenerateNewTranslationIdsVisitor());
            }

            modelReference.setModel(new JcrNodeModel(targetNode));
        }
    } catch (RepositoryException | IllegalArgumentException ex) {
        log.error(ex.getMessage());
        error(ex.getMessage());
    }
}

From source file:org.hippoecm.frontend.plugins.console.menu.move.MoveDialog.java

License:Apache License

@Override
public void onOk() {
    Node sourceNode = getOriginalModel().getObject();
    Node parentNode = getParentDestNode();

    if (Strings.isEmpty(name) || parentNode == null || sourceNode == null) {
        return;//from  ww w. j ava  2s  . c  o  m
    }

    try {
        String targetPath = parentNode.getPath();
        if (!targetPath.endsWith("/")) {
            targetPath += "/";
        }
        targetPath += name;

        // The actual move
        Session jcrSession = UserSession.get().getJcrSession();
        jcrSession.move(sourceNode.getPath(), targetPath);

        Node targetNode = JcrUtils.getNodeIfExists(targetPath, jcrSession);
        if (targetNode != null) {
            modelReference.setModel(new JcrNodeModel(targetNode));
        }
    } catch (RepositoryException ex) {
        error(ex.getMessage());
    }
}

From source file:org.hippoecm.frontend.plugins.console.menu.node.NodeDialog.java

License:Apache License

public NodeDialog(IModelReference<Node> modelReference) {
    this.modelReference = modelReference;
    final IModel<Node> nodeModel = modelReference.getModel();
    setModel(nodeModel);/* w  w w .j  a v  a2  s.  co m*/

    getParent().add(CssClass.append("node-dialog"));

    // list defined child node names and types for automatic completion
    final Node node = nodeModel.getObject();
    try {
        NodeType pnt = node.getPrimaryNodeType();
        for (NodeDefinition nd : pnt.getChildNodeDefinitions()) {
            if (!nd.isProtected()) {
                for (NodeType nt : nd.getRequiredPrimaryTypes()) {
                    if (!nt.isAbstract()) {
                        addNodeType(nd, nt);
                    }
                    for (NodeType subnt : getDescendantNodeTypes(nt)) {
                        addNodeType(nd, subnt);
                    }
                }
            }
        }
        for (NodeType nt : node.getMixinNodeTypes()) {
            for (NodeDefinition nd : nt.getChildNodeDefinitions()) {
                if (!nd.isProtected()) {
                    for (NodeType cnt : nd.getRequiredPrimaryTypes()) {
                        if (!cnt.isAbstract()) {
                            addNodeType(nd, cnt);
                        }
                        for (NodeType subnt : getDescendantNodeTypes(cnt)) {
                            addNodeType(nd, subnt);
                        }
                    }
                }
            }
        }
    } catch (RepositoryException e) {
        log.warn("Unable to populate autocomplete list for child node names", e);
    }

    AutoCompleteSettings settings = new AutoCompleteSettings();
    settings.setAdjustInputWidth(false);
    settings.setUseSmartPositioning(true);
    settings.setShowCompleteListOnFocusGain(true);
    settings.setShowListOnEmptyInput(true);
    // Setting a max height will trigger a correct recalculation of the height when the list of items is filtered
    settings.setMaxHeightInPx(400);

    final Model<String> typeModel = new Model<String>() {
        @Override
        public String getObject() {
            if (name != null && namesToTypes.containsKey(name)) {
                Collection<String> types = namesToTypes.get(name);
                if (types.size() == 1) {
                    type = types.iterator().next();
                }
            } else if (namesToTypes.size() == 1) {
                Collection<String> types = namesToTypes.values().iterator().next();
                if (types.size() == 1) {
                    type = types.iterator().next();
                }
            }
            return type;
        }

        @Override
        public void setObject(String s) {
            type = s;
        }
    };
    typeField = new AutoCompleteTextFieldWidget<String>("type", typeModel, settings) {
        @Override
        protected Iterator<String> getChoices(final String input) {
            Collection<String> result = new TreeSet<>();
            if (!Strings.isEmpty(name)) {
                if (namesToTypes.get(name) != null) {
                    result.addAll(namesToTypes.get(name));
                }
                if (namesToTypes.get("*") != null) {
                    result.addAll(namesToTypes.get("*"));
                }
            } else {
                namesToTypes.values().forEach(result::addAll);
            }
            Iterator<String> resultIter = result.iterator();
            while (resultIter.hasNext()) {
                if (!resultIter.next().contains(input)) {
                    resultIter.remove();
                }
            }
            return result.iterator();
        }

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            if (isVisibleInHierarchy()) {
                target.add(nameField);
            }
        }
    };
    typeField.setRequired(true);
    add(typeField);

    final Model<String> nameModel = new Model<String>() {
        @Override
        public String getObject() {
            if (type != null && typesToNames.containsKey(type)) {
                if (name == null) {
                    Collection<String> names = typesToNames.get(type);
                    if (names.size() == 1) {
                        String _name = names.iterator().next();
                        if (!_name.equals("*")) {
                            name = _name;
                        }
                    }
                }
            } else if (typesToNames.size() == 1) {
                Collection<String> names = typesToNames.values().iterator().next();
                if (names.size() == 1) {
                    String _name = names.iterator().next();
                    if (!_name.equals("*")) {
                        name = _name;
                    }
                }
            }
            return name;
        }

        @Override
        public void setObject(String s) {
            name = s;
        }
    };
    nameField = new AutoCompleteTextFieldWidget<String>("name", nameModel, settings) {
        @Override
        protected Iterator<String> getChoices(String input) {
            Collection<String> result = new TreeSet<>();
            if (type != null && !type.isEmpty()) {
                if (typesToNames.get(type) != null) {
                    result.addAll(typesToNames.get(type));
                }
            } else {
                for (String nodeName : namesToTypes.keySet()) {
                    if (!nodeName.equals("*") && nodeName.contains(input)) {
                        result.add(nodeName);
                    }
                }
            }
            return result.iterator();
        }

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            if (isVisibleInHierarchy()) {
                target.add(typeField);
            }
        }
    };
    nameField.setRequired(true);

    add(setFocus(nameField));
}

From source file:org.hippoecm.frontend.plugins.gallery.imageutil.ImageBinary.java

License:Apache License

public ImageBinary(final Node parent, final InputStream stream, final String fileName, String mimeType)
        throws GalleryException {

    try {//  ww  w .  ja  v  a 2s  . com
        binary = ResourceHelper.getValueFactory(parent).createBinary(stream);
    } catch (RepositoryException e) {
        die("Failed to create binary", e);
    }

    this.fileName = fileName;

    if (MimeTypeHelper.isSvgMimeType(mimeType)) {
        // Sanselan does not recognize SVG files, so do not auto-detect the MIME type and color model
        this.mimeType = MimeTypeHelper.MIME_TYPE_SVG;
        this.colorModel = ColorModel.UNKNOWN;
    } else {
        final ImageInfo info = createImageInfo();

        this.mimeType = MimeTypeHelper
                .sanitizeMimeType(Strings.isEmpty(mimeType) ? info.getMimeType() : mimeType);
        try {
            colorModel = parseColorModel(info);
        } catch (RepositoryException e) {
            die("Failed to parse color model", e);
        }

        if (colorModel == ColorModel.UNKNOWN) {
            throw new GalleryException("Unknown color profile for " + toString());
        }

        if (colorModel != ColorModel.RGB) {
            try {
                synchronized (conversionLock) {
                    InputStream converted = ImageUtils.convertToRGB(getStream(), colorModel);
                    binary.dispose();
                    binary = ResourceHelper.getValueFactory(parent).createBinary(converted);
                    colorModel = ColorModel.RGB;
                }
            } catch (IOException e) {
                die("Error during conversion to RGB", e);
            } catch (UnsupportedImageException e) {
                die("Image can't be converted to RGB", e);
            } catch (RepositoryException e) {
                die("Repository error after conversion", e);
            }
        }
    }
}

From source file:org.hippoecm.frontend.plugins.jquery.upload.behaviors.AjaxFileUploadBehavior.java

License:Apache License

/**
 * Decides what should be the response's content type depending on the 'Accept' request header. HTML5 browsers
 * work with "application/json", older ones use IFrame to make the upload and the response should be HTML. Read
 * http://blueimp.github.com/jQuery-File-Upload/ docs for more info.
 *
 * @param request/*w ww .  j  a  va  2 s. c  o  m*/
 */
protected boolean wantsHtml(ServletWebRequest request) {
    String acceptHeader = request.getHeader("Accept");
    return !Strings.isEmpty(acceptHeader) && acceptHeader.contains("text/html");
}

From source file:org.hippoecm.frontend.plugins.login.LoginPlugin.java

License:Apache License

@Override
protected void onBeforeRender() {
    super.onBeforeRender();

    Request request = RequestCycle.get().getRequest();

    /**/*from w w w  .java  2 s.c o m*/
     * Strip the first query parameter from URL if it is empty
     * Copied from {@link AbstractComponentMapper#removeMetaParameter}
     */
    Url urlCopy = new Url(request.getUrl());
    if (!urlCopy.getQueryParameters().isEmpty()
            && Strings.isEmpty(urlCopy.getQueryParameters().get(0).getValue())) {
        String pageComponentInfoCandidate = urlCopy.getQueryParameters().get(0).getName();
        if (PageComponentInfo.parse(pageComponentInfoCandidate) != null) {
            urlCopy.getQueryParameters().remove(0);
        }
    }

    parameters = new PageParametersEncoder().decodePageParameters(urlCopy);
}

From source file:org.hippoecm.frontend.plugins.reviewedactions.DocumentWorkflowPlugin.java

License:Apache License

public DocumentWorkflowPlugin(final IPluginContext context, final IPluginConfig config) {
    super(context, config);

    add(renameAction = new StdWorkflow("rename", new StringResourceModel("rename-label", this, null), context,
            getModel()) {//from w ww  . j  a  v  a 2  s . c  o  m
        private RenameDocumentArguments renameDocumentArguments;

        @Override
        public String getSubMenu() {
            return "document";
        }

        @Override
        protected Component getIcon(final String id) {
            return HippoIcon.fromSprite(id, Icon.TYPE);
        }

        @Override
        protected IModel getTooltip() {
            if (isEnabled()) {
                return super.getTooltip();
            } else {
                return new StringResourceModel("unavailable-tip", this, null);
            }
        }

        @Override
        protected IDialogService.Dialog createRequestDialog() {
            String locale = null;
            try {
                final HippoNode node = getModelNode();
                locale = CodecUtils.getLocaleFromNodeAndAncestors(node);
                renameDocumentArguments = new RenameDocumentArguments(node.getDisplayName(), node.getName());
            } catch (RepositoryException ex) {
                renameDocumentArguments = new RenameDocumentArguments();
            }

            return new RenameDocumentDialog(renameDocumentArguments,
                    new StringResourceModel("rename-title", DocumentWorkflowPlugin.this, null), this,
                    CodecUtils.getNodeNameCodecModel(context, locale), this.getModel());
        }

        private HippoNode getModelNode() throws RepositoryException {
            return (HippoNode) getModel().getNode();
        }

        @Override
        protected String execute(Workflow wf) throws Exception {
            final String targetName = renameDocumentArguments.getTargetName();
            final String uriName = renameDocumentArguments.getUriName();

            if (Strings.isEmpty(targetName)) {
                throw new WorkflowException("No name given for document node");
            }
            if (Strings.isEmpty(uriName)) {
                throw new WorkflowException("No URL name given for document node");
            }

            final HippoNode node = getModelNode();
            String nodeName = getNodeNameCodec(node).encode(uriName);
            String localName = getLocalizeCodec().encode(targetName);

            if (Strings.isEmpty(nodeName)) {
                throw new IllegalArgumentException("You need to enter a name");
            }

            WorkflowManager manager = UserSession.get().getWorkflowManager();
            DefaultWorkflow defaultWorkflow = (DefaultWorkflow) manager.getWorkflow("core", node);
            if (!((WorkflowDescriptorModel) getDefaultModel()).getNode().getName().equals(nodeName)) {
                ((DocumentWorkflow) wf).rename(nodeName);
            }
            if (!node.getDisplayName().equals(localName)) {
                defaultWorkflow.setDisplayName(localName);
            }
            return null;
        }
    });

    add(copyAction = new StdWorkflow("copy", new StringResourceModel("copy-label", this, null), context,
            getModel()) {
        NodeModelWrapper destination = null;
        String name = null;

        @Override
        public String getSubMenu() {
            return "document";
        }

        @Override
        protected Component getIcon(final String id) {
            return HippoIcon.fromSprite(id, Icon.FILES);
        }

        @Override
        protected IDialogService.Dialog createRequestDialog() {
            destination = new NodeModelWrapper(getFolder()) {
            };

            try {
                IModel<StringCodec> codec = new AbstractReadOnlyModel<StringCodec>() {
                    @Override
                    public StringCodec getObject() {
                        try {
                            return getNodeNameCodec(getModelNode(), getFolder().getNode());
                        } catch (RepositoryException e) {
                            return getNodeNameCodec(getFolder().getNode());
                        }
                    }
                };

                final CopyNameHelper copyNameHelper = new CopyNameHelper(codec,
                        new StringResourceModel("copyof", DocumentWorkflowPlugin.this, null).getString());
                name = copyNameHelper.getCopyName(getModelNode().getDisplayName(),
                        destination.getNodeModel().getNode());
            } catch (RepositoryException ex) {
                return new ExceptionDialog(ex);
            }
            return new DestinationDialog(
                    new StringResourceModel("copy-title", DocumentWorkflowPlugin.this, null),
                    new StringResourceModel("copy-name", DocumentWorkflowPlugin.this, null),
                    new PropertyModel<>(this, "name"), destination, getPluginContext(), getPluginConfig()) {
                {
                    setOkEnabled(true);
                }

                @Override
                public void invokeWorkflow() throws Exception {
                    copyAction.invokeWorkflow();
                }

                @Override
                protected boolean checkPermissions() {
                    return isWritePermissionGranted(destination.getChainedModel());
                }

                @Override
                protected boolean checkFolderTypes() {
                    return isDocumentAllowedInFolder(DocumentWorkflowPlugin.this.getModel(),
                            destination.getChainedModel());
                }
            };
        }

        @Override
        protected String execute(Workflow wf) throws Exception {
            Node folder = destination != null ? destination.getNodeModel().getNode()
                    : new JcrNodeModel("/").getNode();
            Node document = getModel().getNode();

            String nodeName = getNodeNameCodec(document, folder).encode(name);

            DocumentWorkflow workflow = (DocumentWorkflow) wf;
            workflow.copy(new Document(folder), nodeName);

            JcrNodeModel resultModel = new JcrNodeModel(folder.getPath() + "/" + nodeName);
            Node result = resultModel.getNode();

            WorkflowManager manager = UserSession.get().getWorkflowManager();
            DefaultWorkflow defaultWorkflow = (DefaultWorkflow) manager.getWorkflow("core",
                    result.getNode(nodeName));
            defaultWorkflow.setDisplayName(getLocalizeCodec().encode(name));

            browseTo(resultModel);
            return null;
        }

        private HippoNode getModelNode() throws RepositoryException {
            return (HippoNode) getModel().getNode();
        }

    });

    add(moveAction = new StdWorkflow("move", new StringResourceModel("move-label", this, null), context,
            getModel()) {
        NodeModelWrapper destination;

        @Override
        public String getSubMenu() {
            return "document";
        }

        @Override
        protected Component getIcon(final String id) {
            return HippoIcon.fromSprite(id, Icon.MOVE_INTO);
        }

        @Override
        protected IModel getTooltip() {
            if (isEnabled()) {
                return super.getTooltip();
            } else {
                return new StringResourceModel("unavailable-tip", this, null);
            }
        }

        @Override
        protected IDialogService.Dialog createRequestDialog() {
            destination = new NodeModelWrapper(getFolder()) {
            };
            return new DestinationDialog(
                    new StringResourceModel("move-title", DocumentWorkflowPlugin.this, null), null, null,
                    destination, getPluginContext(), getPluginConfig()) {
                @Override
                public void invokeWorkflow() throws Exception {
                    moveAction.invokeWorkflow();
                }

                @Override
                protected boolean checkPermissions() {
                    return isWritePermissionGranted(destination.getChainedModel());
                }

                @Override
                protected boolean checkFolderTypes() {
                    return isDocumentAllowedInFolder(DocumentWorkflowPlugin.this.getModel(),
                            destination.getChainedModel());
                }
            };
        }

        @Override
        protected String execute(Workflow wf) throws Exception {
            Node document = getModel().getNode();
            Node folder = destination != null ? destination.getNodeModel().getObject()
                    : new JcrNodeModel("/").getNode();

            String nodeName = document.getName();
            DocumentWorkflow workflow = (DocumentWorkflow) wf;
            workflow.move(new Document(folder), nodeName);
            browseTo(new JcrNodeModel(folder.getPath() + "/" + nodeName));
            return null;
        }
    });

    add(deleteAction = new StdWorkflow("delete", new StringResourceModel("delete-label", this, null), context,
            getModel()) {

        @Override
        public String getSubMenu() {
            return "document";
        }

        @Override
        protected Component getIcon(final String id) {
            return HippoIcon.fromSprite(id, Icon.TIMES);
        }

        @Override
        protected IModel getTooltip() {
            if (isEnabled()) {
                return super.getTooltip();
            } else {
                return new StringResourceModel("unavailable-tip", this, null);
            }
        }

        @Override
        protected IDialogService.Dialog createRequestDialog() {
            IModel<String> message = new StringResourceModel("delete-message", DocumentWorkflowPlugin.this,
                    null, getDocumentName());
            IModel<String> title = new StringResourceModel("delete-title", DocumentWorkflowPlugin.this, null,
                    getDocumentName());
            return new DeleteDialog(title, getModel(), message, this, getEditorManager());
        }

        @Override
        protected String execute(Workflow wf) throws Exception {
            DocumentWorkflow workflow = (DocumentWorkflow) wf;
            workflow.delete();
            return null;
        }
    });

    add(requestDeleteAction = new StdWorkflow("requestDelete",
            new StringResourceModel("request-delete", this, null), context, getModel()) {

        @Override
        public String getSubMenu() {
            return "document";
        }

        @Override
        protected Component getIcon(final String id) {
            return HippoIcon.fromSprite(id, Icon.TIMES);
        }

        @Override
        protected IDialogService.Dialog createRequestDialog() {
            IModel<String> message = new StringResourceModel("delete-message", DocumentWorkflowPlugin.this,
                    null, getDocumentName());
            IModel<String> title = new StringResourceModel("delete-title", DocumentWorkflowPlugin.this, null,
                    getDocumentName());
            return new DeleteDialog(title, getModel(), message, this, getEditorManager());
        }

        @Override
        protected String execute(Workflow wf) throws Exception {
            DocumentWorkflow workflow = (DocumentWorkflow) wf;
            workflow.requestDeletion();
            return null;
        }
    });

    add(whereUsedAction = new StdWorkflow("where-used", new StringResourceModel("where-used-label", this, null),
            context, getModel()) {

        @Override
        public String getSubMenu() {
            return "document";
        }

        @Override
        protected Component getIcon(final String id) {
            return HippoIcon.fromSprite(id, Icon.LINK);
        }

        @Override
        protected IDialogService.Dialog createRequestDialog() {
            WorkflowDescriptorModel wdm = getModel();
            return new WhereUsedDialog(wdm, getEditorManager());
        }

        @Override
        protected String execute(Workflow wf) throws Exception {
            return null;
        }
    });

    add(historyAction = new StdWorkflow("history", new StringResourceModel("history-label", this, null),
            context, getModel()) {

        @Override
        public String getSubMenu() {
            return "document";
        }

        @Override
        protected Component getIcon(final String id) {
            return HippoIcon.fromSprite(id, Icon.RESTORE);
        }

        @Override
        protected IDialogService.Dialog createRequestDialog() {
            WorkflowDescriptorModel wdm = getModel();
            return new HistoryDialog(wdm, getEditorManager());
        }

        @Override
        protected String execute(Workflow wf) throws Exception {
            return null;
        }
    });

    Map<String, Serializable> info = getHints();
    if (!info.containsKey("delete")) {
        hideOrDisable(info, "requestDelete", requestDeleteAction);
    } else {
        requestDeleteAction.setVisible(false);
    }
    hideOrDisable(info, "delete", deleteAction);
    hideOrDisable(info, "rename", renameAction);
    hideOrDisable(info, "move", moveAction);

    hideOrDisable(info, "copy", copyAction);
    hideOrDisable(info, "listVersions", historyAction);
}

From source file:org.hippoecm.frontend.plugins.richtext.dialog.images.RichTextEditorImageService.java

License:Apache License

private RichTextImage loadImageItem(Map<String, String> values) {
    final String uuid = values.get(RichTextEditorImageLink.UUID);
    if (!Strings.isEmpty(uuid)) {
        final String type = values.get(RichTextEditorImageLink.TYPE);
        try {/*www  .ja v a  2 s .  c om*/
            return factory.loadImageItem(uuid, type);
        } catch (RichTextException e) {
            log.warn("Could not load rich text image " + uuid);
        }
    }
    return null;
}

From source file:org.hippoecm.frontend.plugins.richtext.jcr.JcrRichTextImageFactory.java

License:Apache License

/**
 * Load an existing RichTextImage using the uuid and type.
 * @throws RichTextException/* w w  w.j  a  va  2  s .  c o m*/
 */
@Override
public RichTextImage loadImageItem(String uuid, String type) throws RichTextException {
    if (Strings.isEmpty(uuid)) {
        throw new IllegalArgumentException("uuid is empty");
    }
    try {
        javax.jcr.Session session = UserSession.get().getJcrSession();
        try {
            Node node = session.getNodeByIdentifier(uuid);
            String name = RichTextFacetHelper.getChildFacetNameOrNull(nodeModel.getObject(), uuid);
            return createImageItem(node, name, type);
        } catch (ItemNotFoundException infe) {
            throw new RichTextException("Could not resolve " + uuid);
        }
    } catch (RepositoryException e) {
        log.error("Error resolving image " + uuid);
        throw new RichTextException("Error retrieving canonical node for imageNode[" + uuid + "]", e);
    }
}