use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class VltNodeTypeFactory method initDeclaredPropertyDefinitions.
private void initDeclaredPropertyDefinitions(VltNodeType nt, ResourceProxy child) {
Map<String, VltPropertyDefinition> pds = new HashMap<>();
// load propertyDefinition children
for (ResourceProxy aChild : child.getChildren()) {
String childName = PathUtil.getName(aChild.getPath());
if (childName.startsWith("jcr:propertyDefinition")) {
String jcrName = (String) aChild.getProperties().get("jcr:name");
if (jcrName != null) {
VltPropertyDefinition pd = new VltPropertyDefinition();
pd.setName(jcrName);
Boolean autoCreated = (Boolean) aChild.getProperties().get("jcr:autoCreated");
if (autoCreated != null) {
pd.setAutoCreated(autoCreated);
}
Boolean multiple = (Boolean) aChild.getProperties().get("jcr:multiple");
if (multiple != null) {
pd.setMultiple(multiple);
}
Boolean mandatory = (Boolean) aChild.getProperties().get("jcr:mandatory");
if (mandatory != null) {
pd.setMandatory(mandatory);
}
Boolean isProtected = (Boolean) aChild.getProperties().get("jcr:protected");
if (isProtected != null) {
pd.setProtected(isProtected);
}
final Object object = aChild.getProperties().get("jcr:requiredType");
if (object != null) {
String requiredType = (String) object;
if (requiredType != null) {
pd.setRequiredType(propertyTypeFromName(requiredType));
}
}
pds.put(jcrName, pd);
}
}
}
// load mandatory
String[] mandatoryProperties = (String[]) child.getProperties().get("rep:mandatoryProperties");
if (mandatoryProperties != null) {
for (int i = 0; i < mandatoryProperties.length; i++) {
String aMandatoryProperty = mandatoryProperties[i];
VltPropertyDefinition vpd = pds.get(aMandatoryProperty);
if (vpd == null) {
vpd = new VltPropertyDefinition();
vpd.setName(aMandatoryProperty);
pds.put(aMandatoryProperty, vpd);
}
vpd.setMandatory(true);
}
}
// load protected
String[] protectedProperties = (String[]) child.getProperties().get("rep:protectedProperties");
if (protectedProperties != null) {
for (int i = 0; i < protectedProperties.length; i++) {
String aProtectedProperties = protectedProperties[i];
VltPropertyDefinition vpd = pds.get(aProtectedProperties);
if (vpd == null) {
vpd = new VltPropertyDefinition();
vpd.setName(aProtectedProperties);
pds.put(aProtectedProperties, vpd);
}
vpd.setProtected(true);
}
}
nt.setDeclaredPropertyDefinitions(pds.values().toArray(new VltPropertyDefinition[pds.size()]));
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class JcrNode method getPropertyType.
public int getPropertyType(String propertyName) {
PropertyDefinition pd = getPropertyDefinition(propertyName);
if (pd != null) {
return pd.getRequiredType();
}
// otherwise use the SerializationManager to read the
// underlying vault file and derive the propertyType from there
GenericJcrRootFile u = properties.getUnderlying();
if (u == null) {
// no underlying properties file, that's not good
Activator.getDefault().getPluginLogger().warn("No underlying properties file, cannot derive propertyType (" + propertyName + ") for " + this);
return -1;
}
IFolder contentSyncRoot = ProjectUtil.getSyncDirectory(getProject());
IFile file = (IFile) u.file;
try (InputStream contents = file.getContents()) {
String resourceLocation = file.getFullPath().makeRelativeTo(contentSyncRoot.getFullPath()).toPortableString();
ResourceProxy resourceProxy = Activator.getDefault().getSerializationManager().readSerializationData(resourceLocation, contents);
// resourceProxy could be containing a full tree
// dive into the right position
String rawValue = properties.getValue(propertyName);
return PropertyTypeSupport.propertyTypeOfString(rawValue);
} catch (Exception e) {
Activator.getDefault().getPluginLogger().warn("Exception occurred during analyzing propertyType (" + propertyName + ") for " + this, e);
}
return -1;
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ResourceChangeCommandFactory method normaliseResourceChildren.
/**
* Normalises the of the specified <tt>resourceProxy</tt> by comparing the serialization data and the filesystem
* data
*
* @param serializationFile the file which contains the serialization data
* @param resourceProxy the resource proxy
* @param syncDirectory the sync directory
* @param repository TODO
* @throws CoreException
*/
private void normaliseResourceChildren(IFile serializationFile, ResourceProxy resourceProxy, IFolder syncDirectory, Repository repository) throws CoreException {
// TODO - this logic should be moved to the serializationManager
try {
SerializationKindManager skm = new SerializationKindManager();
skm.init(repository);
String primaryType = (String) resourceProxy.getProperties().get(Repository.JCR_PRIMARY_TYPE);
List<String> mixinTypesList = getMixinTypes(resourceProxy);
SerializationKind serializationKind = skm.getSerializationKind(primaryType, mixinTypesList);
if (serializationKind == SerializationKind.METADATA_FULL) {
return;
}
} catch (RepositoryException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed creating a " + SerializationDataBuilder.class.getName(), e));
}
IPath serializationDirectoryPath = serializationFile.getFullPath().removeLastSegments(1);
Iterator<ResourceProxy> childIterator = resourceProxy.getChildren().iterator();
Map<String, IResource> extraChildResources = new HashMap<>();
for (IResource member : serializationFile.getParent().members()) {
if (member.equals(serializationFile)) {
continue;
}
extraChildResources.put(member.getName(), member);
}
while (childIterator.hasNext()) {
ResourceProxy child = childIterator.next();
String childName = PathUtil.getName(child.getPath());
String osPath = serializationManager.getOsPath(childName);
// covered children might have a FS representation, depending on their child nodes, so
// accept a directory which maps to their name
extraChildResources.remove(osPath);
// covered children do not need a filesystem representation
if (resourceProxy.covers(child.getPath())) {
continue;
}
IPath childPath = serializationDirectoryPath.append(osPath);
IResource childResource = ResourcesPlugin.getWorkspace().getRoot().findMember(childPath);
if (childResource == null) {
Activator.getDefault().getPluginLogger().trace("For resource at with serialization data {0} the serialized child resource at {1} does not exist in the filesystem and will be ignored", serializationFile, childPath);
childIterator.remove();
}
}
for (IResource extraChildResource : extraChildResources.values()) {
IPath extraChildResourcePath = extraChildResource.getFullPath().makeRelativeTo(syncDirectory.getFullPath()).makeAbsolute();
resourceProxy.addChild(new ResourceProxy(serializationManager.getRepositoryPath(extraChildResourcePath.toPortableString())));
Activator.getDefault().getPluginLogger().trace("For resource at with serialization data {0} the found a child resource at {1} which is not listed in the serialized child resources and will be added", serializationFile, extraChildResource);
}
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ResourceChangeCommandFactory method buildResourceProxy.
private ResourceProxy buildResourceProxy(String resourceLocation, IResource serializationResource, IFolder syncDirectory, String fallbackPrimaryType, Repository repository) throws CoreException, IOException {
if (serializationResource instanceof IFile) {
IFile serializationFile = (IFile) serializationResource;
try (InputStream contents = serializationFile.getContents()) {
String serializationFilePath = serializationResource.getFullPath().makeRelativeTo(syncDirectory.getFullPath()).toPortableString();
ResourceProxy resourceProxy = serializationManager.readSerializationData(serializationFilePath, contents);
normaliseResourceChildren(serializationFile, resourceProxy, syncDirectory, repository);
return resourceProxy;
}
}
return new ResourceProxy(serializationManager.getRepositoryPath(resourceLocation), Collections.singletonMap(Repository.JCR_PRIMARY_TYPE, (Object) fallbackPrimaryType));
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ResourceChangeCommandFactory method removeFileCommand.
private Command<?> removeFileCommand(Repository repository, IResource resource) throws CoreException, IOException {
if (resource.isTeamPrivateMember(IResource.CHECK_ANCESTORS)) {
Activator.getDefault().getPluginLogger().trace("Skipping team-private resource {0}", resource);
return null;
}
if (ignoredFileNames.contains(resource.getName())) {
return null;
}
IFolder syncDirectory = ProjectUtil.getSyncDirectory(resource.getProject());
Filter filter = ProjectUtil.loadFilter(syncDirectory.getProject());
FilterResult filterResult = getFilterResult(resource, null, filter);
if (filterResult == FilterResult.DENY || filterResult == FilterResult.PREREQUISITE) {
return null;
}
String resourceLocation = getRepositoryPathForDeletedResource(resource, ProjectUtil.getSyncDirectoryFile(resource.getProject()));
// verify whether a resource being deleted does not signal that the content structure
// was rearranged under a covering parent aggregate
IPath serializationFilePath = Path.fromOSString(serializationManager.getSerializationFilePath(resourceLocation, SerializationKind.FOLDER));
ResourceProxy coveringParentData = findSerializationDataFromCoveringParent(resource, syncDirectory, resourceLocation, serializationFilePath);
if (coveringParentData != null) {
Activator.getDefault().getPluginLogger().trace("Found covering resource data ( repository path = {0} ) for resource at {1}, skipping deletion and performing an update instead", coveringParentData.getPath(), resource.getFullPath());
FileInfo info = createFileInfo(resource);
return repository.newAddOrUpdateNodeCommand(new CommandContext(filter), info, coveringParentData);
}
return repository.newDeleteNodeCommand(serializationManager.getRepositoryPath(resourceLocation));
}
Aggregations