CPD Results

The following document contains the results of PMD's CPD 6.21.0.

Duplications

File Line
info/magnolia/ui/form/field/upload/basic/BasicUploadField.java 451
info/magnolia/ui/form/field/upload/basic/ResurfaceBasicUploadField.java 408
        }
        if (args != null && args.length > 0) {
            return i18n.translate(caption, args);
        } else {
            return i18n.translate(caption);
        }
    }

    protected String selectNewCaption;
    protected String selectAnotherCaption;
    protected String deleteCaption;
    protected String dropZoneCaption;
    protected String inProgressCaption;
    protected String inProgressRatioCaption;
    protected String fileDetailHeaderCaption;
    protected String fileDetailNameCaption;
    protected String fileDetailSizeCaption;
    protected String fileDetailFormatCaption;
    protected String fileDetailSourceCaption;
    protected String successNoteCaption;
    protected String warningNoteCaption;
    protected String errorNoteCaption;
    private String sizeInterruption;
    private String typeInterruption;
    private String userInterruption;

    public void setSelectNewCaption(String selectNewCaption) {
        this.selectNewCaption = selectNewCaption;
    }

    public void setSelectAnotherCaption(String selectAnotherCaption) {
        this.selectAnotherCaption = selectAnotherCaption;
    }

    public void setDropZoneCaption(String dropZoneCaption) {
        this.dropZoneCaption = dropZoneCaption;
    }

    public void setInProgressCaption(String inProgressCaption) {
        this.inProgressCaption = inProgressCaption;
    }

    public void setInProgressRatioCaption(String inProgressRatioCaption) {
        this.inProgressRatioCaption = inProgressRatioCaption;
    }

    public void setFileDetailHeaderCaption(String fileDetailHeaderCaption) {
        this.fileDetailHeaderCaption = fileDetailHeaderCaption;
    }

    public void setFileDetailNameCaption(String fileDetailNameCaption) {
        this.fileDetailNameCaption = fileDetailNameCaption;
    }

    public void setFileDetailSizeCaption(String fileDetailSizeCaption) {
        this.fileDetailSizeCaption = fileDetailSizeCaption;
    }

    public void setFileDetailFormatCaption(String fileDetailFormatCaption) {
        this.fileDetailFormatCaption = fileDetailFormatCaption;
    }

    public void setFileDetailSourceCaption(String fileDetailSourceCaption) {
        this.fileDetailSourceCaption = fileDetailSourceCaption;
    }

    public void setSuccessNoteCaption(String successNoteCaption) {
        this.successNoteCaption = successNoteCaption;
    }

    public void setWarningNoteCaption(String warningNoteCaption) {
        this.warningNoteCaption = warningNoteCaption;
    }

    public void setErrorNoteCaption(String errorNoteCaption) {
        this.errorNoteCaption = errorNoteCaption;
    }

    public void setDeteteCaption(String deleteCaption) {
        this.deleteCaption = deleteCaption;
    }

    public void setSizeInterruption(String sizeInterruption) {
        this.sizeInterruption = sizeInterruption;
    }

    public void setTypeInterruption(String typeInterruption) {
        this.typeInterruption = typeInterruption;
    }

    public void setUserInterruption(String userInterruption) {
        this.userInterruption = userInterruption;
    }

    @Override
    protected void displayUploadInterruptNote(InterruptionReason reason) {
        String caption = "";
File Line
info/magnolia/ui/dialog/action/SaveDialogAction.java 81
info/magnolia/ui/form/action/SaveFormAction.java 89
            try {
                final Node node = item.applyChanges();
                setNodeName(node, item);
                node.getSession().save();
            } catch (final RepositoryException e) {
                throw new ActionExecutionException(e);
            }
            callback.onSuccess(getDefinition().getName());
        }
    }

    protected boolean validateForm() {
        boolean isValid = validator.isValid();
        validator.showValidation(!isValid);
        if (!isValid) {
            log.info("Validation error(s) occurred. No save performed.");
        }
        return isValid;
    }

    /**
     * Set the node Name.
     * Node name is set to: <br>
     * the value of the property 'name' if it is present.
     */
    protected void setNodeName(Node node, JcrNodeAdapter item) throws RepositoryException {
        String propertyName = "name";
        if (node.hasProperty(propertyName) && !node.hasProperty(ModelConstants.JCR_NAME)) {
            Property property = node.getProperty(propertyName);
            String newNodeName = property.getString();
            if (!node.getName().equals(Path.getValidatedLabel(newNodeName))) {
                newNodeName = Path.getUniqueLabel(node.getSession(), node.getParent().getPath(), Path.getValidatedLabel(newNodeName));
                item.setNodeName(newNodeName);
                NodeUtil.renameNode(node, newNodeName);
            }
        }
    }
}
File Line
info/magnolia/ui/form/field/upload/basic/BasicUploadField.java 548
info/magnolia/ui/form/field/upload/basic/ResurfaceBasicUploadField.java 505
        if (reason.equals(InterruptionReason.USER)) {
            caption = userInterruption;
        } else if (reason.equals(InterruptionReason.FILE_SIZE)) {
            caption = sizeInterruption;
        } else {
            caption = typeInterruption;
        }
        uiContext.openNotification(MessageStyleTypeEnum.WARNING, true, getCaption(warningNoteCaption, new String[] { i18n.translate(caption) }));
    }

    @Override
    protected void displayUploadFinishedNote(String fileName) {
        uiContext.openNotification(MessageStyleTypeEnum.INFO, true, getCaption(successNoteCaption, new String[] { fileName }));
    }

    @Override
    protected void displayUploadFailedNote(String fileName) {
        uiContext.openAlert(MessageStyleTypeEnum.ERROR, "ERROR", getCaption(errorNoteCaption, new String[] { fileName }), i18n.translate("button.ok"), null);
    }

    public void setEditFileName(boolean editFileName) {
        this.editFileName = editFileName;
    }

    public void setEditFileFormat(boolean editFileFormat) {
        this.editFileFormat = editFileFormat;
    }
