CPD Results

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

Duplications

File Line
info/magnolia/setup/AddLockableMixinToActivatableMixinTask.java 72
info/magnolia/setup/AddLockableMixinToVersionableMixinTask.java 70
        NodeTypeDefinition ntd = createNodeTypeWithProperties(nodeTypeManager, NodeTypes.Activatable.NAME,
                new String[]{JcrConstants.MIX_LOCKABLE}, true, false, null, false, properties);
        return Collections.singletonList(ntd);
    }

    @Override
    public List<String> getNodeTypesToUnregister(NodeTypeManager nodeTypeManager) throws RepositoryException {
        return Lists.newArrayList();
    }

    /**
     * Create a {@link NodeTypeTemplate} by using a {@link javax.jcr.nodetype.NodeType definition}.
     * This method is takes {@link PropertyDefinitionTemplate}s into consideration as well.
     */
    private NodeTypeTemplate createNodeTypeWithProperties(NodeTypeManager nodeTypeManager, String name, String[] superTypeNames, boolean isMixin, boolean isOrderableChildNodes, String primaryItemName, boolean isQueryable, List<PropertyDefinitionTemplate> properties) throws RepositoryException {
        NodeTypeTemplate nodeType = createNodeType(nodeTypeManager, name, superTypeNames, isMixin, isOrderableChildNodes, primaryItemName, isQueryable);
        nodeType.getPropertyDefinitionTemplates().addAll(properties);

        return nodeType;
    }

    /**
     * Creates a {@link PropertyDefinitionTemplate} for given parameters.
     */
    private PropertyDefinitionTemplate createPropertyDefinitionTemplate(NodeTypeManager nodeTypeManager, String name,
                                                                        String type, boolean isAutoCreated,
                                                                        boolean isMandatory, String onParentVersion,
                                                                        boolean isProtected, boolean isMultiple) throws RepositoryException {
        PropertyDefinitionTemplate template = nodeTypeManager.createPropertyDefinitionTemplate();
        template.setName(name);
        template.setRequiredType(PropertyType.valueFromName(type));
        template.setAutoCreated(isAutoCreated);
        template.setMandatory(isMandatory);
        template.setOnParentVersion(OnParentVersionAction.valueFromName(onParentVersion));
        template.setProtected(isProtected);
        template.setMultiple(isMultiple);
        return template;
    }
}
File Line
info/magnolia/cms/beans/config/PropertiesInitializer.java 387
info/magnolia/init/AbstractMagnoliaConfigurationProperties.java 125
        StringBuffer buf = new StringBuffer(strVal);

        int startIndex = strVal.indexOf(PLACEHOLDER_PREFIX);
        while (startIndex != -1) {
            int endIndex = -1;

            int index = startIndex + PLACEHOLDER_PREFIX.length();
            int withinNestedPlaceholder = 0;
            while (index < buf.length()) {
                if (PLACEHOLDER_SUFFIX.equals(buf.subSequence(index, index + PLACEHOLDER_SUFFIX.length()))) {
                    if (withinNestedPlaceholder > 0) {
                        withinNestedPlaceholder--;
                        index = index + PLACEHOLDER_SUFFIX.length();
                    } else {
                        endIndex = index;
                        break;
                    }
                } else if (PLACEHOLDER_PREFIX.equals(buf.subSequence(index, index + PLACEHOLDER_PREFIX.length()))) {
                    withinNestedPlaceholder++;
                    index = index + PLACEHOLDER_PREFIX.length();
                } else {
                    index++;
                }
            }

            if (endIndex != -1) {
                String placeholder = buf.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
                if (!visitedPlaceholders.add(placeholder)) {

                    log.warn("Circular reference detected in properties, \"{}\" is not resolvable", strVal);
                    return strVal;
                }
                // Recursive invocation, parsing placeholders contained in the placeholder key.
                placeholder = parseStringValue(placeholder, visitedPlaceholders);
File Line
info/magnolia/cms/core/Path.java 217
info/magnolia/jcr/util/NodeNameHelper.java 211
        if ("UTF-8".equals(charset)) {
            // jackrabbit not allowed 32: [ ] 91: [[] 93: []] 42: [*] 34: ["] 46: [.] 58 [:] 92: [\] 39 :[']
            // url not valid 59: [;] 47: [/] 63: [?] 43: [+] 37: [%] 33: [!] 35:[#]
            if (charCode != 32
                    && charCode != '['
                    && charCode != ']'
                    && charCode != '*'
                    && charCode != '"'
                    && charCode != ':'
                    && charCode != 92
                    && charCode != 39
                    && charCode != ';'
                    && charCode != '/'
                    && charCode != '?'
                    && charCode != '+'
                    && charCode != '%'
                    && charCode != '!'
                    && charCode != '#'
                    && charCode != '@'
                    && charCode != '='
                    && charCode != '&'
                    && charCode != SelectorUtil.SELECTOR_DELIMITER.charAt(0)) {
                return true;
            }
        } else {
            // charCodes: 48-57: [0-9]; 65-90: [A-Z]; 97-122: [a-z]; 45: [-]; 95:[_]
            if (((charCode >= 48) && (charCode <= 57))
                    || ((charCode >= 65) && (charCode <= 90))
                    || ((charCode >= 97) && (charCode <= 122))
                    || charCode == 45
                    || charCode == 46
                    || charCode == 95) {
                return true;
            }

        }
        return false;

    }
File Line
info/magnolia/cms/util/ObservationUtil.java 339
info/magnolia/observation/DeferringEventListener.java 123
    public static class ListBasedEventIterator implements EventIterator {

        private Iterator iterator;
        private List events;
        private int pos = 0;

        public ListBasedEventIterator(List events) {
            this.events = events;
            this.iterator = events.iterator();
        }

        @Override
        public boolean hasNext() {
            return this.iterator.hasNext();
        }

        @Override
        public Object next() {
            pos++;
            return this.iterator.next();
        }

        @Override
        public void remove() {
            this.iterator.remove();
        }

        @Override
        public Event nextEvent() {
            return (Event) next();
        }

        @Override
        public long getPosition() {
            return pos;
        }

        @Override
        public long getSize() {
            return events.size();
        }

        @Override
        public void skip(long skipNum) {
            for (int i = 0; i < skipNum; i++) {
                next();
            }
        }
    }

}
File Line
info/magnolia/content2bean/impl/TypeMappingImpl.java 82
info/magnolia/jcr/node2bean/impl/TypeMappingImpl.java 273
    public Method getAddMethod(Class<?> type, String name, int numberOfParameters) {
        name = StringUtils.capitalize(name);
        Method method = getExactMethod(type, "add" + name, numberOfParameters);
        if (method == null) {
            method = getExactMethod(type, "add" + StringUtils.removeEnd(name, "s"), numberOfParameters);
        }

        if (method == null) {
            method = getExactMethod(type, "add" + StringUtils.removeEnd(name, "es"), numberOfParameters);
        }

        if (method == null) {
            method = getExactMethod(type, "add" + StringUtils.removeEnd(name, "ren"), numberOfParameters);
        }

        if (method == null) {
            method = getExactMethod(type, "add" + StringUtils.removeEnd(name, "ies") + "y", numberOfParameters);
        }
        return method;
    }

    /**
     * Cache the already resolved types.
     */
    @Override
