magnolia-core Version: 5.0-m5-s2 Last Published: Jun 12, 2012

CPD Results

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

Duplications

FileLine
info/magnolia/cms/beans/config/PropertiesInitializer.java398
info/magnolia/init/AbstractMagnoliaConfigurationProperties.java123
        final StringBuffer buf = new StringBuffer(strVal.trim());

        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);
FileLine
info/magnolia/jcr/decoration/ContentDecoratorNodeWrapper.java133
info/magnolia/jcr/wrapper/PropertyAndChildWrappingNodeWrapper.java53
        super(wrapped);
    }

    @Override
    public PropertyIterator getProperties() throws RepositoryException {
        return wrapPropertyIterator(super.getProperties());
    }

    @Override
    public PropertyIterator getProperties(String namePattern) throws RepositoryException {
        return wrapPropertyIterator(super.getProperties(namePattern));
    }

    @Override
    public PropertyIterator getProperties(String[] nameGlobs) throws RepositoryException {
        return wrapPropertyIterator(super.getProperties(nameGlobs));
    }

    @Override
    public PropertyIterator getWeakReferences() throws RepositoryException {
        return wrapPropertyIterator(super.getWeakReferences());
    }

    @Override
    public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
        return wrapProperty(super.getProperty(relPath));
    }

    @Override
    public PropertyIterator getReferences(String name) throws RepositoryException {
        return wrapPropertyIterator(super.getReferences(name));
    }

    @Override
    public PropertyIterator getWeakReferences(String name) throws RepositoryException {
        return wrapPropertyIterator(super.getWeakReferences(name));
    }

    @Override
    public PropertyIterator getReferences() throws RepositoryException {
        return wrapPropertyIterator(super.getReferences());
    }

    protected PropertyIterator wrapPropertyIterator(PropertyIterator propertyIterator) {
FileLine
info/magnolia/importexport/PropertiesImportExport.java153
info/magnolia/jcr/util/PropertiesImportExport.java179
    protected Object convertPropertyStringToObject(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;
    }
FileLine
info/magnolia/importexport/PropertiesImportExport.java71
info/magnolia/jcr/util/PropertiesImportExport.java86
    public void createNodes(Node 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, MgnlNodeType.NT_CONTENTNODE);
FileLine
info/magnolia/module/model/reader/BetwixtModuleDefinitionReader.java136
info/magnolia/objectfactory/configuration/ComponentConfigurationReader.java113
    public ComponentsDefinition readFromResource(String resourcePath) {
        final InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream(resourcePath));
        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("components", dtdUrl));
FileLine
info/magnolia/jcr/decoration/ContentDecoratorNodeWrapper.java69
info/magnolia/jcr/decoration/ContentDecoratorPropertyWrapper.java58
        this.contentDecorator = 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 getNode() throws ItemNotFoundException, ValueFormatException, RepositoryException {