Class AbstractClientlibVisitor
- java.lang.Object
-
- com.composum.sling.clientlibs.processor.AbstractClientlibVisitor
-
- All Implemented Interfaces:
ClientlibVisitor
- Direct Known Subclasses:
ClientlibDebugConsolePlugin.DebugVisitor
,ProcessingVisitor
,ProcessingVisitor.ExcludeDependenciesVisitor
,RenderingVisitor
,UpdateTimeVisitor
public abstract class AbstractClientlibVisitor extends Object implements ClientlibVisitor
Base class for visitors to aid processing of all parts of a client library.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.composum.sling.clientlibs.handle.ClientlibVisitor
ClientlibVisitor.VisitorMode
-
-
Field Summary
Fields Modifier and Type Field Description protected long
embeddedHash
protected boolean
hasEmbeddedFiles
static Pattern
HASH_PATTERN
Matches the results ofgetHash()
.protected static org.slf4j.Logger
LOG
protected ClientlibElement
owner
The clientlib or category which this visitor processes - i.e., which owns embedded stuff.protected LinkedHashSet<ClientlibLink>
processedElements
protected org.apache.sling.api.resource.ResourceResolver
resolver
protected ClientlibService
service
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractClientlibVisitor(ClientlibElement owner, ClientlibService service, org.apache.sling.api.resource.ResourceResolver resolver, LinkedHashSet<ClientlibLink> processedElements)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
action(ClientlibCategory clientlibCategory, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Optional action to take after visiting the element.protected void
action(ClientlibExternalUri externalUri, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Optional action to take after visiting the element.protected void
action(ClientlibFile file, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Optional action to take after visiting the element.protected void
action(Clientlib clientlib, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Optional action to take after visiting the element.protected void
action(ClientlibResourceFolder folder, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Optional action to take after visiting the element.protected void
alreadyProcessed(ClientlibRef ref, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder folder)
Hook for additional checks about already processed elements.protected abstract ClientlibVisitor
createVisitorFor(ClientlibElement element)
Creates a new visitor for the given clientlib or category as owner.ClientlibVisitor
execute()
Triggers the processing of theClientlibVisitor.getOwner()
by callingClientlibElement.accept(ClientlibVisitor, VisitorMode, ClientlibResourceFolder)
.String
getHash()
Hash consisting of the updatetimes and paths of all embedded files, which should be sufficient to identify any changes as a strong HTTP ETag.ClientlibElement
getOwner()
The ClientlibElement (clientlib or category) whose embedded elements this visitor processes; clientlibs or categories as dependency will be processed by their own visitor.Set<ClientlibLink>
getProcessedElements()
protected ClientlibVisitor
getVisitorFor(ClientlibVisitor.VisitorMode mode, ClientlibElement element)
Returns the appropriate visitor for the given mode and element: if mode=DEPENDS and element is a clientlib or category.protected boolean
isNotProcessed(ClientlibRef ref)
Checks whether something matching this reference has already beenmarkAsProcessed(ClientlibLink, ClientlibResourceFolder, VisitorMode)
.protected void
markAsProcessed(ClientlibLink link, ClientlibResourceFolder parent, ClientlibVisitor.VisitorMode visitorMode)
Marks a link processed for current clientlib call (that is, clientlib tag call).protected void
notPresent(ClientlibRef ref, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Hook for additional checks about an element referenced but not present.protected List<ClientlibElement>
removeMinificationDuplicates(List<ClientlibElement> children)
protected void
resolveAndAccept(ClientlibRef ref, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder folder)
protected boolean
supportsEmbedding(Clientlib.Type type)
protected void
updateHash(String path, Calendar updatetime)
void
visit(ClientlibCategory category, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
void
visit(ClientlibExternalUri externalUri, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
void
visit(ClientlibFile file, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
void
visit(Clientlib clientlib, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
void
visit(ClientlibResourceFolder folder, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
-
-
-
Field Detail
-
LOG
protected static final org.slf4j.Logger LOG
-
service
protected final ClientlibService service
-
resolver
protected final org.apache.sling.api.resource.ResourceResolver resolver
-
processedElements
protected final LinkedHashSet<ClientlibLink> processedElements
-
owner
protected final ClientlibElement owner
The clientlib or category which this visitor processes - i.e., which owns embedded stuff.
-
embeddedHash
protected long embeddedHash
-
hasEmbeddedFiles
protected boolean hasEmbeddedFiles
-
-
Constructor Detail
-
AbstractClientlibVisitor
protected AbstractClientlibVisitor(ClientlibElement owner, ClientlibService service, org.apache.sling.api.resource.ResourceResolver resolver, LinkedHashSet<ClientlibLink> processedElements)
-
-
Method Detail
-
getOwner
public ClientlibElement getOwner()
Description copied from interface:ClientlibVisitor
The ClientlibElement (clientlib or category) whose embedded elements this visitor processes; clientlibs or categories as dependency will be processed by their own visitor.- Specified by:
getOwner
in interfaceClientlibVisitor
-
execute
public ClientlibVisitor execute() throws IOException, javax.jcr.RepositoryException
Description copied from interface:ClientlibVisitor
Triggers the processing of theClientlibVisitor.getOwner()
by callingClientlibElement.accept(ClientlibVisitor, VisitorMode, ClientlibResourceFolder)
.- Specified by:
execute
in interfaceClientlibVisitor
- Returns:
- this
- Throws:
IOException
javax.jcr.RepositoryException
-
getVisitorFor
protected ClientlibVisitor getVisitorFor(ClientlibVisitor.VisitorMode mode, ClientlibElement element)
Returns the appropriate visitor for the given mode and element: if mode=DEPENDS and element is a clientlib or category.
-
createVisitorFor
protected abstract ClientlibVisitor createVisitorFor(ClientlibElement element)
Creates a new visitor for the given clientlib or category as owner. That'll usually be of the same type as ourselves. Caution: they have to share the sameprocessedElements
set!
-
visit
public void visit(ClientlibCategory category, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent) throws IOException, javax.jcr.RepositoryException
- Specified by:
visit
in interfaceClientlibVisitor
- Throws:
IOException
javax.jcr.RepositoryException
-
visit
public void visit(Clientlib clientlib, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent) throws IOException, javax.jcr.RepositoryException
- Specified by:
visit
in interfaceClientlibVisitor
- Throws:
IOException
javax.jcr.RepositoryException
-
visit
public void visit(ClientlibResourceFolder folder, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent) throws IOException, javax.jcr.RepositoryException
- Specified by:
visit
in interfaceClientlibVisitor
- Throws:
IOException
javax.jcr.RepositoryException
-
removeMinificationDuplicates
protected List<ClientlibElement> removeMinificationDuplicates(List<ClientlibElement> children)
-
visit
public void visit(ClientlibFile file, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent) throws javax.jcr.RepositoryException, IOException
- Specified by:
visit
in interfaceClientlibVisitor
- Throws:
javax.jcr.RepositoryException
IOException
-
visit
public void visit(ClientlibExternalUri externalUri, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
- Specified by:
visit
in interfaceClientlibVisitor
-
resolveAndAccept
protected void resolveAndAccept(ClientlibRef ref, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder folder) throws IOException, javax.jcr.RepositoryException
- Throws:
IOException
javax.jcr.RepositoryException
-
alreadyProcessed
protected void alreadyProcessed(ClientlibRef ref, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder folder)
Hook for additional checks about already processed elements.
-
notPresent
protected void notPresent(ClientlibRef ref, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Hook for additional checks about an element referenced but not present. Default: debuglog.
-
getHash
public String getHash()
Hash consisting of the updatetimes and paths of all embedded files, which should be sufficient to identify any changes as a strong HTTP ETag. That's an URL-safe string with 11 characters containing digits, letters and - or _ .
-
isNotProcessed
protected boolean isNotProcessed(ClientlibRef ref)
Checks whether something matching this reference has already beenmarkAsProcessed(ClientlibLink, ClientlibResourceFolder, VisitorMode)
.
-
markAsProcessed
protected void markAsProcessed(ClientlibLink link, ClientlibResourceFolder parent, ClientlibVisitor.VisitorMode visitorMode)
Marks a link processed for current clientlib call (that is, clientlib tag call).
-
getProcessedElements
public Set<ClientlibLink> getProcessedElements()
-
supportsEmbedding
protected boolean supportsEmbedding(Clientlib.Type type)
-
action
protected void action(ClientlibCategory clientlibCategory, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Optional action to take after visiting the element. Default : empty.
-
action
protected void action(Clientlib clientlib, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Optional action to take after visiting the element. Default : empty.
-
action
protected void action(ClientlibResourceFolder folder, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Optional action to take after visiting the element. Default : empty.
-
action
protected void action(ClientlibFile file, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent) throws javax.jcr.RepositoryException, IOException
Optional action to take after visiting the element. Default : empty.- Throws:
javax.jcr.RepositoryException
IOException
-
action
protected void action(ClientlibExternalUri externalUri, ClientlibVisitor.VisitorMode mode, ClientlibResourceFolder parent)
Optional action to take after visiting the element. Default : empty.
-
-