File Line
info/magnolia/importexport/PropertiesImportExport.java 153
info/magnolia/jcr/util/PropertiesImportExport.java 172
    protected Object convertNodeDataStringToObject(String valueStr) {
        if (contains(valueStr, ':')) {
            final String type = StringUtils.substringBefore(valueStr, ":");
            final String value = StringUtils.substringAfter(valueStr, ":");

            // there is no beanUtils converter for Calendar
            if (type.equalsIgnoreCase("date")) {
                return ISO8601.parse(value);
            } else if (type.equalsIgnoreCase("binary")) {
                return new ByteArrayInputStream(value.getBytes());
            } else {
                try {
                    final Class<?> typeCl;
                    if (type.equals("int")) {
                        typeCl = Integer.class;
                    } else {
                        typeCl = Class.forName("java.lang." + StringUtils.capitalize(type));
                    }
                    return ConvertUtils.convert(value, typeCl);
                } catch (ClassNotFoundException e) {
                    // possibly a stray :, let's ignore it for now
                    return valueStr;
                }
            }
        }
        // no type specified, we assume it's a string, no conversion
        return valueStr;
    }
File Line
info/magnolia/cms/core/DefaultACLBasedPermissions.java 112
info/magnolia/cms/core/NodeTypeBasedPermissions.java 107
    }

    @Override
    public boolean canRead(Path itemPath, ItemId itemId) throws RepositoryException {

        if ((itemId != null && "cafebabe-cafe-babe-cafe-babecafebabe".equals(itemId.toString())) || (itemPath != null && "/".equals(itemPath.toString()))) {
            // quick check - allow access to root to all like in old mgnl security
            return true;
        }

        if (itemPath == null) {

            // we deal only with permissions on nodes
            if (!itemId.denotesNode()) {
                itemId = ((PropertyId) itemId).getParentId();
            }

            synchronized (monitor) {

                if (readCache.containsKey(itemId)) {
                    return readCache.get(itemId);
                }

                itemPath = session.getHierarchyManager().getPath(itemId);
                boolean canRead = canRead(itemPath, itemId);
                readCache.put(itemId, canRead);
                return canRead;
            }
        }

        String path = pathResolver.getJCRPath(itemPath);
File Line
info/magnolia/content2bean/impl/Content2BeanTransformerImpl.java 344
info/magnolia/jcr/node2bean/impl/Node2BeanTransformerImpl.java 314
                throw new Content2BeanException(e);
            }
        }

        if (Locale.class.equals(propertyType)) {
            if (value instanceof String) {
                String localeStr = (String) value;
                if (StringUtils.isNotEmpty(localeStr)) {
                    return LocaleUtils.toLocale(localeStr);
                }
            }
        }

        if (Collection.class.equals(propertyType) && value instanceof Map) {
            // TODO never used ?
            return ((Map) value).values();
        }

        // this is mainly the case when we are flattening node hierarchies
        if (String.class.equals(propertyType) && value instanceof Map && ((Map) value).size() == 1) {
            return ((Map) value).values().iterator().next();
        }

        return value;
    }
