public boolean isLeaf() { try { if (nodeModel != null) { Node node = nodeModel.getObject(); if (node != null) { return !node.getNodes().hasNext(); } } } catch (RepositoryException ex) { log.error(ex.getMessage()); } return true; }
/** * Loads child nodes. * @return loaded child nodes * @throws RepositoryException if repository exception occurs */ protected List<Node> loadChildNodes() throws RepositoryException { List<Node> childNodes = null; Node childNode; for (NodeIterator nodeIt = nodeModel.getObject().getNodes(); nodeIt.hasNext(); ) { childNode = nodeIt.nextNode(); if (childNode != null) { if (childNodes == null) { childNodes = new LinkedList<>(); } childNodes.add(childNode); } } return (childNodes != null) ? childNodes : Collections.emptyList(); }
public Iterator<NodeType> iterator(long first, long count) { List<NodeType> list = new ArrayList<NodeType>(); Node node = nodeModel.getObject(); if (node != null) { try { NodeType[] nodeTypes = node.getMixinNodeTypes(); list = Arrays.asList(nodeTypes); } catch (RepositoryException e) { log.error(e.getMessage()); } } return list.iterator(); }
public long size() { long result = 0; try { if (nodeModel.getObject() != null) { PropertyIterator it = nodeModel.getObject().getProperties(); result = it.getSize(); // result = result - 1; // For jcr:primaryType // result = nodeModel.getNode().hasProperty("jcr:mixinTypes") ? result -1 : result; } } catch (RepositoryException e) { log.error(e.getMessage()); } return result; }
private void ensureChildrenLoaded() { if (nodeModel.getObject() == null) { reloadChildren = false; reloadChildCount = false; children = new ArrayList<>(); childCount = 0; } else if (children == null || reloadChildren) { try { children = loadChildren(); childCount = children.size(); } catch (RepositoryException e) { log.warn("Unable to load children, setting empty list: " + e.getMessage()); children = new ArrayList<>(); childCount = 0; } reloadChildren = false; reloadChildCount = false; } }
public boolean isValid(IDetachable targetId, String facetSelectPath) { if (!isValid(targetId)) { return false; } if (facetSelectPath == null) { return false; } if (facetSelectPath.indexOf('/') <= 0) { return false; } String docsub = facetSelectPath.substring(facetSelectPath.indexOf('/') + 1); if (!docsub.startsWith("{_document}/")) { return false; } String resource = docsub.substring(docsub.indexOf('/') + 1); if (resource.indexOf('/') > 0) { return false; } JcrNodeModel selectedModel = (JcrNodeModel) targetId; Node node = selectedModel.getObject(); try { node = node.getNode(node.getName()); return node.hasNode(resource); } catch (RepositoryException e) { log.error(e.getMessage()); } return false; }
@Override public int getChildCount() { Node jcrNode = this.nodeModel.getObject(); if (jcrNode instanceof HippoNode) { try { final HippoNode hippoNode = (HippoNode) jcrNode; // do not count for virtual nodes w.r.t performance if (hippoNode.isVirtual()) { return 0; } } catch (RepositoryException e) { log.warn("Unable to get child count", e); } } return super.getChildCount(); }
@Override public void setMultiple(boolean multiple) { delegate.setMultiple(multiple); try { updateItem(getPrototype().getObject(), delegate.getPath(), delegate); } catch (RepositoryException ex) { log.error("Failed to update prototype", ex); } catch (BuilderException ex) { log.error("Failed to find prototype when updating the path", ex); } }
public boolean isValid(IDetachable targetId) { if (!(targetId instanceof JcrNodeModel)) { return false; } JcrNodeModel selectedModel = (JcrNodeModel) targetId; Node node = selectedModel.getObject(); if (node == null) { return false; } try { return node.isNodeType("mix:referenceable"); } catch (RepositoryException e) { log.error(e.getMessage()); return false; } }
private String getCaptionProperty(final String propertyName) { final String shortName = getShortName(propertyName); JcrNodeModel nodeModel = getNodeModel(); if (nodeModel == null) { return null; } try { final Node templateNode = TranslatorUtils.getTemplateNode(nodeModel.getObject()); Node fieldTypeNode = templateNode.getNode(shortName); if (fieldTypeNode != null && fieldTypeNode.isNodeType(FrontendNodeType.NT_PLUGIN)) { return fieldTypeNode.getProperty(TranslatorUtils.CAPTION_PROPERTY).getString(); } else { log.debug("Cannot find the field node type '{}'", propertyName); } } catch (TranslatorException | RepositoryException e) { log.debug("Cannot retrieve caption property of the field '{}'", propertyName, e); } return null; }
@Override public List<PropertyDescriptor> getPropertyDescriptors() { Node node = getNodeModel().getObject(); List<String> properties = getList(FrontendNodeType.FRONTEND_PROPERTIES); List<PropertyDescriptor> descriptors = new ArrayList<>(properties.size()); for (String name : properties) { int type = DEFAULT_TYPE; boolean multiple = DEFAULT_MULTIPLICITY; try { if (node.hasProperty(name)) { Property prototype = node.getProperty(name); type = prototype.getType(); multiple = prototype.isMultiple(); } descriptors.add(new PropertyDescriptor(name, type, multiple)); } catch (RepositoryException e) { log.error("cannot get create property descriptor for property " + name, e); } } return descriptors; }
public Iterator<Property> iterator(long first, long count) { List<Property> list = new ArrayList<Property>(); try { if (nodeModel.getObject() != null) { PropertyIterator it = nodeModel.getObject().getProperties(); if (it.getSize() > 0) { it.skip(first); for (int i = 0; i < count && it.hasNext(); i++) { Property prop = it.nextProperty(); // boolean isPrimaryType = prop.getName().equals("jcr:primaryType"); // boolean isMixinTypes = prop.getName().equals("jcr:mixinTypes"); // if (!isPrimaryType && !isMixinTypes) { list.add(prop); // } } } } } catch (InvalidItemStateException e) { // This can happen after a node has been deleted and the tree hasn't been refreshed yet } catch (RepositoryException e) { log.error(e.getMessage()); } return list.iterator(); }
public String getDefaultFacetSelectPath(IDetachable targetId) { if (!isValid(targetId)) { return null; } JcrNodeModel selectedModel = (JcrNodeModel) targetId; Node node = selectedModel.getObject(); try { if (node.isNodeType("hippo:handle")) { node = node.getNode(node.getName()); Item primary = JcrHelper.getPrimaryItem(node); for (NodeIterator children = node.getNodes(); children.hasNext();) { Node child = children.nextNode(); if (primary.isSame(child)) { continue; } if (child.isNodeType("hippo:resource")) { return node.getName() + "/{_document}/" + child.getName(); } } return node.getName() + "/{_document}/" + primary.getName(); } } catch (RepositoryException e) { log.error(e.getMessage()); } return null; }
private boolean isValid(IDetachable targetId) { if (!(targetId instanceof JcrNodeModel)) { return false; } JcrNodeModel selectedModel = (JcrNodeModel) targetId; Node node = selectedModel.getObject(); if (node == null) { return false; } try { if (node.isNodeType("hippo:handle")) { Node doc = node.getNode(node.getName()); Item primary = JcrHelper.getPrimaryItem(doc); return (primary.isNode() && ((Node) primary).isNodeType("hippo:resource")); } } catch (RepositoryException e) { log.error(e.getMessage()); } return false; }
public JcrNodeModel getPrototype() throws BuilderException { if (prototype == null || prototype.getObject() == null) { prototype = prototypeStore.getPrototype(type, true); if (prototype == null) { if (readonly) { prototype = prototypeStore.getPrototype(type, false); if (prototype == null) { throw new BuilderException("No prototype found"); } } else { prototype = prototypeStore.createPrototype(type, true); if (prototype == null) { throw new BuilderException("No prototype could be created for " + type); } } } paths = new HashMap<>(); for (Map.Entry<String, IFieldDescriptor> entry : typeDescriptor.getFields().entrySet()) { paths.put(entry.getKey(), entry.getValue().getPath()); } } return prototype; }
attached = true; try { Node reportNode = nodeModel.getObject(); if (reportNode.isNodeType(ReportingNodeTypes.NT_REPORT)) { Node queryNode = reportNode.getNode(ReportingNodeTypes.QUERY);
private void load() { if (locales == null) { locales = new TreeMap<String, HippoLocale>(); Node document = model.getObject(); if (document != null) { try { String id = document.getProperty(HippoTranslationNodeType.ID).getString(); Query query = document.getSession().getWorkspace().getQueryManager().createQuery( "SELECT " + HippoTranslationNodeType.LOCALE + " FROM " + HippoTranslationNodeType.NT_TRANSLATED + " WHERE " + HippoTranslationNodeType.ID + "='" + id + "'", Query.SQL); final QueryResult result = query.execute(); final RowIterator rowIterator = result.getRows(); while (rowIterator.hasNext()) { final Row row = rowIterator.nextRow(); final Value value = row.getValue(HippoTranslationNodeType.LOCALE); HippoLocale locale = provider.getLocale(value.getString()); locales.put(locale.getName(), locale); } } catch (RepositoryException ex) { log.error("Error retrieving translations of document " + model.getItemModel().getPath()); } } } }