@SuppressWarnings("unchecked") @Override public T getObject() { return (T) itemModel.getObject(); }
/** * Determine whether the Item exists. This will retrieve the Item from the repository. * If the Item has been loaded in this request cycle (e.g. using {@link IModel#getObject}), but has since * been removed, the returned information may be incorrect. * * @return true when the Item exists */ public boolean exists() { checkLiveJcrSession(); return getObject() != null; }
/** * Retrieve the node from the repository. May return null when the node no longer exists or * the model was initially created with a null object. */ public Node getNode() { return (Node) getItemModel().getObject(); }
public Property getProperty() { return (Property) getItemModel().getObject(); }
private void addTemplate(JcrItemModel model) throws RepositoryException { Item item = (Item) model.getObject(); String name = item.getName(); Set<String> excluded = descriptor.getExcluded(); if (excluded == null || !excluded.contains(name)) { elements.addLast(new JcrNodeModel(model)); } } }
/** * The absolute JCR path for the Item. * * @return the absolute path */ public String getPath() { checkLiveJcrSession(); Item item = getObject(); if (item != null) { try { absPath = item.getPath(); return absPath; } catch (InvalidItemStateException e) { // ignore, item has been removed log.debug("Item " + absPath + " no longer exists", e); } catch (RepositoryException e) { log.error(e.getMessage(), e); } } return absPath; }
private static Node getCompoundNode(final JcrPropertyValueModel model) { JcrItemModel itemModel = model.getJcrPropertymodel().getItemModel(); final JcrItemModel nodeModel = itemModel.getParentModel(); return (Node) nodeModel.getObject(); }
@Override protected void loadElements() { if (elements != null) { return; } elements = new LinkedList<>(); try { Node node = (Node) getItemModel().getObject(); if (node != null) { // expand the name-pattern NodeIterator iterator = node.getNodes(descriptor.getPath()); while (iterator.hasNext()) { Node child = iterator.nextNode(); // add child if it is not excluded. // TODO: filter on node type addTemplate(new JcrItemModel(child)); } } } catch (RepositoryException ex) { log.error(ex.getMessage()); } }
private void writeObject(ObjectOutputStream output) throws IOException { if (isAttached()) { log.warn("Undetached JcrItemModel "+getPath()); T object = this.getObject(); if (object != null) { TraceMonitor.trace(object); } if (RuntimeConfigurationType.DEPLOYMENT.equals(Application.get().getConfigurationType())) { detach(); } } output.defaultWriteObject(); }
@Override public void remove(JcrNodeModel model) { load(); Iterator<JcrNodeModel> iterator = elements.iterator(); while (iterator.hasNext()) { JcrNodeModel currentModel = iterator.next(); if (model.equals(currentModel)) { iterator.remove(); try { JcrItemModel itemModel = model.getItemModel(); if (itemModel.exists()) { Item item = (Item) itemModel.getObject(); // remove the item log.info("removing item {}", item.getPath()); item.remove(); } else { log.info("item {} does not exist", itemModel.getPath()); } } catch (RepositoryException ex) { log.error(ex.getMessage(), ex); } } else { currentModel.detach(); } } }
@Override public void detach() { if (isAttached()) { T object = this.getObject(); if (object != null) { TraceMonitor.release(object); } } detaching = true; save(); super.detach(); detaching = false; }
@Override public void moveUp(JcrPropertyValueModel model) { load(); int index = model.getIndex(); if (descriptor.isMultiple() && index > 0) { try { Property property = (Property) getItemModel().getObject(); Value[] oldValues = property.getValues(); Value[] newValues = new Value[oldValues.length]; System.arraycopy(oldValues, 0, newValues, 0, oldValues.length); newValues[index] = oldValues[index - 1]; newValues[index - 1] = oldValues[index]; property.setValue(newValues); } catch (RepositoryException ex) { log.error(ex.getMessage()); } } else { log.error("Cannot move first value further up."); } }
@Override public void addNew() { load(); try { Node parent = (Node) getItemModel().getObject(); if (parent != null) { Node node; if (prototype != null) { HippoSession session = (HippoSession) UserSession.get().getJcrSession(); node = JcrUtils.copy(session, prototype.getNode().getPath(), parent.getPath() + "/" + descriptor.getPath()); } else { log.info("No prototype available to initialize child node for field {} with type {}", descriptor .getName(), descriptor.getTypeDescriptor().getType()); node = parent.addNode(descriptor.getPath(), descriptor.getTypeDescriptor().getType()); } elements.addLast(new JcrNodeModel(node)); } else { log.warn("No parent available to initialize child node"); } } catch (RepositoryException ex) { log.error("Error creating child node", ex); } }
if (predecessor != null) { try { Node parent = (Node) getItemModel().getObject(); String srcPath = model.getNode().getName() + (model.getNode().getIndex() > 1 ? "[" + model.getNode().getIndex() + "]" : "");
Node node = itemModel.getParentModel().getObject(); String path = itemModel.getPath(); String name = path.substring(path.lastIndexOf('/') + 1);
void process(Event event, EventCollection<IEvent<IClusterConfig>> collection) { processChanges(collection); if (event.getType() != 0) { try { String path = event.getPath(); path = path.substring(0, path.lastIndexOf('/')); JcrItemModel model = new JcrItemModel(path, false); Node root = getNode(); while (model != null && !root.isSame((Node) model.getObject())) { if (model.exists()) { Node node = (Node) model.getObject(); if (node.isNodeType(FrontendNodeType.NT_PLUGIN)) { IPluginConfig config = wrapConfig(node); collection.add(new ClusterConfigEvent(JcrClusterConfig.this, config, ClusterConfigEvent.EventType.PLUGIN_CHANGED)); break; } } model = model.getParentModel(); } } catch (RepositoryException ex) { log.error("unable to find plugin configuration for event", ex); } } else { collection.add(new ClusterConfigEvent(JcrClusterConfig.this, null, ClusterConfigEvent.EventType.PLUGIN_CHANGED)); } }
/** * Start the observation by listening to JCR {@link Event}s. */ @Override public void startObservation() { if (getItemModel().getObject() == null) { log.info("skipping observation for null node"); return; } if (getItemModel().getRelativePath() == null) { listener = new JcrEventListener(context, Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED | Event.NODE_MOVED, "/", true, new String[] { getItemModel().getUuid() }, null); } else { listener = new JcrEventListener(context, Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED | Event.NODE_MOVED, getItemModel().getPath(), false, null, null); } listener.start(); }
public PropertyDefinition getDefinition(int type, boolean multiValued) { Node node = (Node) getItemModel().getParentModel().getObject(); String path = getItemModel().getPath(); String name = path.substring(path.lastIndexOf('/') + 1);
Node node = (Node) parentModel.getObject(); node.setProperty(property.getItemModel().getPath().substring(parentModel.getPath().length() + 1), newValues); if (!property.getItemModel().exists()) {
try { if (getItemModel().exists()) { Property property = (Property) getItemModel().getObject(); if (property.getDefinition().isMultiple()) { Value[] values = property.getValues();