Class ImpExExportWriter

  • Direct Known Subclasses:
    ImpExCSVExportWriter, ImpExXMLExportWriter

    public abstract class ImpExExportWriter
    extends java.lang.Object
    With instantiating an implementation of this class you can export items of the platform to an output. The kind of output depends of implementation of this class (normal cases are CSV-files or XML-files).
    After instantiating you have to set an header descriptor for defining the output format of the following items. Afterwards you can export items belonging to the specified header.
    • Constructor Detail

      • ImpExExportWriter

        protected ImpExExportWriter()
        Constructs a ImpExExportWriter with the default SessionContext.
      • ImpExExportWriter

        protected ImpExExportWriter​(SessionContext ctx)
        Construct a ImpExExportWriter with the given SessionContext.
        Parameters:
        ctx - SessionContext
    • Method Detail

      • newLine

        public abstract void newLine()
        Write a newline.
      • comment

        public abstract void comment​(java.lang.String comment)
        Writes a comment.
        Parameters:
        comment - comment to write
      • close

        public abstract void close()
        Closes the underlying writer.
      • setCurrentHeader

        public void setCurrentHeader​(java.lang.String headerLine,
                                     EnumerationValue headerValidationMode)
                              throws ImpExException
        Sets the current Header. This header defines the used columns when exporting an item with writeLine(Item) .
        Parameters:
        headerLine - the header line from which the header object will be parsed
        headerValidationMode - the following modes are supported:
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_STRICT
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_RELAXED
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_ONLY
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_RELAXED
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_STRICT
      • Throws:
        ImpExException - error while parsing the header from given string
      • setCurrentHeader

        public void setCurrentHeader​(java.lang.String headerLine,
                                     EnumerationValue headerValidationMode,
                                     DocumentIDRegistry docIDRegistry)
                              throws ImpExException
        Sets the current Header which uses given document id registry for id resolving. This header defines the used columns when exporting an item with writeLine(Item).
        Parameters:
        headerLine - the header line
        headerValidationMode - the following modes are supported:
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_STRICT
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_RELAXED
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_ONLY
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_RELAXED
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_STRICT
      • docIDRegistry - the registry used by the new header for resolving document id's
        Throws:
        ImpExException - error while parsing the header from given string
      • setCurrentHeader

        public void setCurrentHeader​(java.lang.String headerLine,
                                     EnumerationValue headerValidationMode,
                                     DocumentIDRegistry docIDRegistry,
                                     boolean outputHeader)
                              throws ImpExException
        Sets the current Header which uses given document id registry for id resolving. This header defines the used columns when exporting an item with writeLine(Item). Outputs the Header into the underlying Writer and add a newline dependend on given output parameter.
        Parameters:
        headerLine - the header line
        headerValidationMode - the following modes are supported:
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_STRICT
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.IMPORT_RELAXED
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_ONLY
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_RELAXED
      • ImpExConstants.Enumerations.ImpExValidationModeEnum.EXPORT_REIMPORT_STRICT
      • docIDRegistry - the registry used by the new header for resolving document id's
        outputHeader - write the header in specified style into the writer?
        Throws:
        ImpExException - error while parsing the header from given string
      • setCurrentHeader

        public void setCurrentHeader​(HeaderDescriptor header)
        Sets the current Header. This header defines the used columns when exporting an item with writeLine(Item) .
        Parameters:
        header - the header object which defines the columns to export
      • writeCurrentHeader

        public abstract void writeCurrentHeader​(boolean asComment)
                                         throws ImpExException
        Writes the the current header either as a comment, if asComment is set to true, or as a normal row if asComment is false. The columns are shifted according to the set column offset.
        Throws:
        ImpExException - error while writing
        See Also:
        setColumnOffset(int), getColumnOffset()
      • writeLine

        public abstract void writeLine​(Item item)
                                throws ImpExException
        Exports the Item into the underlying Writer using current header.
        Parameters:
        item - Item to export.
        Throws:
        ImpExException - error while translating item to text
      • getCurrentHeader

        public HeaderDescriptor getCurrentHeader()
        Returns the currently active header. All subsequent calls to writeLine(Item) will export these items as described by this header.
        Returns:
        currently set header
      • getLanguage

        protected Language getLanguage​(StandardColumnDescriptor cd)
                                throws HeaderValidationException
        Extracts the Language from the given column descriptor or returns the default one.
        Parameters:
        cd - column descriptor from which the language will be used
        Returns:
        Language language of column descriptor or default language of session
        Throws:
        HeaderValidationException - if configured language of descriptor or of session is not valid
      • getAllAttributeValues

        protected java.util.Map<java.lang.String,​java.lang.Object> getAllAttributeValues​(java.util.Set<StandardColumnDescriptor> columns,
                                                                                               Item item)
                                                                                        throws UnresolvedValueException
        Queries all items Attribute given by the set of column descriptors.
        Parameters:
        columns - set of column descriptors whose value are needed from given item
        item - item whose attribute values are needed
        Returns:
        values of item attribute specified by given set of column descriptors
        Throws:
        UnresolvedValueException - a attribute is not valid
      • getAttributeValue

        protected java.lang.Object getAttributeValue​(StandardColumnDescriptor cd,
                                                     Item item)
                                              throws UnresolvedValueException
        Queries an items Attribute given by the column descriptor.
        Parameters:
        cd - column descriptor whose value is needed from given item
        item - item whose attribute value is needed
        Returns:
        value of item attribute specified by given column descriptor
        Throws:
        UnresolvedValueException - attribute is not valid
      • setColumnOffset

        public void setColumnOffset​(int offset)
        Sets the column offset to be used when exporting data. An offset of 0 indicates that all fields (type field included) should be exported. A negative offset of -n means that the n left-most items are shifted out, whereas a positive offset means that the columns are shifted to the right.
        Parameters:
        offset - column offset
      • getColumnOffset

        public int getColumnOffset()
        Returns the current column offset.
        Returns:
        current column offset
        See Also:
        setColumnOffset(int)
      • getExportWriter

        public abstract java.lang.Object getExportWriter()
        Returns the general writer which is used for this export. e.g. a CSvWriter or a XMLWriter. The returnvalue must be casted.
        Returns:
        uncasted Object
      • writeSrcLine

        public abstract void writeSrcLine​(java.lang.String scrLine)
                                   throws java.io.IOException
        Writes the String srcLine to the writer as a normal line.
        Parameters:
        scrLine - the line to be written to the writer
        Throws:
        java.io.IOException - if an error occurs while writing
      • writeComment

        public abstract void writeComment​(java.lang.String comment)
                                   throws java.io.IOException
        Writes the String comment to the writer as a line comment.
        Parameters:
        comment - the line to be written to the writer
        Throws:
        java.io.IOException - if an error occurs while writing