Class AbstractContentTypeUpgradeOperation
- java.lang.Object
-
- org.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation<String>
-
- org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
-
- org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
-
- org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentTypeUpgradeOperation
-
- All Implemented Interfaces:
org.craftercms.commons.upgrade.UpgradeOperation<String>
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.web.context.ServletContextAware
- Direct Known Subclasses:
BoxRemoteAssetUpgradeOperation
public abstract class AbstractContentTypeUpgradeOperation extends AbstractContentUpgradeOperation
Base implementation ofUpgradeOperation
for all content-type related upgradesSupported YAML properties:
- includedContentTypes: (optional) list of content-types that can be handled by this operation, if left unset all content-types will be included
- formDefinitionXpath: (optional) XPath selector to evaluate if a content-type should be handled by this operation, if left unset all content-types will be included
- maxCacheItems: (optional) maximum number of items in the cache, can be used for performance tuning in case an upgrade needs to parse too many files in the repository. Defaults to 200
- Author:
- joseross
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
AbstractContentUpgradeOperation.ListFileVisitor
-
-
Field Summary
Fields Modifier and Type Field Description protected com.google.common.cache.Cache<Path,Document>
cache
Cache used to avoid parsing the same file multiple times during the execution of this operationstatic String
CONFIG_KEY_CONTENT_TYPES
static String
CONFIG_KEY_FORM_DEFINITION
static String
CONFIG_KEY_MAX_ITEMS
protected String
contentTypeXpath
XPath to query the content-type of item descriptorsstatic int
DEFAULT_MAX_ITEMS
protected DocumentBuilderFactory
factory
protected String
formDefinitionTemplate
Path template to find the form-definition.xml file for a content-typeprotected String
formDefinitionXpath
XPath to evaluate if a content-type can be handled by this operation (optional)protected List<String>
includedContentTypes
List of content-types that can be handled by this operation (optional)static String
NAME_PLACEHOLDER
protected TransformerFactory
transformerFactory
protected XPathFactory
xPathFactory
-
Fields inherited from class org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
CONFIG_KEY_INCLUDED_PATHS, includedPaths
-
Fields inherited from class org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
changedFiles, commitDetails, CONFIG_KEY_COMMIT_DETAILS, deletedFiles, servletContext, studioConfiguration
-
-
Constructor Summary
Constructors Constructor Description AbstractContentTypeUpgradeOperation(StudioConfiguration studioConfiguration, String contentTypeXpath, String formDefinitionTemplate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doInit(org.apache.commons.configuration2.HierarchicalConfiguration config)
protected Path
getFormDefinition(StudioUpgradeContext context, String contentTypeName)
Finds the form-definition.xml five for the given content-typeprotected Document
loadDocument(Path file)
Parses the given XML fileprotected Object
select(Object source, String xpath, QName type)
Evaluates a XPath selector on the given objectprotected boolean
shouldBeUpdated(StudioUpgradeContext context, Path file)
Indicates if the given file should be updated by this classprotected void
writeFile(Path file, Document document)
Writes an XML file to the file system without committing any changes in the repository-
Methods inherited from class org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
doExecute, filterPaths, findIncludedPaths, readFile, updateFile, writeFile
-
Methods inherited from class org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
commitAllChanges, doExecute, getCommitMessage, init, loadResource, setServletContext, trackChangedFiles, trackDeletedFiles
-
-
-
-
Field Detail
-
CONFIG_KEY_CONTENT_TYPES
public static final String CONFIG_KEY_CONTENT_TYPES
- See Also:
- Constant Field Values
-
CONFIG_KEY_FORM_DEFINITION
public static final String CONFIG_KEY_FORM_DEFINITION
- See Also:
- Constant Field Values
-
CONFIG_KEY_MAX_ITEMS
public static final String CONFIG_KEY_MAX_ITEMS
- See Also:
- Constant Field Values
-
NAME_PLACEHOLDER
public static final String NAME_PLACEHOLDER
- See Also:
- Constant Field Values
-
DEFAULT_MAX_ITEMS
public static final int DEFAULT_MAX_ITEMS
- See Also:
- Constant Field Values
-
includedContentTypes
protected List<String> includedContentTypes
List of content-types that can be handled by this operation (optional)
-
formDefinitionXpath
protected String formDefinitionXpath
XPath to evaluate if a content-type can be handled by this operation (optional)
-
contentTypeXpath
protected String contentTypeXpath
XPath to query the content-type of item descriptors
-
formDefinitionTemplate
protected String formDefinitionTemplate
Path template to find the form-definition.xml file for a content-type
-
cache
protected com.google.common.cache.Cache<Path,Document> cache
Cache used to avoid parsing the same file multiple times during the execution of this operation
-
factory
protected DocumentBuilderFactory factory
-
xPathFactory
protected XPathFactory xPathFactory
-
transformerFactory
protected TransformerFactory transformerFactory
-
-
Constructor Detail
-
AbstractContentTypeUpgradeOperation
public AbstractContentTypeUpgradeOperation(StudioConfiguration studioConfiguration, String contentTypeXpath, String formDefinitionTemplate)
-
-
Method Detail
-
doInit
protected void doInit(org.apache.commons.configuration2.HierarchicalConfiguration config)
- Overrides:
doInit
in classAbstractContentUpgradeOperation
-
shouldBeUpdated
protected boolean shouldBeUpdated(StudioUpgradeContext context, Path file) throws org.craftercms.commons.upgrade.exception.UpgradeException
Description copied from class:AbstractContentUpgradeOperation
Indicates if the given file should be updated by this class- Specified by:
shouldBeUpdated
in classAbstractContentUpgradeOperation
- Parameters:
context
- the current upgrade contextfile
- the file to check- Returns:
- true if the file should be updated
- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- if there is any error checking the file
-
loadDocument
protected Document loadDocument(Path file) throws ExecutionException
Parses the given XML file- Parameters:
file
- the file to parse- Returns:
- the parsed file
- Throws:
ExecutionException
- if there is any error parsing the file
-
getFormDefinition
protected Path getFormDefinition(StudioUpgradeContext context, String contentTypeName)
Finds the form-definition.xml five for the given content-type- Parameters:
context
- the current upgrade contextcontentTypeName
- the content-type name- Returns:
- the form definition file
-
select
protected Object select(Object source, String xpath, QName type) throws XPathExpressionException
Evaluates a XPath selector on the given object- Parameters:
source
- the object to evaluatexpath
- the selector to evaluatetype
- the type to return- Returns:
- the evaluation result
- Throws:
XPathExpressionException
- if there is any error evaluating the selector
-
writeFile
protected void writeFile(Path file, Document document) throws org.craftercms.commons.upgrade.exception.UpgradeException
Writes an XML file to the file system without committing any changes in the repository- Parameters:
file
- the file to writedocument
- the XML document to write- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- if there is any error writing the file
-
-