File Line
info/magnolia/ui/form/field/upload/basic/BasicUploadField.java 409
info/magnolia/ui/form/field/upload/basic/ResurfaceBasicUploadField.java 386
        this.setInProgressCaption(definition.getInProgressCaption());
        this.setInProgressRatioCaption(definition.getInProgressRatioCaption());
        this.setFileDetailHeaderCaption(definition.getFileDetailHeaderCaption());
        this.setFileDetailNameCaption(definition.getFileDetailNameCaption());
        this.setFileDetailSizeCaption(definition.getFileDetailSizeCaption());
        this.setFileDetailFormatCaption(definition.getFileDetailFormatCaption());
        this.setFileDetailSourceCaption(definition.getFileDetailSourceCaption());
        this.setSuccessNoteCaption(definition.getSuccessNoteCaption());
        this.setWarningNoteCaption(definition.getWarningNoteCaption());
        this.setErrorNoteCaption(definition.getErrorNoteCaption());
        this.setDeteteCaption(definition.getDeleteCaption());
        this.setEditFileFormat(definition.isEditFileFormat());
        this.setEditFileName(definition.isEditFileName());
        this.setUserInterruption(definition.getUserInterruption());
        this.setTypeInterruption(definition.getTypeInterruption());
        this.setSizeInterruption(definition.getSizeInterruption());
    }

    /**
     * Caption section.
     */
    protected String captionExtension;
