org.apache.sling.api.SlingConstants Java Examples

The following examples show how to use org.apache.sling.api.SlingConstants. 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: CacheableResource.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
public CacheableResource(RemoteStorageProvider remoteStorageProvider, RemoteResourceReference remoteResourceReference, String path,
                         Map<String, Object> properties) {
    this.remoteStorageProvider = remoteStorageProvider;
    this.remoteResourceReference = remoteResourceReference;
    this.path = path;
    resourceType = Optional.of((String) properties.get(ResourceResolver.PROPERTY_RESOURCE_TYPE)).orElse(NT_UNSTRUCTURED);
    resourceSuperType = (String) properties.get(SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_SUPER_TYPE);
    valueMap = new ValueMapDecorator(Collections.unmodifiableMap(properties));
    resourceMetadata = new ResourceMetadata();
    resourceMetadata.setCreationTime(remoteResourceReference.getCreated());
    resourceMetadata.setModificationTime(remoteResourceReference.getLastModified());
    if (remoteResourceReference.getType() == RemoteResourceReference.Type.FILE) {
        resourceMetadata.setContentLength(remoteResourceReference.getSize());
    }
}
 
Example #2
Source File: ReplicatedScriptLauncher.java    From APM with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized JobResult process(Job job) {
  JobResult result = JobResult.FAILED;
  final String searchPath = job.getProperty(SlingConstants.PROPERTY_PATH).toString();
  final Script script = getScript(searchPath);
  if (script != null) {
    final String userId = getUserId(script);
    result = SlingHelper
        .resolveDefault(resolverFactory, userId, resolver -> runReplicated(resolver, script), JobResult.FAILED);
  } else {
    logger.warn("Replicated script cannot be found by script manager: {}", searchPath);
  }
  return result;
}
 
Example #3
Source File: AutoclosableResourceResolver.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
private void resourceResolverShouldBeIgnoredWhenResolverFactoryIsExecutedInMethodFromDifferentClass(
    Event event, List<String> attributesList) {
  if (attributesList.containsAll(ATTRIBUTES)) {
    String path = (String) event.getProperty(SlingConstants.PROPERTY_PATH);
    try {
      SlingHelper.operate(resolverFactory, resolver -> processPackage(resolver, path));
    } catch (OperateException e) {
      System.out.println("something went wrong");
    }
  }
}
 
Example #4
Source File: ErrorHandler.java    From publick-sling-blog with Apache License 2.0 5 votes vote down vote up
@Override
public void activate() {
    SlingHttpServletRequest request = getRequest();
    SlingHttpServletResponse response = getResponse();
    ResourceResolver resolver = getResourceResolver();

    isAnonymous = "anonymous".equals(resolver.adaptTo(Session.class).getUserID());

    message = (String) request.getAttribute(SlingConstants.ERROR_MESSAGE);
    Integer scObject = (Integer) request.getAttribute(SlingConstants.ERROR_STATUS);

    code = (scObject != null) ? scObject.intValue() : response.SC_INTERNAL_SERVER_ERROR;

    if (message == null) {
        message = statusToString(code);
    }

    // Print stack trace only if the user is not anonymous
    if (!isAnonymous) {
        if (request.getAttribute(SlingConstants.ERROR_EXCEPTION) instanceof Throwable) {
            Throwable throwable = (Throwable) request.getAttribute(SlingConstants.ERROR_EXCEPTION);
            printStackTrace(throwable);
        }
    }

    response.setStatus(code);
    response.setContentType("text/html"); 
    response.setCharacterEncoding("utf-8");
}
 
Example #5
Source File: SampleFelixResourceListener.java    From aem-osgi-annotation-demo with Apache License 2.0 4 votes vote down vote up
public void handleEvent(final Event event) {
    logger.info("Felix EventHander: {} at: {}",
        event.getTopic(), event.getProperty(SlingConstants.PROPERTY_PATH));
}
 
Example #6
Source File: SampleOsgiResourceListener.java    From aem-osgi-annotation-demo with Apache License 2.0 4 votes vote down vote up
public void handleEvent(final Event event) {
    logger.info("OSGi EventHandler: {} at: {}",
            event.getTopic(), event.getProperty(SlingConstants.PROPERTY_PATH));
}
 
Example #7
Source File: ReplicationConsumer.java    From APM with Apache License 2.0 4 votes vote down vote up
public void run(String scriptPath) {
  Map<String, Object> properties = Collections.singletonMap(SlingConstants.PROPERTY_PATH, scriptPath);
  jobManager.addJob(ReplicatedScriptLauncher.JOB_NAME, properties);
}
 
Example #8
Source File: SimpleResourceListener.java    From aem-ide-tooling-4-intellij with Apache License 2.0 4 votes vote down vote up
public void  handleEvent(final Event event) {
    logger.debug("Resource event: {} at: {}", event.getTopic(), event.getProperty(SlingConstants.PROPERTY_PATH));
}