Class Archivers
- java.lang.Object
-
- org.ametys.plugins.contentio.archive.Archivers
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Archivers.AmetysObjectNotImportedException
Exception indicating an Ametys Object cannot be imported
-
Field Summary
Fields Modifier and Type Field Description (package private) static String
__BINARY_ATTRIBUTES_FOLDER_NAME
(package private) static String
__FILE_ATTRIBUTES_FOLDER_NAME
private static Properties
__OUTPUT_FORMAT_PROPERTIES
(package private) static String
__RICH_TEXT_ATTACHMENTS_FOLDER_NAME
private static SAXTransformerFactory
__transformerFactory
static String
WARN_MESSAGE_ROOT_HAS_PENDING_CHANGES
The warning message for a root ofArchiver
which stil has pending change while we do a unitary save on every imported object.
-
Constructor Summary
Constructors Modifier Constructor Description private
Archivers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static void
_exportResource(String dataPath, NamedResource resource, ZipOutputStream zos, String prefix)
private static void
_exportRichText(String richTextDataPath, RichText richText, ZipOutputStream zos, String prefix)
static void
exportAcl(Node node, ZipOutputStream zos, String path)
Export ACL sub-nodestatic void
exportBinaries(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path)
Export the given data holder's binariesstatic void
exportFiles(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path)
Export the given data holder's filesstatic void
exportRichTexts(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path)
Export the attachments of the given data holder's rich textsstatic String
getFolderPathFromDataPath(String dataPath)
Retrieves a folder path from a data path.static String
getHashedPath(String name)
Computes a hashed path from an object name.static SAXTransformerFactory
getSaxTransformerFactory()
Gets aSAXTransformerFactory
static void
importAcl(Node node, Path zipPath, Merger merger, String zipEntryPath, org.slf4j.Logger logger)
Import ACL sub-nodestatic TransformerHandler
newTransformerHandler()
Get a TransformerHandler object that can process SAXContentHandler events into a Resultstatic Node
replaceNodeWithDesiredUuid(Node srcNode, String uuid)
Replace the given JCR Node by a copy of it with the given UUID.static void
setStandardOutputProperties(TransformerHandler transformerHandler)
Sets standard output properties to the transformer of the given handler, such as encoding and indentation.static void
unitarySave(Node ametysObjectNode, org.slf4j.Logger logger)
Save the pending changes brought to this node associated to anAmetysObject
If the save failed, it is logged in ERROR level and the changes are discarded.static String
xpathEvalNonEmpty(String xPath, Node domNode)
Evaluates a non-empty XPath query.
-
-
-
Field Detail
-
WARN_MESSAGE_ROOT_HAS_PENDING_CHANGES
public static final String WARN_MESSAGE_ROOT_HAS_PENDING_CHANGES
The warning message for a root ofArchiver
which stil has pending change while we do a unitary save on every imported object.- See Also:
- Constant Field Values
-
__BINARY_ATTRIBUTES_FOLDER_NAME
static final String __BINARY_ATTRIBUTES_FOLDER_NAME
- See Also:
- Constant Field Values
-
__FILE_ATTRIBUTES_FOLDER_NAME
static final String __FILE_ATTRIBUTES_FOLDER_NAME
- See Also:
- Constant Field Values
-
__RICH_TEXT_ATTACHMENTS_FOLDER_NAME
static final String __RICH_TEXT_ATTACHMENTS_FOLDER_NAME
- See Also:
- Constant Field Values
-
__OUTPUT_FORMAT_PROPERTIES
private static final Properties __OUTPUT_FORMAT_PROPERTIES
-
__transformerFactory
private static SAXTransformerFactory __transformerFactory
-
-
Constructor Detail
-
Archivers
private Archivers()
-
-
Method Detail
-
getSaxTransformerFactory
public static SAXTransformerFactory getSaxTransformerFactory()
Gets aSAXTransformerFactory
- Returns:
- a
SAXTransformerFactory
-
newTransformerHandler
public static TransformerHandler newTransformerHandler() throws TransformerConfigurationException
Get a TransformerHandler object that can process SAXContentHandler events into a Result- Returns:
- A non-null reference to a TransformerHandler, that maybe used as a ContentHandler for SAX parse events.
- Throws:
TransformerConfigurationException
- If for some reason theTransformerHandler cannot be created.
-
setStandardOutputProperties
public static void setStandardOutputProperties(TransformerHandler transformerHandler)
Sets standard output properties to the transformer of the given handler, such as encoding and indentation.- Parameters:
transformerHandler
- The transformer handler
-
getHashedPath
public static String getHashedPath(String name)
Computes a hashed path from an object name.- Parameters:
name
- the object name.- Returns:
- a hashed path.
-
exportAcl
public static void exportAcl(Node node, ZipOutputStream zos, String path) throws RepositoryException, IOException
Export ACL sub-node- Parameters:
node
- The JCR nodezos
- the ZIP OutputStream.path
- the zip entry path- Throws:
RepositoryException
- if an error occursIOException
- if an I/O error occurs
-
importAcl
public static void importAcl(Node node, Path zipPath, Merger merger, String zipEntryPath, org.slf4j.Logger logger) throws RepositoryException, IOException
Import ACL sub-node- Parameters:
node
- The JCR nodezipPath
- the input zip pathmerger
- TheMerger
zipEntryPath
- the zip entry pathlogger
- The logger- Throws:
RepositoryException
- if an error occursIOException
- if an I/O error occurs
-
xpathEvalNonEmpty
public static String xpathEvalNonEmpty(String xPath, Node domNode) throws Archivers.AmetysObjectNotImportedException, TransformerException
Evaluates a non-empty XPath query. If the result is empty, anArchivers.AmetysObjectNotImportedException
is thrown.- Parameters:
xPath
- The XPath querydomNode
- The DOM node- Returns:
- The evaluation as String
- Throws:
Archivers.AmetysObjectNotImportedException
- If the result is emptyTransformerException
- if an evaluation error occured
-
replaceNodeWithDesiredUuid
public static Node replaceNodeWithDesiredUuid(Node srcNode, String uuid) throws RepositoryException
Replace the given JCR Node by a copy of it with the given UUID. The source JCR Node is removed.- Parameters:
srcNode
- The source JCR Nodeuuid
- The desired UUID- Returns:
- The JCR Node with the desired UUID
- Throws:
RepositoryException
- if an error occurs
-
unitarySave
public static void unitarySave(Node ametysObjectNode, org.slf4j.Logger logger) throws Archivers.AmetysObjectNotImportedException, ImportGlobalFailException
Save the pending changes brought to this node associated to anAmetysObject
If the save failed, it is logged in ERROR level and the changes are discarded.- Parameters:
ametysObjectNode
- The nodelogger
- The logger- Throws:
Archivers.AmetysObjectNotImportedException
- If the save failedImportGlobalFailException
- If a severe error occured and the global import process must be stopped
-
exportRichTexts
public static void exportRichTexts(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path) throws IOException
Export the attachments of the given data holder's rich texts- Parameters:
dataHolder
- The data holderzos
- TheZipOutputStream
where to export the attachmentspath
- The path of the folder used to export the attachments- Throws:
IOException
- if an error occurs while exporting the attachments
-
_exportRichText
private static void _exportRichText(String richTextDataPath, RichText richText, ZipOutputStream zos, String prefix) throws IOException
- Throws:
IOException
-
exportBinaries
public static void exportBinaries(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path) throws IOException
Export the given data holder's binaries- Parameters:
dataHolder
- The data holderzos
- TheZipOutputStream
where to export the binariespath
- The path of the folder used to export the binaries- Throws:
IOException
- if an error occurs while exporting the binaries
-
exportFiles
public static void exportFiles(ModelAwareDataHolder dataHolder, ZipOutputStream zos, String path) throws IOException
Export the given data holder's files- Parameters:
dataHolder
- The data holderzos
- TheZipOutputStream
where to export the filespath
- The path of the folder used to export the files- Throws:
IOException
- if an error occurs while exporting the files
-
_exportResource
private static void _exportResource(String dataPath, NamedResource resource, ZipOutputStream zos, String prefix) throws IOException
- Throws:
IOException
-
getFolderPathFromDataPath
public static String getFolderPathFromDataPath(String dataPath)
Retrieves a folder path from a data path. Replaces all repeater entries like '[x]', to a folder with the position ('/x')- Parameters:
dataPath
- the data path- Returns:
- the folder path
-
-