Package org.apache.jackrabbit.server.io
Class XmlHandler
- java.lang.Object
-
- org.apache.jackrabbit.server.io.DefaultHandler
-
- org.apache.jackrabbit.server.io.XmlHandler
-
- All Implemented Interfaces:
CopyMoveHandler,DeleteHandler,IOHandler,PropertyHandler
public class XmlHandler extends DefaultHandler
XmlHandlerimports xml files and exports nodes that have the properXML_MIMETYPEdefined with their content. The export is performed by running adocument view exportfor the content of the export root defined with the specifiedExportContext.Please note that this handler is not suited for a generic system or document view import/export of
Nodes because an extra root node is always created during import and expected during export, respectively.
-
-
Field Summary
Fields Modifier and Type Field Description static StringXML_MIMETYPEthe xml mimetypestatic StringXML_MIMETYPE_ALTthe alternative xml mimetype.
-
Constructor Summary
Constructors Constructor Description XmlHandler()Creates a newXmlHandlerwith default nodetype definitions and without setting the IOManager.XmlHandler(IOManager ioManager)Creates a newXmlHandlerwith default nodetype definitions:
Nodetype for Collection:nt:unstructuredNodetype for Non-Collection:nt:fileNodetype for Non-Collection content:nt:unstructuredXmlHandler(IOManager ioManager, String collectionNodetype, String defaultNodetype, String contentNodetype)Creates a newXmlHandler
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanExport(ExportContext context, boolean isCollection)Returns true if the export root is a node and if it contains a child node with namejcr:contentin case this export is not intended for a collection.booleancanImport(ImportContext context, boolean isCollection)Returns true, if this handler can run a successful import based on the specified context.protected voidexportData(ExportContext context, boolean isCollection, Node contentNode)Checks if the given content node contains a jcr:data property and spools its value to the output stream of the export context.
Please note, that subclasses that define a different structure of the content node should create their ownexportDatamethod.protected voidexportProperties(ExportContext context, boolean isCollection, Node contentNode)Retrieves mimetype, encoding and modification time from the content node.protected booleanforceCompatibleContentNodes()Defines if content nodes should be replace if they don't have the node type given byDefaultHandler.getCollectionNodeType().protected booleanimportData(ImportContext context, boolean isCollection, Node contentNode)Imports the data present on the import context to the specified content node.protected booleanimportProperties(ImportContext context, boolean isCollection, Node contentNode)Imports the properties present on the specified context to the content node.-
Methods inherited from class org.apache.jackrabbit.server.io.DefaultHandler
canCopy, canDelete, canExport, canExport, canImport, canImport, canMove, copy, delete, detect, exportContent, exportContent, exportProperties, getCollectionNodeType, getContentNode, getContentNode, getContentNodeType, getIOManager, getName, getNodeType, importContent, importContent, importProperties, move, setCollectionNodetype, setContentNodetype, setDefaultNodetype, setIOManager
-
-
-
-
Field Detail
-
XML_MIMETYPE
public static final String XML_MIMETYPE
the xml mimetype- See Also:
- Constant Field Values
-
XML_MIMETYPE_ALT
public static final String XML_MIMETYPE_ALT
the alternative xml mimetype. tika detects xml as this.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XmlHandler
public XmlHandler()
Creates a newXmlHandlerwith default nodetype definitions and without setting the IOManager.- See Also:
IOHandler.setIOManager(IOManager)
-
XmlHandler
public XmlHandler(IOManager ioManager)
Creates a newXmlHandlerwith default nodetype definitions:
- Nodetype for Collection:
nt:unstructured - Nodetype for Non-Collection:
nt:file - Nodetype for Non-Collection content:
nt:unstructured
- Parameters:
ioManager-
- Nodetype for Collection:
-
-
Method Detail
-
canImport
public boolean canImport(ImportContext context, boolean isCollection)
Description copied from interface:IOHandlerReturns true, if this handler can run a successful import based on the specified context.- Specified by:
canImportin interfaceIOHandler- Overrides:
canImportin classDefaultHandler- See Also:
IOHandler.canImport(ImportContext, boolean)
-
importData
protected boolean importData(ImportContext context, boolean isCollection, Node contentNode) throws IOException, RepositoryException
Description copied from class:DefaultHandlerImports the data present on the import context to the specified content node.- Overrides:
importDatain classDefaultHandler- Throws:
IOExceptionRepositoryException- See Also:
DefaultHandler.importData(ImportContext, boolean, Node)
-
importProperties
protected boolean importProperties(ImportContext context, boolean isCollection, Node contentNode)
Description copied from class:DefaultHandlerImports the properties present on the specified context to the content node.- Overrides:
importPropertiesin classDefaultHandler- See Also:
DefaultHandler.importProperties(ImportContext, boolean, Node)
-
forceCompatibleContentNodes
protected boolean forceCompatibleContentNodes()
Defines if content nodes should be replace if they don't have the node type given byDefaultHandler.getCollectionNodeType().- Overrides:
forceCompatibleContentNodesin classDefaultHandler- Returns:
true, always.
-
canExport
public boolean canExport(ExportContext context, boolean isCollection)
Description copied from class:DefaultHandlerReturns true if the export root is a node and if it contains a child node with namejcr:contentin case this export is not intended for a collection.- Specified by:
canExportin interfaceIOHandler- Overrides:
canExportin classDefaultHandler- Returns:
- true if the export root is a node. If the specified boolean parameter
is false (not a collection export) the given export root must contain a
child node with name
jcr:content. - See Also:
IOHandler.canExport(ExportContext, boolean)
-
exportData
protected void exportData(ExportContext context, boolean isCollection, Node contentNode) throws IOException, RepositoryException
Description copied from class:DefaultHandlerChecks if the given content node contains a jcr:data property and spools its value to the output stream of the export context.
Please note, that subclasses that define a different structure of the content node should create their ownexportDatamethod.- Overrides:
exportDatain classDefaultHandler- Parameters:
context- export contextisCollection-trueif collectioncontentNode- the content node- Throws:
IOException- if an I/O error occursRepositoryException- See Also:
DefaultHandler.exportData(ExportContext, boolean, Node)
-
exportProperties
protected void exportProperties(ExportContext context, boolean isCollection, Node contentNode) throws IOException
Description copied from class:DefaultHandlerRetrieves mimetype, encoding and modification time from the content node. The content length is determined by the length of the jcr:data property if it is present. The creation time however is retrieved from the parent node (in case of isCollection == false only).- Overrides:
exportPropertiesin classDefaultHandler- Parameters:
context- the export contextisCollection-trueif collectioncontentNode- the content node- Throws:
IOException- If an error occurs.- See Also:
DefaultHandler.exportProperties(ExportContext, boolean, Node)
-
-