File Line
info/magnolia/importexport/PropertiesImportExport.java 71
info/magnolia/jcr/util/PropertiesImportExport.java 79
    public void createContent(Content root, InputStream propertiesStream) throws IOException, RepositoryException {
        Properties properties = new OrderedProperties();

        properties.load(propertiesStream);

        properties = keysToInnerFormat(properties);

        for (Object o : properties.keySet()) {
            String key = (String) o;
            String valueStr = properties.getProperty(key);

            String propertyName = StringUtils.substringAfterLast(key, ".");
            String path = StringUtils.substringBeforeLast(key, ".");

            String type = null;
            if (propertyName.equals("@type")) {
                type = valueStr;
            } else if (properties.containsKey(path + ".@type")) {
                type = properties.getProperty(path + ".@type");
            }

            type = StringUtils.defaultIfEmpty(type, ItemType.CONTENTNODE.getSystemName());
File Line
info/magnolia/cms/util/NodeDataUtil.java 108
info/magnolia/jcr/util/PropertyUtil.java 292
    public static String getValueString(Value value, String dateFormat) {
        try {
            switch (value.getType()) {
            case (PropertyType.STRING):
                return value.getString();
            case (PropertyType.DOUBLE):
                return Double.toString(value.getDouble());
            case (PropertyType.LONG):
                return Long.toString(value.getLong());
            case (PropertyType.BOOLEAN):
                return Boolean.toString(value.getBoolean());
            case (PropertyType.DATE):
                Date valueDate = value.getDate().getTime();
                return DateUtil.format(valueDate, dateFormat);
File Line
info/magnolia/module/model/reader/BetwixtModuleDefinitionReader.java 141
info/magnolia/objectfactory/configuration/ComponentConfigurationReader.java 113
        final InputStreamReader reader = new InputStreamReader(resourceAsStream);
        try {
            return read(reader);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                log.error("Can't close input for {}", resourcePath);
            }
        }
    }

    /**
     * @deprecated TODO very ugly hack to force documents to be validated against OUR DTD.
     *             We could use an EntityResolver, but it seems that with SAX, the documents will only be
     *             validated if they original have a doctype declaration.
     *             We could also use http://doctypechanger.sourceforge.net/
     *             ... or switch to XmlSchema.
     */
    private Reader replaceDtd(Reader reader) throws IOException {
        String content = IOUtils.toString(reader);

        // remove doctype
        Pattern pattern = Pattern.compile("<!DOCTYPE .*>");
        Matcher matcher = pattern.matcher(content);
        content = matcher.replaceFirst("");

        // set doctype to the dtd
        try {
            Document doc = new SAXBuilder().build(new StringReader(content));
            doc.setDocType(new DocType("module", dtdUrl));
File Line
info/magnolia/jcr/decoration/ContentDecoratorNodeWrapper.java 101
info/magnolia/jcr/decoration/ContentDecoratorPropertyWrapper.java 58
        return contentDecorator;
    }

    @Override
    public Session getSession() throws RepositoryException {
        return wrapSession(super.getSession());
    }

    @Override
    public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
        Item item = super.getAncestor(depth);
        if (item.isNode()) {
            return wrapNode((Node) item);
        } else {
            return wrapProperty((Property) item);
        }
    }

    @Override
    public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException {
        return wrapNode(super.getParent());
    }

    @Override
    public Node addNode(String relPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {
File Line
info/magnolia/voting/voters/RequestExtensionVoter.java 62
info/magnolia/voting/voters/UserAgentVoter.java 57
    public List<String> getAllowed() {
        return allowed;
    }

    public void setAllowed(List<String> allowed) {
        this.allowed.addAll(allowed);
    }

    public void addAllowed(String contentType) {
        allowed.add(contentType);
    }

    public List<String> getRejected() {
        return rejected;
    }

    public void setRejected(List<String> rejected) {
        this.rejected.addAll(rejected);
    }

    public void addRejected(String contentType) {
        rejected.add(contentType);
    }

    @Override
    protected boolean boolVote(Object value) {
        final String extension = aggregationStateProvider.get().getExtension();
File Line
info/magnolia/content2bean/impl/Content2BeanTransformerImpl.java 240
info/magnolia/jcr/node2bean/impl/Node2BeanTransformerImpl.java 368
            value = state.getCurrentContent().getName();
        } else if (propertyName.equals("className") && value == null) {
            value = values.get("class");
        }

        // do no try to set a bean-property that has no corresponding node-property
        // else if (!values.containsKey(propertyName)) {
        if (value == null) {
            return;
        }

        log.debug("try to set {}.{} with value {}", bean, propertyName, value);

        // if the parent bean is a map, we can't guess the types.
        if (!(bean instanceof Map)) {
            try {
                PropertyTypeDescriptor dscr = mapping.getPropertyTypeDescriptor(bean.getClass(), propertyName);
                if (dscr.getType() != null) {

                    // try to use an adder method for a Collection property of the bean
                    if (dscr.isCollection() || dscr.isMap()) {
File Line
info/magnolia/module/delta/CopyNodeTask.java 59
info/magnolia/module/delta/MoveNodeTask.java 56
    public CopyNodeTask(String name, String description, String workspaceName, String src, String dest, boolean overwrite) {
        super(name, description);
        this.workspaceName = workspaceName;
        this.src = src;
        this.dest = dest;
        this.overwrite = overwrite;
    }

    @Override
    protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException {
        Session session = installContext.getJCRSession(workspaceName);
        if (session.nodeExists(dest)) {
            if (overwrite) {
                session.getNode(dest).remove();
            } else {
                installContext.error("Can't copy " + src + " to " + dest + " because the target node already exists.", null);