use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class JcrNode method doGetProperty.
private Object doGetProperty(ResourceProxy resourceProxy, String propertyName) {
if (resourceProxy.getPath().equals(getJcrPath())) {
Map<String, Object> props = resourceProxy.getProperties();
if (props.containsKey(propertyName)) {
Object p0 = props.get(propertyName);
return p0;
}
} else {
List<ResourceProxy> resourceProxyChildren = resourceProxy.getChildren();
for (Iterator<ResourceProxy> it = resourceProxyChildren.iterator(); it.hasNext(); ) {
final ResourceProxy aChild = it.next();
final Object p1 = doGetProperty(aChild, propertyName);
if (p1 != null) {
return p1;
}
}
}
return null;
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class AddOrUpdateNodeCommand method update.
private void update(ResourceProxy resource, Session session) throws RepositoryException, IOException {
String path = resource.getPath();
boolean nodeExists = session.nodeExists(path);
Node node;
if (nodeExists) {
node = session.getNode(path);
getLogger().trace("Found existing node at {0} with primaryType {1}", path, node.getPrimaryNodeType().getName());
} else {
node = createNode(resource, session);
getLogger().trace("Created node at {0} with primaryType {1}", path, node.getPrimaryNodeType().getName());
}
if (nodeExists && getFlags().contains(CommandExecutionFlag.CREATE_ONLY_WHEN_MISSING)) {
return;
}
updateNode(node, resource);
processDeletedNodes(node, resource);
for (ResourceProxy child : resource.getCoveredChildren()) {
update(child, session);
}
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class VltNodeTypeFactory method initDeclaredFields.
private void initDeclaredFields(VltNodeType nt) {
final ResourceProxy child = nt.getResourceProxy();
String[] superTypeNamess = (String[]) child.getProperties().get("jcr:supertypes");
nt.setDeclaredSupertypeNames(superTypeNamess);
if (superTypeNamess != null) {
NodeType[] superTypes = new NodeType[superTypeNamess.length];
for (int i = 0; i < superTypeNamess.length; i++) {
superTypes[i] = getNodeType(superTypeNamess[i]);
}
nt.setDeclaredSupertypes(superTypes);
}
Set<VltNodeDefinition> nds = new HashSet<>();
for (ResourceProxy ntChild : child.getChildren()) {
String ntChildName = PathUtil.getName(ntChild.getPath());
if (ntChildName.startsWith("jcr:childNodeDefinition")) {
VltNodeDefinition nd = handleChildNodeDefinition(ntChild);
nds.add(nd);
} else if (ntChildName.startsWith("rep:residualChildNodeDefinitions")) {
// go through children
for (ResourceProxy residualChild : ntChild.getChildren()) {
nds.add(handleChildNodeDefinition(residualChild));
}
}
}
nt.setDeclaredChildNodeDefinitions(nds.toArray(new NodeDefinition[0]));
initDeclaredPropertyDefinitions(nt, child);
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class ContentXmlHandler method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
ResourceProxy current;
// name is equal to label except for SNS
String label = ISO9075.decode(qName);
String name = label;
// code mostly taken from {@link org.apache.jackrabbit.vault.fs.impl.io.DocViewSaxImporter}
DocViewNode node;
try {
node = new DocViewNode(name, label, attributes, npResolver);
if (qName.equals(JCR_ROOT)) {
current = root;
} else {
ResourceProxy parent = queue.peekLast();
StringBuilder path = new StringBuilder(parent.getPath());
if (path.charAt(path.length() - 1) != '/')
path.append('/');
path.append(qName);
current = new ResourceProxy(ISO9075.decode(path.toString()));
parent.addChild(current);
}
for (Map.Entry<String, DocViewProperty> entry : node.props.entrySet()) {
try {
Object typedValue = TypeHint.convertDocViewPropertyToTypedValue(entry.getValue());
// unsupported
if (typedValue == null) {
continue;
}
current.addProperty(entry.getKey(), typedValue);
} catch (Throwable t) {
Activator.getDefault().getPluginLogger().error("Could not parse property '" + entry.getValue().name, t);
}
}
queue.add(current);
} catch (NamespaceException e) {
Activator.getDefault().getPluginLogger().error("Could not resolve a JCR namespace.", e);
}
}
use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.
the class SimpleXmlSerializationManager method readSerializationData.
@Override
public ResourceProxy readSerializationData(String filePath, InputStream source) throws IOException {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
SerializationDataHandler h = new SerializationDataHandler();
saxParser.parse(new InputSource(source), h);
return new ResourceProxy(filePath, h.getResult());
} catch (ParserConfigurationException | SAXException e) {
// TODO proper exception handling
throw new RuntimeException(e);
}
}
Aggregations