File Line
info/magnolia/ui/contentapp/browser/action/SaveItemPropertyAction.java 100
info/magnolia/ui/dialog/action/SaveConfigDialogAction.java 102
        if (!((JcrItemAdapter) item).hasChangedProperties()) {
            return;
        }

        if (item instanceof AbstractJcrNodeAdapter) {
            // Saving JCR Node, getting updated node first
            AbstractJcrNodeAdapter nodeAdapter = (AbstractJcrNodeAdapter) item;
            try {
                // get modifications
                Node node = nodeAdapter.applyChanges();
                node.getSession().save();
            } catch (RepositoryException e) {
                log.error("Could not save changes to node", e);
            }

        } else if (item instanceof JcrPropertyAdapter) {
            // Saving JCR Property, update it first
            JcrPropertyAdapter propertyAdapter = (JcrPropertyAdapter) item;
            try {
                // get parent first because once property is updated, it won't exist anymore if the name changes
                Node parent = propertyAdapter.getJcrItem().getParent();

                // get modifications
                propertyAdapter.applyChanges();
                parent.getSession().save();

                // update workbench selection in case the property changed name
                JcrPropertyItemId newItemId = propertyAdapter.getItemId();
                eventBus.fireEvent(new ContentChangedEvent(newItemId));
File Line
info/magnolia/ui/form/field/transformer/item/FileTransformer.java 265
info/magnolia/ui/form/field/transformer/multi/DelegatingMultiValueFieldTransformer.java 220
    }

    /**
     * Populates the given root item with its child items.
     */
    protected void populateStoredChildItems(JcrNodeAdapter rootItem) {
        List<Node> childNodes = getStoredChildNodes(rootItem);
        for (Node child : childNodes) {
            JcrNodeAdapter item = new JcrNodeAdapter(child);
            rootItem.addChild(item);
        }
    }

    /**
     * Fetches child nodes of the given parent from JCR, filtered using the {@link NodeUtil#MAGNOLIA_FILTER} predicate.
     */
    protected List<Node> getStoredChildNodes(JcrNodeAdapter parent) {
        try {
            if (!(parent instanceof JcrNewNodeAdapter) && parent.getJcrItem().hasNodes()) {
                return NodeUtil.asList(NodeUtil.getNodes(parent.getJcrItem(), NodeUtil.MAGNOLIA_FILTER));
            }
        } catch (RepositoryException re) {
            log.warn("Not able to access the Child Nodes of the following Node Identifier {}", parent.getItemId(), re);
        }
        return new ArrayList<>();
File Line
info/magnolia/ui/workbench/thumbnail/JcrThumbnailContainer.java 109
info/magnolia/ui/workbench/tree/HierarchicalJcrContainer.java 292
        try {
            if (!getConfiguration().isIncludeSystemNodes() && node.getName().startsWith("jcr:") || node.getName().startsWith("rep:")) {
                return false;
            }

            String primaryNodeTypeName = node.getPrimaryNodeType().getName();
            for (NodeTypeDefinition nodeTypeDefinition : getConfiguration().getNodeTypes()) {
                if (nodeTypeDefinition.isStrict()) {
                    if (primaryNodeTypeName.equals(nodeTypeDefinition.getName())) {
                        return true;
                    }
                } else if (NodeUtil.isNodeType(node, nodeTypeDefinition.getName())) {
                    return true;
                }
            }
File Line
info/magnolia/ui/form/field/upload/basic/BasicUploadField.java 581
info/magnolia/ui/form/field/upload/basic/ResurfaceBasicUploadField.java 531
    }

    @Override
    public boolean isEmpty() {
        return getValue().isEmpty();
    }

    @Override
    public void setReadOnly(boolean readOnly) {
        super.setReadOnly(readOnly);
        if (readOnly) {
            // Remove drop zone
            if (getDropZone() != null) {
                getDropZone().setDropHandler(null);
            }
            if (getUpload() != null) {
                getUpload().removeStartedListener(this);
                getUpload().removeFinishedListener(this);
                getUpload().removeProgressListener(this);
            }
            if (getValue().isEmpty()) {
                buildEmptyLayout();
            }
        }

    }
}
File Line
info/magnolia/ui/dialog/formdialog/FormBuilder.java 179
info/magnolia/ui/dialog/formdialog/FormPresenterImpl.java 208
            FormTab tab = buildFormTab(tabDefinition, item, form);
            if (tab == null) continue;

            Iterator<Component> fieldIt = tab.getContainer().iterator();
            while (fieldIt.hasNext()) {
                view.addField((Field<?>) fieldIt.next());
            }

            fieldIt = tab.getContainer().iterator();
            if (!firstFieldIsBuilt && fieldIt.hasNext()) {
                ((Component.Focusable) fieldIt.next()).focus();
                firstFieldIsBuilt = true;
            }

            view.addFormSection(tabDefinition.getLabel(), tab.getContainer());
File Line
info/magnolia/ui/workbench/thumbnail/JcrThumbnailContainer.java 175
info/magnolia/ui/workbench/thumbnail/ThumbnailContainer.java 168
    }

    /**
     * ThumbnailContainer property. Can have a Resource or a String as value.
     */
    public class ThumbnailContainerProperty extends AbstractProperty<Object> {

        private Object resourceId;

        private final ImageProvider imageProvider;

        public ThumbnailContainerProperty(final Object resourceId, ImageProvider imageProvider) {
            this.resourceId = resourceId;
            this.imageProvider = imageProvider;
        }

        @Override
        public Object getValue() {
            if (imageProvider == null) {
                return null;
            }
            return imageProvider.getThumbnailResource(resourceId, ImageProvider.THUMBNAIL_GENERATOR);
        }

        @Override
        public void setValue(Object newValue) throws ReadOnlyException {
            this.resourceId = newValue;
        }

        @Override
        public Class<Object> getType() {
            return Object.class;
        }
    }

    /**
     * ThumbnailContainer property that builds a caption based on the filename and extension. Should ideally be configurable.
     */
    public class ThumbnailCaptionProperty extends AbstractProperty<Object> {