use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class ContentNodeTranslator method doTranslate.
private Content doTranslate(final Node node, final boolean hasChildren, final boolean allowAltRootPath) {
final ContentId contentId = ContentId.from(node.id().toString());
if (!allowAltRootPath && !(node.path().toString().startsWith(ContentNodeHelper.getContentRoot().toString() + "/") || node.path().equals(ContentNodeHelper.getContentRoot()))) {
throw new ContentNotFoundException(contentId, ContextAccessor.current().getBranch(), ContentNodeHelper.getContentRoot());
}
final ContentPath parentContentPath = getParent(node.path());
final Content.Builder<?> builder = contentDataSerializer.fromData(node.data().getRoot());
builder.id(contentId).parentPath(parentContentPath).name(node.name().toString()).childOrder(node.getChildOrder()).permissions(node.getPermissions()).inheritPermissions(node.inheritsPermissions()).hasChildren(hasChildren).contentState(ContentState.from(node.getNodeState().value())).manualOrderValue(node.getManualOrderValue());
final boolean isRoot = NodePath.ROOT.equals(node.parentPath());
if (isRoot) {
builder.root();
}
return builder.build();
}
use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class CreateContentCommand method getDefaultLanguage.
private Locale getDefaultLanguage(final CreateContentParams createContentParams) {
ContentPath parentPath = createContentParams.getParent();
if (createContentParams.getLanguage() == null) {
final Node parent = nodeService.getByPath(ContentNodeHelper.translateContentParentToNodeParentPath(parentPath));
final List<Property> inheritProperties = parent.data().getProperties(ContentPropertyNames.INHERIT);
final boolean inherited = inheritProperties.stream().anyMatch(property -> ContentInheritType.CONTENT.name().equals(property.getString()));
final String language;
if (inherited) {
final Node contentRootNode = runAsAdmin(() -> this.nodeService.getByPath(ContentNodeHelper.translateContentPathToNodePath(ContentPath.ROOT)));
language = contentRootNode.data().getString(ContentPropertyNames.LANGUAGE);
} else {
language = parent.data().getString(ContentPropertyNames.LANGUAGE);
}
return language != null ? Locale.forLanguageTag(language) : null;
} else {
return createContentParams.getLanguage();
}
}
use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class CreateMediaHandler method doExecute.
@Override
protected Object doExecute() {
String name = this.name;
Content result = null;
final ContentPath parent = this.parentPath != null ? ContentPath.from(this.parentPath) : ContentPath.ROOT;
while (result == null) {
final CreateMediaParams params = createParams(name);
try {
result = this.contentService.create(params);
} catch (ContentAlreadyExistsException e) {
name = generateUniqueContentName(this.idGenerator, parent, this.name);
}
}
return new ContentMapper(result);
}
use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class MoveContentHandler method executeMove.
private Content executeMove() {
final ContentId sourceId;
final ContentPath sourcePath;
if (this.source.startsWith("/")) {
// source is path
sourcePath = ContentPath.from(this.source);
final Content sourceContent = contentService.getByPath(sourcePath);
sourceId = sourceContent.getId();
} else {
// source is key
sourceId = ContentId.from(this.source);
final Content sourceContent = contentService.getById(sourceId);
sourcePath = sourceContent.getPath();
}
if (target.endsWith("/")) {
// /a/b -> /c/d/ => /c/d/b
return move(sourceId, ContentPath.from(target).asAbsolute());
} else if (!target.startsWith("/")) {
// /a/b -> c => /a/c
return rename(sourceId, target);
} else {
// rename+move to target path
final ContentPath targetPath = ContentPath.from(target);
final ContentPath targetParent = targetPath.getParentPath();
if (targetParent.equals(sourcePath.getParentPath())) {
// /a/b -> /a/c => /a/c
return rename(sourceId, targetPath.getName());
}
// /a/b -> /c/d => /c/d
if (contentService.contentExists(targetPath)) {
final Context currentContext = ContextAccessor.current();
throw new ContentAlreadyExistsException(targetPath, currentContext.getRepositoryId(), currentContext.getBranch());
}
// needs to be first renamed to temporary unique name to avoid clashing with siblings with same target name in source parent or with siblings with source name in target parent
rename(sourceId, uniqueName());
move(sourceId, targetParent);
return rename(sourceId, targetPath.getName());
}
}
use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class UnpublishContentHandler method resolveContentIds.
private List<ContentId> resolveContentIds() {
final List<ContentId> contentIds = new ArrayList<>();
for (final String key : this.keys) {
if (key.startsWith("/")) {
final ContentPath path = ContentPath.from(key);
final Content content = getByPath(path);
if (content != null) {
contentIds.add(content.getId());
}
} else {
contentIds.add(ContentId.from(key));
}
}
return contentIds;
}
Aggregations