Start page / Plug-In Development / ContentCreator Extensions / Management Extensions / Store Mapping / Code Example
Store Mapping: Code Example
A Store Mapping plug-in implements the FirstSpirit API interface WebeditStoreMappingPlugin. This interface defines two methods that operate slightly differently:
- requestMappedFolder()
should return an existing Page Store folder corresponding to the Site Store folder passed as a parameter. If a suitable Page Store folder does not exist, this method should return null. If a Page Store folder is returned, ContentCreator will modify this folder or its contents accordingly during move or rename operations. - requireMappedFolder()
must return a Page Store folder corresponding to the Site Store folder passed as a parameter. If a suitable Page Store folder does not exist yet, this method must create it. This method is used to determine where in the Page Store new page elements should be created or existing Page Store elements should be moved to.
Both methods should employ the same algorithm to map a Site Store folder passed as a parameter to a Page Store folder as a return value (provided the latter folder type exists) so that uses of the Store Mapper in which both methods are called in sequence provide consistent results according to the same selection rules.
public class ExampleStoreMapping implements WebeditStoreMappingPlugin {
private BaseContext _context;
@Override
public void setUp(@NotNull final BaseContext context) {
_context = context;
}
@Override
public void tearDown() {
}
@Override
@Nullable
public PageFolder requestMappedFolder(@NotNull final SiteStoreFolder folder) {
final PageFolder systemFolder = getWebClientSystemFolder();
Listable<PageFolder> systemFolderChildren = systemFolder.getChildren(PageFolder.class);
while (systemFolderChildren.iterator().hasNext()) {
PageFolder pf = systemFolderChildren.iterator().next();
if (pf.getUid().equals(folder.getUid())) {
return pf;
}
}
return null;
}
@Override
@NotNull
public PageFolder requireMappedFolder(@NotNull final SiteStoreFolder folder) {
final PageFolder mappedFolder = requestMappedFolder(folder);
if (mappedFolder == null) {
final PageFolder systemFolder = getWebClientSystemFolder();
final Map<Language, String> displayNames = new HashMap<Language, String>();
for (final Language editorialLanguage : folder.getStore().getProject().getEditorialLanguages()) {
displayNames.put(editorialLanguage, folder.getDisplayName(editorialLanguage));
}
try {
final PageFolder newFolder = systemFolder.createPageFolder(folder.getUid(), displayNames, false);
return newFolder;
} catch (ElementDeletedException e) {
// Handle exception if systemFolder is a deleted item.
} catch (LockException e) {
// Handle exception if systemFolder is currently being edited by another user.
} catch (DuplicateReferenceNameException e) {
// Handle exception if UID given to newFolder already exists in the Page Store.
} finally {
return systemFolder;
}
} else {
return mappedFolder;
}
}
/**
* Retrieve the WebClient System Folder defined in the project settings.
**/
@NotNull
private PageFolder getWebClientSystemFolder() {
final PageStoreRoot pageStoreRoot =
(PageStoreRoot) _context.requireSpecialist(StoreAgent.TYPE).getStore(Store.Type.PAGESTORE, false);
final Project project = pageStoreRoot.getProject();
final PageFolder systemFolder = project.getWebeditSystemFolder();
return systemFolder != null ? systemFolder : pageStoreRoot;
}
}