javax.jcr.observation.Event Java Examples
The following examples show how to use
javax.jcr.observation.Event.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CatalogDataResourceProviderManagerImpl.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
@Activate protected synchronized void activate(final ComponentContext ctx) throws LoginException, RepositoryException { // check enabled state if (resolver == null) { bundleContext = ctx.getBundleContext(); final Map<String, Object> map = new HashMap<>(); map.put(ResourceResolverFactory.SUBSERVICE, VIRTUAL_PRODUCTS_SERVICE); resolver = resolverFactory.getServiceResourceResolver(map); // Watch for events on the root to register/deregister virtual catalogs data roots at runtime // For each observed path create an event listener object which redirects the event to the main class final Session session = resolver.adaptTo(Session.class); if (session != null) { this.observationEventListeners = new EventListener[this.observationPaths.length]; for (int i = 0; i < this.observationPaths.length; i++) { this.observationEventListeners[i] = new EventListener() { public void onEvent(EventIterator events) { CatalogDataResourceProviderManagerImpl.this.onEvent(events); } }; session.getWorkspace() .getObservationManager() .addEventListener(this.observationEventListeners[i], Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED, this.observationPaths[i], // absolute path true, // isDeep null, // uuids null, // node types true); // noLocal } } // register all virtual catalog data definitions that already exist registerDataRoots(); } }
Example #2
Source File: ThumbnailGenerator.java From sling-samples with Apache License 2.0 | 5 votes |
protected void activate(ComponentContext context) throws Exception { supportedMimeTypes.put("image/jpeg", ".jpg"); supportedMimeTypes.put("image/png", ".png"); String contentPath = (String)context.getProperties().get(CONTENT_PATH_PROPERTY); session = repository.loginAdministrative(null); if (repository.getDescriptor(Repository.OPTION_OBSERVATION_SUPPORTED).equals("true")) { observationManager = session.getWorkspace().getObservationManager(); String[] types = { "nt:file" }; observationManager.addEventListener(this, Event.NODE_ADDED, contentPath, true, null, types, false); } }
Example #3
Source File: ThumbnailGenerator.java From sling-samples with Apache License 2.0 | 5 votes |
public void onEvent(EventIterator it) { while (it.hasNext()) { Event event = it.nextEvent(); try { if (event.getType() == Event.NODE_ADDED && !(event.getPath().contains("thumbnails"))) { log.info("new upload: {}", event.getPath()); Node addedNode = session.getRootNode().getNode(event.getPath().substring(1)); processNewNode(addedNode); log.info("finished processing of {}", event.getPath()); } } catch (Exception e) { log.error(e.getMessage(), e); } } }
Example #4
Source File: ConfirmedOrdersObserver.java From sling-samples with Apache License 2.0 | 5 votes |
protected void activate(ComponentContext context) throws Exception { session = repository.loginAdministrative(null); // Listen for changes to our orders if (repository.getDescriptor(Repository.OPTION_OBSERVATION_SUPPORTED).equals("true")) { observationManager = session.getWorkspace().getObservationManager(); final String[] types = { "nt:unstructured" }; final boolean isDeep = true; final boolean noLocal = true; final String path = SlingbucksConstants.ORDERS_PATH; observationManager.addEventListener(this, Event.PROPERTY_CHANGED | Event.PROPERTY_ADDED, path, isDeep, null, types, noLocal); log.info("Observing property changes to {} nodes under {}", Arrays.asList(types), path); } }
Example #5
Source File: VaultSyncServiceImpl.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Activate protected void activate(Config config) throws RepositoryException { List<SyncHandler> newSyncSpecs = new LinkedList<SyncHandler>(); for (String def : config.vault_sync_syncroots()) { SyncHandler spec = new SyncHandler(new File(def)); newSyncSpecs.add(spec); log.info("Added sync specification: {}", spec); } syncHandlers = newSyncSpecs.toArray(new SyncHandler[newSyncSpecs.size()]); enabled = config.vault_sync_enabled(); checkDelay = config.vault_sync_fscheckinterval() * 1000; log.info("Vault Sync service is {}", enabled ? "enabled" : "disabled"); if (enabled) { // setup session session = repository.loginAdministrative(null); // set up observation listener session.getWorkspace().getObservationManager().addEventListener( this, Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_CHANGED | Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED, "/", true /* isDeep */, null /* uuid */, null /* nodeTypeName */, true /* noLocal */ ); fsCheckThread = new Thread(this, "Vault Sync Thread"); fsCheckThread.setDaemon(true); fsCheckThread.start(); } }
Example #6
Source File: JcrNamespaceHandler.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void postProcess(BeanDefinitionBuilder definitionBuilder, Element element) { List<Element> eventTypes = DomUtils.getChildElementsByTagName(element, EVENT_TYPE); if (eventTypes != null && eventTypes.size() > 0) { // compute event type int eventType = 0; Constants types = new Constants(Event.class); for (Iterator<Element> iter = eventTypes.iterator(); iter.hasNext();) { Element evenTypeElement = iter.next(); eventType |= types.asNumber(DomUtils.getTextValue(evenTypeElement)).intValue(); } definitionBuilder.addPropertyValue("eventTypes", Integer.valueOf(eventType)); } List<Element> nodeTypeNames = DomUtils.getChildElementsByTagName(element, NODE_TYPE_NAME); String[] nodeTypeValues = new String[nodeTypeNames.size()]; for (int i = 0; i < nodeTypeValues.length; i++) { nodeTypeValues[i] = DomUtils.getTextValue(nodeTypeNames.get(i)); } definitionBuilder.addPropertyValue(NODE_TYPE_NAME, nodeTypeValues); List<Element> uuids = DomUtils.getChildElementsByTagName(element, UUID); String[] uuidsValues = new String[uuids.size()]; for (int i = 0; i < uuidsValues.length; i++) { uuidsValues[i] = DomUtils.getTextValue(uuids.get(i)); } definitionBuilder.addPropertyValue(UUID, uuidsValues); //TODO, reference a listenerBean, it is not a propertyReference Element eventListner = DomUtils.getChildElementByTagName(element, "listener"); String listenerBeanRefName = DomUtils.getTextValue(eventListner); definitionBuilder.addPropertyReference("listener", listenerBeanRefName); }
Example #7
Source File: CatalogDataResourceProviderManagerImpl.java From commerce-cif-connector with Apache License 2.0 | 4 votes |
/** * Handle resource events to add or remove virtual catalog data registrations. */ public void onEvent(EventIterator events) { try { // collect all actions to be performed for this event final Map<String, Boolean> actions = new HashMap<>(); boolean nodeAdded = false; boolean nodeRemoved = false; while (events.hasNext()) { final Event event = events.nextEvent(); final String path = event.getPath(); final int eventType = event.getType(); if (eventType == Event.NODE_ADDED) { nodeAdded = true; Session session = resolver.adaptTo(Session.class); final Node node = session.getNode(path); if (node != null && node.isNodeType(JcrResourceConstants.NT_SLING_FOLDER) && node.hasProperty( CatalogDataResourceProviderFactory.PROPERTY_FACTORY_ID) || node.hasProperty(CONF_ROOT)) { actions.put(path, true); } } else if (eventType == Event.NODE_REMOVED && providers.containsKey(path)) { nodeRemoved = true; actions.put(path, false); } else if ((eventType == Event.PROPERTY_CHANGED || eventType == Event.PROPERTY_ADDED || eventType == Event.PROPERTY_REMOVED) && isRelevantPath(path)) { // narrow down the properties to be watched. // force re-registering nodeAdded = true; nodeRemoved = true; } } for (Map.Entry<String, Boolean> action : actions.entrySet()) { if (action.getValue()) { final Resource rootResource = resolver.getResource(action.getKey()); if (rootResource != null) { registerDataRoot(rootResource); } } else { final ResourceProvider provider = providers.remove(action.getKey()); if (provider != null) { unregisterService(provider); } } } if (nodeAdded && nodeRemoved) { // maybe a virtual catalog was moved, re-register all virtual catalogs // (existing ones will be skipped) registerDataRoots(); } } catch (RepositoryException e) { log.error("Unexpected repository exception during event processing.", e); } }