CPD Results
The following document contains the results of PMD's CPD 5.1.2.
Duplications
File |
Line |
info/magnolia/resources/app/action/EditResourceAction.java |
118 |
info/magnolia/resources/app/action/HotfixResourceAction.java |
101 |
private void copyResourceToJcr() throws ActionExecutionException {
Resource resourceToHotfix = fetchResourceToHotfix();
Resource parent = resourceToHotfix.getParent();
if (parent == null) {
throw new ActionExecutionException(new IllegalStateException("Could not get parent of resource to hotfix."));
}
try {
Session jcrSession = context.getJCRSession(JcrResourceOrigin.RESOURCES_WORKSPACE);
if (jcrSession.nodeExists(resourceToHotfix.getPath())) {
String title = i18n.translate("resources.actions.hotfixResource.notification.alreadyExists.title");
String body = i18n.translate("resources.actions.hotfixResource.notification.alreadyExists.body", resourceToHotfix.getPath());
appContext.openAlert(WARNING, title, body, i18n.translate("button.ok"), new AlertCallback() {
@Override
public void onOk() {
}
});
return;
}
// create parent directories in JCR if they don't exist yet
Node parentNode = NodeUtil.createPath(jcrSession.getRootNode(), parent.getPath(), NodeTypes.Folder.NAME);
Node resourceNode = createResourceNode(resourceToHotfix, parentNode, resourceToHotfix.getName());
jcrSession.save();
String resourceNodePath = resourceNode.getPath(); |
File |
Line |
info/magnolia/resources/app/action/EditResourceAction.java |
144 |
info/magnolia/resources/app/action/HotfixResourceAction.java |
130 |
String resourceNodePath = resourceNode.getPath();
eventBus.fireEvent(new ContentChangedEvent(resourceNodePath));
appContext.openNotification(INFO, true, i18n.translate("resources.actions.hotfixResource.notification.success"));
} catch (Exception e) {
appContext.openNotification(ERROR, false, i18n.translate("resources.actions.hotfixResource.notification.error"));
throw new ActionExecutionException(e);
}
}
private Resource fetchResourceToHotfix() {
String resourcePath = (String) resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH).getValue();
return ((LayeredResource) origin.getByPath(resourcePath)).getFirst();
}
private Node createResourceNode(Resource resourceToHotfix, Node parentNode, String resourceName) throws RepositoryException, IOException {
try (Reader reader = resourceToHotfix.openReader()) {
String content = IOUtils.toString(reader);
Node resourceNode = parentNode.addNode(resourceName, NodeTypes.Content.NAME);
resourceNode.setProperty(JcrResourceOrigin.TEXT_PROPERTY, content);
return resourceNode;
}
}
} |