Example usage for org.dom4j.io XMLWriter XMLWriter

List of usage examples for org.dom4j.io XMLWriter XMLWriter

Introduction

In this page you can find the example usage for org.dom4j.io XMLWriter XMLWriter.

Prototype

public XMLWriter(OutputStream out, OutputFormat format) throws UnsupportedEncodingException 

Source Link

Usage

From source file:fr.gouv.culture.vitam.command.VitamCommand.java

License:Open Source License

public static void convertPdfa() {
    XMLWriter writer = null;/*from w  w w .j  a v a 2 s . c o  m*/
    try {
        writer = new XMLWriter(outputStream, StaticValues.defaultOutputFormat);
    } catch (UnsupportedEncodingException e1) {
        System.err.println(StaticValues.LBL.error_writer.get() + ": " + e1.toString());
        return;
    }
    File basedir = new File(fromPdfA);
    List<File> files;
    try {
        files = DroidHandler.matchedFiled(new File[] { basedir }, extensions,
                StaticValues.config.argument.recursive);
    } catch (CommandExecutionException e1) {
        System.err.println(StaticValues.LBL.error_error.get() + e1.toString());
        return;
    }
    if (basedir.isFile()) {
        basedir = basedir.getParentFile();
    }
    File baseoutdir = new File(toPdfA);
    if (!baseoutdir.exists()) {
        baseoutdir.mkdirs();
    }
    if (baseoutdir.isFile()) {
        baseoutdir = baseoutdir.getParentFile();
    }
    int errorcpt = 0;
    boolean checkDroid = false;
    try {
        StaticValues.config.initDroid();
        checkDroid = true;
    } catch (CommandExecutionException e) {
        System.err.println(StaticValues.LBL.error_initdroid.get() + e.toString());
    }
    System.out.println("\nTransform PDF/A-1B\n");
    Element root = null;
    Element temp = null;
    VitamResult vitamResult = new VitamResult();
    if (StaticValues.config.argument.outputModel == VitamOutputModel.OneXML) {
        root = XmlDom.factory.createElement("transform");
        root.addAttribute("source", basedir.getAbsolutePath());
        root.addAttribute("target", baseoutdir.getAbsolutePath());
        vitamResult.unique = XmlDom.factory.createDocument(root);
    } else {
        // force multiple
        vitamResult.multiples = new ArrayList<Document>();
    }
    for (File file : files) {
        String basename = file.getName();
        File rootdir;
        String subpath = null;
        if (file.getParentFile().equals(basedir)) {
            rootdir = basedir;
            subpath = File.separator;
        } else {
            rootdir = file.getParentFile();
            subpath = rootdir.getAbsolutePath().replace(basedir.getAbsolutePath(), "") + File.separator;
        }
        String fullname = subpath + basename;
        String puid = null;
        if (checkDroid) {
            try {
                List<DroidFileFormat> list = StaticValues.config.droidHandler.checkFileFormat(file,
                        StaticValues.config.argument);
                if (list == null || list.isEmpty()) {
                    System.err.println("Ignore: " + fullname);
                    Element pdfa = XmlDom.factory.createElement("convert");
                    Element newElt = XmlDom.factory.createElement("file");
                    newElt.addAttribute("filename", fullname);
                    pdfa.add(newElt);
                    addPdfaElement(root, pdfa, basedir, baseoutdir, true, "Error: filetype not found", null,
                            vitamResult);
                    errorcpt++;
                    continue;
                }
                DroidFileFormat type = list.get(0);
                puid = type.getPUID();
                if (puid.startsWith(StaticValues.FORMAT_XFMT) || puid.equals("fmt/411")) { // x-fmt or RAR
                    System.err.println("Ignore: " + fullname + " " + puid);
                    Element pdfa = XmlDom.factory.createElement("convert");
                    Element newElt = XmlDom.factory.createElement("file");
                    newElt.addAttribute("filename", fullname);
                    pdfa.add(newElt);
                    addPdfaElement(root, pdfa, basedir, baseoutdir, true, "Error: filetype not allowed", puid,
                            vitamResult);
                    errorcpt++;
                    continue;
                }
            } catch (CommandExecutionException e) {
                // ignore
            }
        }
        System.out.println("PDF/A-1B convertion... " + fullname);
        long start = System.currentTimeMillis();
        Element pdfa = PdfaConverter.convertPdfA(subpath, basename, basedir, baseoutdir, StaticValues.config);
        long end = System.currentTimeMillis();
        boolean error = false;
        if (pdfa.selectSingleNode(".[@status='ok']") == null) {
            error = true;
            errorcpt++;
        }
        if (error) {
            System.err.println(StaticValues.LBL.error_pdfa.get() + " PDF/A-1B KO: " + fullname + " "
                    + ((end - start) * 1024 / file.length()) + " ms/KB " + (end - start) + " ms " + "\n");
        } else {
            System.out.println("PDF/A-1B OK: " + fullname + " " + ((end - start) * 1024 / file.length())
                    + " ms/KB " + (end - start) + " ms " + "\n");
        }
        temp = addPdfaElement(root, pdfa, basedir, baseoutdir, error, "error", puid, vitamResult);
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }
    }
    if (root != null) {
        XmlDom.addDate(StaticValues.config.argument, StaticValues.config, root);
        if (errorcpt > 0) {
            root.addAttribute("status", "error found");
        } else {
            root.addAttribute("status", "ok");
        }
        try {
            writer.write(vitamResult.unique);
        } catch (IOException e) {
            System.err.println(StaticValues.LBL.error_analysis.get() + e);
        }
    } else {
        XmlDom.addDate(StaticValues.config.argument, StaticValues.config, temp);
        try {
            writer.write(temp);
        } catch (IOException e) {
        }
    }
    if (errorcpt < files.size()) {
        System.out.println(StaticValues.LBL.action_pdfa.get() + " [ " + files.size()
                + (errorcpt > 0 ? " (" + StaticValues.LBL.error_error.get() + errorcpt + " )" : "") + " ]");
    } else {
        System.err.println(StaticValues.LBL.error_pdfa.get() + " [ " + StaticValues.LBL.error_error.get()
                + errorcpt + " ]");
    }
}

From source file:fr.gouv.culture.vitam.command.VitamCommand.java

License:Open Source License

public static void checkFilesType() {
    File fic = new File(FILEarg);
    if (!fic.exists()) {
        System.err.println(StaticValues.LBL.error_filenotfile.get() + ": " + FILEarg);
        return;//from  w w  w.j av  a  2s.c o m
    } else {
        System.out.println("\n" + StaticValues.LBL.tools_dir_format_output.get() + "\n");
        Document global = null;
        Element root = null;
        XMLWriter writer = null;
        try {
            writer = new XMLWriter(outputStream, StaticValues.defaultOutputFormat);
        } catch (UnsupportedEncodingException e1) {
            System.err.println(StaticValues.LBL.error_writer.get() + ": " + e1.toString());
            return;
        }
        if (StaticValues.config.argument.outputModel == VitamOutputModel.OneXML) {
            root = XmlDom.factory.createElement("checkfiles");
            root.addAttribute("source", FILEarg);
            global = XmlDom.factory.createDocument(root);
            EmlExtract.filEmls.clear();
        }
        if (showFormat) {
            if (StaticValues.config.droidHandler == null && StaticValues.config.exif == null
                    && StaticValues.config.jhove == null) {
                System.err.println(StaticValues.LBL.error_initfits.get());
                return;
            }
            try {
                List<File> files = DroidHandler.matchedFiled(new File[] { fic }, extensions,
                        StaticValues.config.argument.recursive);
                for (File file : files) {
                    String shortname;
                    if (fic.isDirectory()) {
                        shortname = StaticValues.getSubPath(file, fic);
                    } else {
                        shortname = FILEarg;
                    }
                    Element result = Commands.showFormat(shortname, null, null, file, StaticValues.config,
                            StaticValues.config.argument);
                    XmlDom.addDate(StaticValues.config.argument, StaticValues.config, result);
                    if (root != null) {
                        root.add(result);
                    } else {
                        writer.write(result);
                        System.out.println("\n========================================================");
                    }
                }
            } catch (CommandExecutionException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
                e.printStackTrace();
            } catch (IOException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
            }
        } else {
            if (StaticValues.config.droidHandler == null) {
                System.err.println(StaticValues.LBL.error_initdroid.get());
                return;
            }
            if (root != null) {
                Element newElt = XmlDom.factory.createElement("toolsversion");
                if (StaticValues.config.droidHandler != null) {
                    newElt.addAttribute("pronom", StaticValues.config.droidHandler.getVersionSignature());
                }
                if (StaticValues.config.droidHandler != null) {
                    newElt.addAttribute("droid", "6.1");
                }
                root.add(newElt);
            }
            List<DroidFileFormat> list;
            try {
                VitamArgument argument = new VitamArgument(StaticValues.config.argument.archive,
                        StaticValues.config.argument.recursive, true, true, true,
                        StaticValues.config.argument.outputModel, StaticValues.config.argument.checkSubFormat,
                        StaticValues.config.argument.extractKeyword);
                List<File> files = DroidHandler.matchedFiled(new File[] { fic }, extensions,
                        argument.recursive);
                list = StaticValues.config.droidHandler.checkFilesFormat(files, argument, null);
                String pathBeforeArg = fic.getCanonicalPath();
                pathBeforeArg = pathBeforeArg.substring(0, pathBeforeArg.indexOf(FILEarg));
                for (DroidFileFormat droidFileFormat : list) {
                    Element fileformat = droidFileFormat.toElement(true);
                    Attribute filename = fileformat.attribute("filename");
                    if (filename != null) {
                        String value = filename.getText();
                        filename.setText(value.replace(pathBeforeArg, ""));
                    }
                    XmlDom.addDate(StaticValues.config.argument, StaticValues.config, fileformat);
                    if (root != null) {
                        root.add(fileformat);
                    } else {
                        writer.write(fileformat);
                        System.out.println("\n========================================================");
                    }
                }
            } catch (CommandExecutionException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
            } catch (IOException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
            }
        }
        if (global != null) {
            XmlDom.addDate(StaticValues.config.argument, StaticValues.config, root);
            if (!EmlExtract.filEmls.isEmpty()) {
                Element sortEml = XmlDom.factory.createElement("emlsort");
                for (String parent : EmlExtract.filEmls.keySet()) {
                    Element eparent = XmlDom.factory.createElement("parent");
                    String fil = EmlExtract.filEmls.get(parent);
                    eparent.addAttribute("messageId", parent);
                    String[] fils = fil.split(",");
                    for (String mesg : fils) {
                        if (mesg != null && mesg.length() > 1) {
                            Element elt = XmlDom.factory.createElement("descendant");
                            elt.addAttribute("messageId", mesg);
                            eparent.add(elt);
                        }
                    }
                    sortEml.add(eparent);
                }
                root.add(sortEml);
            }
            try {
                writer.write(global);
            } catch (IOException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
            }
        }
    }
}

From source file:fr.gouv.culture.vitam.dbgui.DatabaseGui.java

License:Open Source License

/**
 * Main GUI constructor/*from w ww. j ava2  s  .  com*/
 */
public DatabaseGui() {
    StaticValues.initialize();
    List<Image> images = new ArrayList<Image>();
    images.add(Toolkit.getDefaultToolkit().getImage(getClass().getResource(VITAM64_PNG)));
    images.add(Toolkit.getDefaultToolkit().getImage(getClass().getResource(VITAM32_PNG)));
    setIconImages(images);
    try {
        writer = new XMLWriter(System.out, StaticValues.defaultOutputFormat);
    } catch (UnsupportedEncodingException e1) {
        logger.warn(StaticValues.LBL.error_writer.get() + e1.toString());
        quit();
        return;
    }
    listMenuItem = new ArrayList<JMenuItem>();
    listButton = new ArrayList<JButton>();
    listAllMenuItem = new ArrayList<JMenuItem>();
    listAllButton = new ArrayList<JButton>();
    getContentPane().setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.current_file = null;
    this.config = StaticValues.config;

    BorderLayout borderLayout = new BorderLayout();
    borderLayout.setVgap(5);
    getContentPane().setLayout(borderLayout);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    Hashtable<String, String> listMenuItems = new Hashtable<String, String>();
    listMenuItems.put("menu", "menu.file/menu.edit/menu.tools/menu.help");
    listMenuItems.put("menu.file", "file.import/tool.csvimport/tool.xmlimport/-/file.quit");
    listMenuItems.put("menu.edit", "edit.copy/edit.clear");
    listMenuItems.put("menu.tools", "tool.export/tool.visual/tool.select/tool.sql");
    listMenuItems.put("menu.help", "help.about/help.config");

    setTitle(StaticValues.LBL.appName.get());
    setBackground(Color.white);

    /*
     * Toolbars
     */
    toolBar = new JToolBar("Toolbar");
    toolBar.setFloatable(false);
    toolBarWest = new JToolBar("Toolbar");
    toolBarWest.setFloatable(false);
    toolBarWest.setOrientation(JToolBar.VERTICAL);
    mb = new JMenuBar();
    createMenuBar(listMenuItems);
    getContentPane().add(toolBar, BorderLayout.NORTH);
    getContentPane().add(toolBarWest, BorderLayout.WEST);
    setJMenuBar(mb);
    changeButtonMenu(false);

    Dimension screenSize = new Dimension(java.awt.Toolkit.getDefaultToolkit().getScreenSize());
    int width = screenSize.width / 2;
    if (width < 600) {
        width = 600;
    }
    int height = (int) (screenSize.getHeight() / 2);
    if (height < 500) {
        height = 500;
    }
    screenSize.setSize(width, height);
    setSize(screenSize);

    texteOut = new JTextPane();
    texteOut.setEditable(false);
    texteErr = new JTextPane();
    texteErr.setEditable(false);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
    splitPane.setDividerSize(2);
    splitPane.setAutoscrolls(true);
    JScrollPane outPane = new JScrollPane(texteOut);
    outPane.setViewportBorder(UIManager.getBorder("TextPane.border"));
    JScrollPane errPane = new JScrollPane(texteErr);

    splitPane.setLeftComponent(outPane);
    splitPane.setRightComponent(errPane);
    splitPane.setDividerLocation((screenSize.height - 100) / 2);

    getContentPane().add(splitPane, BorderLayout.CENTER);

    // Redirection of System.out and System.err
    ConsoleOutputStream cos = new ConsoleOutputStream(texteOut, null);
    System.setOut(new PrintStream(cos, true));
    //logger.warn("Syserr to real syserr");
    ConsoleOutputStream coserr = new ConsoleOutputStream(texteErr, Color.RED);
    System.setErr(new PrintStream(coserr, true));

    progressBar = new JProgressBar(0, 10);
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    getContentPane().add(progressBar, BorderLayout.PAGE_END);
    endProgressBar();

    frameDialog = new JFrame("Vitam Configuration");
    frameDialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            databaseGui.setEnabled(true);
            databaseGui.requestFocus();
            frameDialog.setVisible(false);
        }
    });
    configDialog = new VitamConfigDialog(frameDialog, this);
    configDialog.setOpaque(true); // content panes must be opaque
    frameDialog.setContentPane(configDialog);
    frameDialog.pack();
    frameDialog.setVisible(false);

    frameDatabase = new JFrame("Vitam Database Viewer");
    frameDatabase.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            databaseGui.setEnabled(true);
            databaseGui.requestFocus();
            frameDatabase.setVisible(false);
        }
    });
    vitamDatabase = new VitamDatabaseDialog(frameDatabase, this);
    vitamDatabase.setOpaque(true); // content panes must be opaque
    frameDatabase.setContentPane(vitamDatabase);
    frameDatabase.pack();
    frameDatabase.setVisible(false);

    frameSelect = new JFrame("Vitam Database Select");
    frameSelect.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            databaseGui.setEnabled(true);
            databaseGui.requestFocus();
            frameSelect.setVisible(false);
        }
    });
    vitamSelect = new VitamDatabaseSelectDialog(frameSelect, this);
    vitamSelect.setOpaque(true); // content panes must be opaque
    frameSelect.setContentPane(vitamSelect);
    frameSelect.pack();
    frameSelect.setVisible(false);

    frameSql = new JFrame("Vitam Database Select");
    frameSql.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            databaseGui.setEnabled(true);
            databaseGui.requestFocus();
            frameSql.setVisible(false);
        }
    });
    vitamSql = new VitamDatabaseFreeSelectDialog(frameSql, this);
    vitamSql.setOpaque(true); // content panes must be opaque
    frameSql.setContentPane(vitamSql);
    frameSql.pack();
    frameSql.setVisible(false);
}

From source file:fr.gouv.culture.vitam.dbgui.VitamDatabaseSelectDialog.java

License:Open Source License

private void viewerPanel(JTabbedPane tabbedPane) {
    JPanel xmlFilePanel = new JPanel();
    tabbedPane.addTab("Database Select", null, xmlFilePanel, null);
    GridBagLayout gbl_xmlFilePanel = new GridBagLayout();
    gbl_xmlFilePanel.columnWidths = new int[] { 21, 38, 86, 0, 0, 0, 0, 0, 45, 86, 0, 0, 0, 0, 72, 0, 0, 0, 0,
            0 };/*from   w w w. j a  va 2  s .co  m*/
    gbl_xmlFilePanel.rowHeights = new int[] { 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0 };
    gbl_xmlFilePanel.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
            0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0 };
    gbl_xmlFilePanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
    xmlFilePanel.setLayout(gbl_xmlFilePanel);

    selectModel = new ConstanceSelectModel();
    CheckComboBoxSelectionChangedListener listener = new CheckComboBoxSelectionChangedListener() {
        @Override
        public void selectionChanged(int idx) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            boolean[] revert = new boolean[fieldsChecked.length];
            if (idx >= fieldsChecked.length) {
                if (idx == fieldsChecked.length) {
                    // all
                    for (int i = 0; i < fieldsChecked.length; i++) {
                        revert[i] = fieldsChecked[i];
                        fieldsChecked[i] = true;
                        dbselect.addSelected(allFields.get(i));
                    }
                } else {
                    // none
                    for (int i = 0; i < fieldsChecked.length; i++) {
                        fieldsChecked[i] = false;
                        dbselect.remSelected(allFields.get(i));
                        if (comboBoxOrderAsc.isCheckBoxSelected(i)) {
                            comboBoxOrderAsc.changeCheckBoxSelection(i);
                        }
                        if (comboBoxOrderDesc.isCheckBoxSelected(i)) {
                            comboBoxOrderDesc.changeCheckBoxSelection(i);
                        }
                    }
                }
            } else {
                fieldsChecked[idx] = !fieldsChecked[idx];
                if (fieldsChecked[idx]) {
                    dbselect.addSelected(allFields.get(idx));
                } else {
                    dbselect.remSelected(allFields.get(idx));
                    if (comboBoxOrderAsc.isCheckBoxSelected(idx)) {
                        comboBoxOrderAsc.changeCheckBoxSelection(idx);
                    }
                    if (comboBoxOrderDesc.isCheckBoxSelected(idx)) {
                        comboBoxOrderDesc.changeCheckBoxSelection(idx);
                    }
                }
            }
            try {
                resetSelect();
            } catch (WaarpDatabaseSqlException e) {
                if (idx >= fieldsChecked.length) {
                    for (int i = 0; i < fieldsChecked.length; i++) {
                        fieldsChecked[i] = revert[i];
                        if (!fieldsChecked[i]) {
                            dbselect.remSelected(allFields.get(i));
                            comboBoxFields.changeCheckBoxSelection(i);
                            if (comboBoxOrderAsc.isCheckBoxSelected(i)) {
                                comboBoxOrderAsc.changeCheckBoxSelection(i);
                            }
                            if (comboBoxOrderDesc.isCheckBoxSelected(i)) {
                                comboBoxOrderDesc.changeCheckBoxSelection(i);
                            }
                        }
                    }
                } else {
                    fieldsChecked[idx] = !fieldsChecked[idx];
                    if (fieldsChecked[idx]) {
                        dbselect.addSelected(allFields.get(idx));
                        comboBoxFields.changeCheckBoxSelection(idx);
                    } else {
                        dbselect.remSelected(allFields.get(idx));
                        comboBoxFields.changeCheckBoxSelection(idx);
                        if (comboBoxOrderAsc.isCheckBoxSelected(idx)) {
                            comboBoxOrderAsc.changeCheckBoxSelection(idx);
                        }
                        if (comboBoxOrderDesc.isCheckBoxSelected(idx)) {
                            comboBoxOrderDesc.changeCheckBoxSelection(idx);
                        }
                    }
                }
                try {
                    resetSelect();
                } catch (WaarpDatabaseSqlException e2) {
                }
                JOptionPane.showMessageDialog(frame, "Le champ ajout provoque un timeout, il est retir.",
                        "Attention", JOptionPane.WARNING_MESSAGE);
            }
            setCursor(null);
        }
    };

    CheckComboBoxSelectionChangedListener listenerAsc = new CheckComboBoxSelectionChangedListener() {
        @Override
        public void selectionChanged(int idx) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            if (idx >= fieldsChecked.length) {
                if (idx == fieldsChecked.length) {
                    // all
                    for (int i = 0; i < fieldsChecked.length; i++) {
                        try {
                            dbselect.addOrderAsc(allFields.get(i));
                            if (!fieldsChecked[i]) {
                                comboBoxFields.changeCheckBoxSelection(i);
                                fieldsChecked[i] = true;
                            }
                        } catch (IllegalArgumentException e) {
                            System.err.println("Attention: " + e.toString());
                        }
                    }
                } else {
                    // none
                    for (int i = 0; i < fieldsChecked.length; i++) {
                        dbselect.remOrderAsc(allFields.get(i));
                    }
                }
            } else {
                if (comboBoxOrderAsc.isCheckBoxSelected(idx)) {
                    try {
                        dbselect.addOrderAsc(allFields.get(idx));
                        if (!fieldsChecked[idx]) {
                            comboBoxFields.changeCheckBoxSelection(idx);
                            fieldsChecked[idx] = true;
                        }
                    } catch (IllegalArgumentException e) {
                        JOptionPane.showMessageDialog(frame, e.toString(), "Attention",
                                JOptionPane.WARNING_MESSAGE);
                        comboBoxOrderAsc.changeCheckBoxSelection(idx);
                    }
                } else {
                    dbselect.remOrderAsc(allFields.get(idx));
                }
            }
            try {
                resetSelect();
            } catch (WaarpDatabaseSqlException e) {
                if (idx >= fieldsChecked.length) {
                    for (int i = 0; i < fieldsChecked.length; i++) {
                        dbselect.remOrderAsc(allFields.get(i));
                        comboBoxOrderAsc.changeCheckBoxSelection(i);
                    }
                } else {
                    comboBoxOrderAsc.changeCheckBoxSelection(idx);
                    dbselect.remOrderAsc(allFields.get(idx));
                }
                try {
                    resetSelect();
                } catch (WaarpDatabaseSqlException e2) {
                }
                JOptionPane.showMessageDialog(frame, "L'ordre ajout provoque un timeout, il est retir.",
                        "Attention", JOptionPane.WARNING_MESSAGE);
            }
            setCursor(null);
        }
    };

    CheckComboBoxSelectionChangedListener listenerDesc = new CheckComboBoxSelectionChangedListener() {
        @Override
        public void selectionChanged(int idx) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            if (idx >= fieldsChecked.length) {
                if (idx == fieldsChecked.length) {
                    // all
                    for (int i = 0; i < fieldsChecked.length; i++) {
                        try {
                            dbselect.addOrderDesc(allFields.get(i));
                            if (!fieldsChecked[i]) {
                                comboBoxFields.changeCheckBoxSelection(i);
                                fieldsChecked[i] = true;
                            }
                        } catch (IllegalArgumentException e) {
                            System.err.println("Attention: " + e.toString());
                        }
                    }
                } else {
                    // none
                    for (int i = 0; i < fieldsChecked.length; i++) {
                        dbselect.remOrderDesc(allFields.get(i));
                    }
                }
            } else {
                if (comboBoxOrderDesc.isCheckBoxSelected(idx)) {
                    try {
                        dbselect.addOrderDesc(allFields.get(idx));
                        if (!fieldsChecked[idx]) {
                            comboBoxFields.changeCheckBoxSelection(idx);
                            fieldsChecked[idx] = true;
                        }
                    } catch (IllegalArgumentException e) {
                        JOptionPane.showMessageDialog(frame, e.toString(), "Attention",
                                JOptionPane.WARNING_MESSAGE);
                        comboBoxOrderDesc.changeCheckBoxSelection(idx);
                    }
                } else {
                    dbselect.remOrderDesc(allFields.get(idx));
                }
            }
            try {
                resetSelect();
            } catch (WaarpDatabaseSqlException e) {
                if (idx >= fieldsChecked.length) {
                    for (int i = 0; i < fieldsChecked.length; i++) {
                        comboBoxOrderDesc.changeCheckBoxSelection(idx);
                        dbselect.remOrderDesc(allFields.get(i));
                    }
                } else {
                    comboBoxOrderDesc.changeCheckBoxSelection(idx);
                    dbselect.remOrderDesc(allFields.get(idx));
                }
                try {
                    resetSelect();
                } catch (WaarpDatabaseSqlException e2) {
                }
                JOptionPane.showMessageDialog(frame, "L'ordre ajout provoque un timeout, il est retir.",
                        "Attention", JOptionPane.WARNING_MESSAGE);
            }
            setCursor(null);
        }
    };

    comboBoxFields = new CheckComboBox(new HashSet<Object>(), true, "Champs selectionnes");
    comboBoxFields.addSelectionChangedListener(listener);
    GridBagConstraints gbc_comboBox_1 = new GridBagConstraints();
    gbc_comboBox_1.gridwidth = 3;
    gbc_comboBox_1.insets = new Insets(0, 0, 5, 5);
    gbc_comboBox_1.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBox_1.gridx = 0;
    gbc_comboBox_1.gridy = 0;
    xmlFilePanel.add(comboBoxFields, gbc_comboBox_1);

    comboBoxOrderAsc = new CheckComboBox(new HashSet<Object>(), true, "Ordre Ascendant");
    comboBoxOrderAsc.addSelectionChangedListener(listenerAsc);
    GridBagConstraints gbc_comboBox = new GridBagConstraints();
    gbc_comboBox.gridwidth = 3;
    gbc_comboBox.insets = new Insets(0, 0, 5, 5);
    gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBox.gridx = 3;
    gbc_comboBox.gridy = 0;
    xmlFilePanel.add(comboBoxOrderAsc, gbc_comboBox);

    comboBoxOrderDesc = new CheckComboBox(new HashSet<Object>(), true, "Ordre Descendant");
    comboBoxOrderDesc.addSelectionChangedListener(listenerDesc);
    GridBagConstraints gbc_comboBoxDesc = new GridBagConstraints();
    gbc_comboBoxDesc.gridwidth = 4;
    gbc_comboBoxDesc.insets = new Insets(0, 0, 5, 5);
    gbc_comboBoxDesc.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBoxDesc.gridx = 6;
    gbc_comboBoxDesc.gridy = 0;
    xmlFilePanel.add(comboBoxOrderDesc, gbc_comboBoxDesc);

    comboBoxConditions = new JComboBox();
    GridBagConstraints gbc_comboBoxConditions = new GridBagConstraints();
    gbc_comboBoxConditions.gridwidth = 6;
    gbc_comboBoxConditions.insets = new Insets(0, 0, 5, 5);
    gbc_comboBoxConditions.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBoxConditions.gridx = 11;
    gbc_comboBoxConditions.gridy = 0;
    xmlFilePanel.add(comboBoxConditions, gbc_comboBoxConditions);

    btnDelCondition = new JButton("Condition -");
    btnDelCondition.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            DbCondition condition = (DbCondition) comboBoxConditions.getSelectedItem();
            if (condition != null && condition instanceof DbCondition) {
                dbselect.removeCondition(condition);
                try {
                    resetSelect();
                } catch (WaarpDatabaseSqlException e) {
                    dbselect.addCondition(condition);
                    try {
                        resetSelect();
                    } catch (WaarpDatabaseSqlException e2) {
                    }
                    JOptionPane.showMessageDialog(frame,
                            "La condition retire provoque un timeout, elle est rajoute.", "Attention",
                            JOptionPane.WARNING_MESSAGE);
                }
                checkButtonView();
            }
            setCursor(null);
        }
    });
    GridBagConstraints gbc_btnDelCondition = new GridBagConstraints();
    gbc_btnDelCondition.insets = new Insets(0, 0, 5, 5);
    gbc_btnDelCondition.gridx = 17;
    gbc_btnDelCondition.gridy = 0;
    xmlFilePanel.add(btnDelCondition, gbc_btnDelCondition);

    JLabel lblTable = new JLabel("Table");
    lblTable.setMinimumSize(new Dimension(40, 14));
    lblTable.setPreferredSize(new Dimension(40, 14));
    GridBagConstraints gbc_lblTable = new GridBagConstraints();
    gbc_lblTable.insets = new Insets(0, 0, 5, 5);
    gbc_lblTable.anchor = GridBagConstraints.EAST;
    gbc_lblTable.gridx = 2;
    gbc_lblTable.gridy = 1;
    xmlFilePanel.add(lblTable, gbc_lblTable);

    comboBoxOperator = new JComboBox();
    comboBoxOperator.setPreferredSize(new Dimension(100, 20));
    comboBoxOperator.setMinimumSize(new Dimension(100, 20));
    comboBoxOperator.setPrototypeDisplayValue(" Not Between XXX");
    comboBoxOperator.setModel(new DefaultComboBoxModel(DbOperator.values()));
    comboBoxOperator.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DbOperator operator = (DbOperator) comboBoxOperator.getSelectedItem();
            switch (operator) {
            case Between:
            case NotBetween:
                // 3
                comboBoxOp2.setEnabled(true);
                comboBoxOp2.setModel(new DefaultComboBoxModel());
                comboBoxOp2.setEditable(true);
                comboBoxOp3.setEnabled(true);
                comboBoxOp3.setModel(new DefaultComboBoxModel());
                comboBoxOp3.setEditable(true);
                break;
            case LENGTH:
                // 3
                comboBoxOp2.setEnabled(true);
                comboBoxOp2.setModel(operatorModel);
                comboBoxOp2.setEditable(false);
                comboBoxOp3.setEnabled(true);
                comboBoxOp3.setModel(new DefaultComboBoxModel());
                comboBoxOp3.setEditable(true);
                break;
            case Different:
            case Equal:
            case Greater:
            case GreaterOrEqual:
            case Less:
            case LessOrEqual:
                // 2
                comboBoxOp2.setEnabled(true);
                comboBoxOp2.setModel(allFieldsModel);
                comboBoxOp2.setEditable(true);
                comboBoxOp3.setEnabled(false);
                break;
            case Like:
            case NotLike:
                // 2
                comboBoxOp2.setEnabled(true);
                comboBoxOp2.setModel(new DefaultComboBoxModel());
                comboBoxOp2.setEditable(true);
                comboBoxOp3.setEnabled(false);
                break;
            case IsNotNull:
            case IsNull:
                // 1
                comboBoxOp2.setEnabled(false);
                comboBoxOp3.setEnabled(false);
                break;
            }
        }
    });

    comboBoxTable = new JComboBox();
    comboBoxTable.setPreferredSize(new Dimension(60, 20));
    comboBoxTable.setMinimumSize(new Dimension(60, 20));
    comboBoxTable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String get = (String) comboBoxTable.getSelectedItem();
            if (dbschema != null) {
                DbTable dbtable2 = dbschema.getTable(get);
                if (dbtable2 != null) {
                    comboBoxOp1.setModel(new DefaultComboBoxModel(dbtable2.getFields().toArray()));
                }
            }
        }
    });
    comboBoxTable.setModel(new DefaultComboBoxModel());
    GridBagConstraints gbc_comboBoxTable = new GridBagConstraints();
    gbc_comboBoxTable.gridwidth = 3;
    gbc_comboBoxTable.insets = new Insets(0, 0, 5, 5);
    gbc_comboBoxTable.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBoxTable.gridx = 3;
    gbc_comboBoxTable.gridy = 1;
    xmlFilePanel.add(comboBoxTable, gbc_comboBoxTable);
    GridBagConstraints gbc_comboBoxOperator = new GridBagConstraints();
    gbc_comboBoxOperator.insets = new Insets(0, 0, 5, 5);
    gbc_comboBoxOperator.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBoxOperator.gridx = 6;
    gbc_comboBoxOperator.gridy = 1;
    xmlFilePanel.add(comboBoxOperator, gbc_comboBoxOperator);

    comboBoxOp1 = new JComboBox();
    comboBoxOp1.setPreferredSize(new Dimension(150, 20));
    comboBoxOp1.setMinimumSize(new Dimension(150, 20));
    GridBagConstraints gbc_comboBoxOp1 = new GridBagConstraints();
    gbc_comboBoxOp1.gridwidth = 4;
    gbc_comboBoxOp1.insets = new Insets(0, 0, 5, 5);
    gbc_comboBoxOp1.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBoxOp1.gridx = 7;
    gbc_comboBoxOp1.gridy = 1;
    xmlFilePanel.add(comboBoxOp1, gbc_comboBoxOp1);

    comboBoxOp2 = new JComboBox();
    comboBoxOp2.setPreferredSize(new Dimension(150, 20));
    comboBoxOp2.setMinimumSize(new Dimension(150, 20));
    GridBagConstraints gbc_comboBoxOp2 = new GridBagConstraints();
    gbc_comboBoxOp2.gridwidth = 4;
    gbc_comboBoxOp2.insets = new Insets(0, 0, 5, 5);
    gbc_comboBoxOp2.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBoxOp2.gridx = 11;
    gbc_comboBoxOp2.gridy = 1;
    xmlFilePanel.add(comboBoxOp2, gbc_comboBoxOp2);

    comboBoxOp3 = new JComboBox();
    comboBoxOp3.setPreferredSize(new Dimension(100, 20));
    comboBoxOp3.setMinimumSize(new Dimension(100, 20));
    GridBagConstraints gbc_comboBoxOp3 = new GridBagConstraints();
    gbc_comboBoxOp3.gridwidth = 2;
    gbc_comboBoxOp3.insets = new Insets(0, 0, 5, 5);
    gbc_comboBoxOp3.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBoxOp3.gridx = 15;
    gbc_comboBoxOp3.gridy = 1;
    xmlFilePanel.add(comboBoxOp3, gbc_comboBoxOp3);
    comboBoxOp3.setEnabled(false);

    btnAddCondition = new JButton("Condition +");
    btnAddCondition.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            DbOperator operator = (DbOperator) comboBoxOperator.getSelectedItem();
            DbField field = (DbField) comboBoxOp1.getSelectedItem();
            DbCondition condition = null;
            switch (operator) {
            case Between:
            case NotBetween: {
                // 3
                String combo1 = (String) comboBoxOp2.getSelectedItem();
                String combo2 = (String) comboBoxOp3.getSelectedItem();
                Object[] objects = new Object[] { field, combo1, combo2 };
                condition = new DbCondition(operator, objects);
            }
                break;
            case LENGTH: {
                // 3
                DbOperator operator2 = (DbOperator) comboBoxOp2.getSelectedItem();
                String combo2 = (String) comboBoxOp3.getSelectedItem();
                Object[] objects = new Object[] { field, operator2, combo2 };
                condition = new DbCondition(operator, objects);
            }
                break;
            case Different:
            case Equal:
            case Greater:
            case GreaterOrEqual:
            case Less:
            case LessOrEqual:
            case Like:
            case NotLike: {
                // 2
                Object object = comboBoxOp2.getSelectedItem();
                Object[] objects = new Object[] { field, object };
                condition = new DbCondition(operator, objects);
            }
                break;
            case IsNotNull:
            case IsNull: {
                // 1
                Object[] objects = new Object[] { field };
                condition = new DbCondition(operator, objects);
            }
                break;
            }
            dbselect.addCondition(condition);
            try {
                resetSelect();
            } catch (WaarpDatabaseSqlException e1) {
                dbselect.removeCondition(condition);
                try {
                    resetSelect();
                } catch (WaarpDatabaseSqlException e2) {
                }
                JOptionPane.showMessageDialog(frame,
                        "La condition ajoute provoque un timeout, elle est retire.", "Attention",
                        JOptionPane.WARNING_MESSAGE);
            }
            initValueView();
            setCursor(null);
        }
    });
    GridBagConstraints gbc_btnAddCondition = new GridBagConstraints();
    gbc_btnAddCondition.insets = new Insets(0, 0, 5, 5);
    gbc_btnAddCondition.gridx = 17;
    gbc_btnAddCondition.gridy = 1;
    xmlFilePanel.add(btnAddCondition, gbc_btnAddCondition);

    table = new JTable(selectModel) {
        private static final long serialVersionUID = -8896530264117717457L;

        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {
                private static final long serialVersionUID = -1026143493017837335L;

                public String getToolTipText(MouseEvent e) {
                    if (dbselect != null) {
                        java.awt.Point p = e.getPoint();
                        int index = columnModel.getColumnIndexAtX(p.x);
                        if (index >= 0) {
                            int realIndex = columnModel.getColumn(index).getModelIndex();
                            return dbselect.selected.get(realIndex).getElement().asXML();
                        }
                    }
                    return null;
                }
            };
        }
    };
    table.setAutoCreateRowSorter(true);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setShowGrid(true);

    JScrollPane scrollpane = new JScrollPane(table);
    GridBagConstraints gbc_table = new GridBagConstraints();
    gbc_table.gridheight = 9;
    gbc_table.gridwidth = 20;
    gbc_table.insets = new Insets(0, 0, 5, 0);
    gbc_table.fill = GridBagConstraints.BOTH;
    gbc_table.gridx = 0;
    gbc_table.gridy = 2;
    xmlFilePanel.add(scrollpane, gbc_table);

    textRowPerPage = new JFormattedTextField(NumberFormat.getIntegerInstance());
    textRowPerPage.setPreferredSize(new Dimension(40, 20));
    textRowPerPage.setMinimumSize(new Dimension(60, 20));
    textRowPerPage.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            try {
                int page = Integer.parseInt(textRowPerPage.getText());
                selectModel.setRowPerPage(page);
                initValueView();
                resizeTable(table);
            } catch (NumberFormatException e2) {
                initValueView();
                resizeTable(table);
            }
            setCursor(null);
        }
    });

    butLast = new JButton("|>");
    butLast.setMinimumSize(new Dimension(60, 23));
    butLast.setMaximumSize(new Dimension(60, 23));
    butLast.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            selectModel.last();
            checkButtonView();
            resizeTable(table);
            setCursor(null);
        }
    });

    butNext = new JButton(">>");
    butNext.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            selectModel.next();
            checkButtonView();
            resizeTable(table);
            setCursor(null);
        }
    });

    textPage = new JFormattedTextField(NumberFormat.getIntegerInstance());
    textPage.setPreferredSize(new Dimension(40, 20));
    textPage.setMinimumSize(new Dimension(40, 20));
    textPage.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            try {
                int page = Integer.parseInt(textPage.getText());
                selectModel.setPage(page);
                checkButtonView();
                resizeTable(table);
            } catch (NumberFormatException e2) {
                checkButtonView();
                resizeTable(table);
            }
            setCursor(null);
        }
    });

    butPrev = new JButton("<<");
    butPrev.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            selectModel.prev();
            checkButtonView();
            resizeTable(table);
            setCursor(null);
        }
    });

    butFirst = new JButton("<|");
    butFirst.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            selectModel.first();
            checkButtonView();
            resizeTable(table);
            setCursor(null);
        }
    });

    btnChargeFiltre = new JButton("Charge Filtre");
    btnChargeFiltre.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            File file = openFile(null, "Choix d'un filtre  charger", false, "xml");
            if (file != null) {
                SAXReader saxReader = new SAXReader();
                Document document;
                try {
                    document = saxReader.read(file);
                } catch (DocumentException e) {
                    JOptionPane.showMessageDialog(frame, "Le fichier n'est pas lisible.", "Attention",
                            JOptionPane.WARNING_MESSAGE);
                    return;
                }
                DbSelect dbSelect = DbSelect.fromElement(document.getRootElement(), dbschema);
                dbselect = dbSelect;
                selectModel.initialize(database, dbselect);
                comboBoxConditions.setModel(new DefaultComboBoxModel(dbselect.conditions.toArray()));
                initValueView();
                initFieldView();
                resizeTable(table);
            }
        }
    });

    btnExportCsv = new JButton("Export CSV");
    btnExportCsv.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            File file = openFile(null, "Export CSV", true, "csv");
            if (file != null) {
                SimpleDelimiterWriter writer = new SimpleDelimiterWriter(file, StaticValues.config.separator);
                try {
                    writer.write(DbConstant.admin.session, dbselect);
                } catch (WaarpDatabaseSqlException e) {
                    JOptionPane.showMessageDialog(frame, "Le fichier n'a pas pu tre export.", "Attention",
                            JOptionPane.WARNING_MESSAGE);
                    return;
                }
            }
        }
    });
    GridBagConstraints gbc_btnExportCsv = new GridBagConstraints();
    gbc_btnExportCsv.insets = new Insets(0, 0, 0, 5);
    gbc_btnExportCsv.gridx = 0;
    gbc_btnExportCsv.gridy = 11;
    xmlFilePanel.add(btnExportCsv, gbc_btnExportCsv);
    GridBagConstraints gbc_btnChargeFiltre = new GridBagConstraints();
    gbc_btnChargeFiltre.gridwidth = 2;
    gbc_btnChargeFiltre.insets = new Insets(0, 0, 0, 5);
    gbc_btnChargeFiltre.gridx = 1;
    gbc_btnChargeFiltre.gridy = 11;
    xmlFilePanel.add(btnChargeFiltre, gbc_btnChargeFiltre);
    GridBagConstraints gbc_buttonFirst = new GridBagConstraints();
    gbc_buttonFirst.anchor = GridBagConstraints.EAST;
    gbc_buttonFirst.insets = new Insets(0, 0, 0, 5);
    gbc_buttonFirst.gridx = 3;
    gbc_buttonFirst.gridy = 11;
    xmlFilePanel.add(butFirst, gbc_buttonFirst);
    GridBagConstraints gbc_btnPrev = new GridBagConstraints();
    gbc_btnPrev.anchor = GridBagConstraints.WEST;
    gbc_btnPrev.insets = new Insets(0, 0, 0, 5);
    gbc_btnPrev.gridx = 4;
    gbc_btnPrev.gridy = 11;
    xmlFilePanel.add(butPrev, gbc_btnPrev);

    JLabel lblPage = new JLabel("Page");
    lblPage.setPreferredSize(new Dimension(40, 14));
    lblPage.setMaximumSize(new Dimension(50, 14));
    lblPage.setMinimumSize(new Dimension(50, 14));
    GridBagConstraints gbc_lblPage = new GridBagConstraints();
    gbc_lblPage.insets = new Insets(0, 0, 0, 5);
    gbc_lblPage.anchor = GridBagConstraints.EAST;
    gbc_lblPage.gridx = 5;
    gbc_lblPage.gridy = 11;
    xmlFilePanel.add(lblPage, gbc_lblPage);
    GridBagConstraints gbc_textField = new GridBagConstraints();
    gbc_textField.insets = new Insets(0, 0, 0, 5);
    gbc_textField.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField.gridx = 6;
    gbc_textField.gridy = 11;
    xmlFilePanel.add(textPage, gbc_textField);
    textPage.setColumns(10);

    lblX = new JLabel("/ x");
    lblX.setMinimumSize(new Dimension(40, 14));
    GridBagConstraints gbc_lblX = new GridBagConstraints();
    gbc_lblX.anchor = GridBagConstraints.WEST;
    gbc_lblX.insets = new Insets(0, 0, 0, 5);
    gbc_lblX.gridx = 7;
    gbc_lblX.gridy = 11;
    xmlFilePanel.add(lblX, gbc_lblX);
    GridBagConstraints gbc_button_1 = new GridBagConstraints();
    gbc_button_1.anchor = GridBagConstraints.EAST;
    gbc_button_1.insets = new Insets(0, 0, 0, 5);
    gbc_button_1.gridx = 8;
    gbc_button_1.gridy = 11;
    xmlFilePanel.add(butNext, gbc_button_1);
    GridBagConstraints gbc_button_3 = new GridBagConstraints();
    gbc_button_3.anchor = GridBagConstraints.WEST;
    gbc_button_3.insets = new Insets(0, 0, 0, 5);
    gbc_button_3.gridx = 10;
    gbc_button_3.gridy = 11;
    xmlFilePanel.add(butLast, gbc_button_3);

    JLabel lblLignepage = new JLabel("Ligne/Page");
    lblLignepage.setPreferredSize(new Dimension(70, 14));
    lblLignepage.setMaximumSize(new Dimension(80, 14));
    lblLignepage.setMinimumSize(new Dimension(80, 14));
    GridBagConstraints gbc_lblLignepage = new GridBagConstraints();
    gbc_lblLignepage.anchor = GridBagConstraints.EAST;
    gbc_lblLignepage.insets = new Insets(0, 0, 0, 5);
    gbc_lblLignepage.gridx = 11;
    gbc_lblLignepage.gridy = 11;
    xmlFilePanel.add(lblLignepage, gbc_lblLignepage);
    GridBagConstraints gbc_textField_1 = new GridBagConstraints();
    gbc_textField_1.gridwidth = 4;
    gbc_textField_1.insets = new Insets(0, 0, 0, 5);
    gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_1.gridx = 12;
    gbc_textField_1.gridy = 11;
    xmlFilePanel.add(textRowPerPage, gbc_textField_1);
    textRowPerPage.setColumns(10);

    btnSauveFiltre = new JButton("Sauve Filtre");
    btnSauveFiltre.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            File file = openFile(null, "Choix d'un fichier pour sauvegarder le filtre", true, "xml");
            if (file != null) {
                Element root = dbselect.toElement();
                try {
                    FileOutputStream out = new FileOutputStream(file);
                    OutputFormat format = OutputFormat.createPrettyPrint();
                    format.setEncoding(StaticValues.CURRENT_OUTPUT_ENCODING);
                    XMLWriter writer = new XMLWriter(out, format);
                    writer.write(root);
                    writer.close();
                    out.close();
                } catch (IOException e2) {
                    JOptionPane.showMessageDialog(frame, "Le fichier n'as pu tre crit : " + e2.toString(),
                            "Attention", JOptionPane.WARNING_MESSAGE);
                    return;
                }
            }
        }
    });
    GridBagConstraints gbc_btnSauveFiltre = new GridBagConstraints();
    gbc_btnSauveFiltre.gridwidth = 2;
    gbc_btnSauveFiltre.insets = new Insets(0, 0, 0, 5);
    gbc_btnSauveFiltre.gridx = 16;
    gbc_btnSauveFiltre.gridy = 11;
    xmlFilePanel.add(btnSauveFiltre, gbc_btnSauveFiltre);
    initValueView();
}

From source file:fr.gouv.culture.vitam.droid.DroidHandler.java

License:Open Source License

/**
 * Example only//from   ww w. j av  a2s  .c o  m
 * 
 * @param args
 * @throws CommandExecutionException
 */
public static void main(String[] args) throws CommandExecutionException {
    StaticValues.initialize();
    String signatureFile = StaticValues.resourceToFile(StaticValues.config.SIGNATURE_FILE);
    String containerSignatureFile = StaticValues.resourceToFile(StaticValues.config.CONTAINER_SIGNATURE_FILE);

    // Init Signature
    initialize(signatureFile, containerSignatureFile, -1);

    // Prepare command
    DroidHandler droid = new DroidHandler();

    String[] tocheck = new String[] { "J:\\Git\\SEDA\\droid-binary-6.1-bin\\doc",
            "J:\\Git\\SEDA\\droid-binary-6.1-bin\\doc\\vitam.xlsx" };

    // Execute and get result
    List<DroidFileFormat> list = null;
    try {
        list = droid.checkFilesFormat(tocheck, null, VitamArgument.NOFEATURE, null);
    } catch (CommandExecutionException e) {
        e.printStackTrace();
    }

    // for the example, print out the result as is
    XMLWriter writer = null;
    try {
        writer = new XMLWriter(System.out, StaticValues.defaultOutputFormat);
    } catch (UnsupportedEncodingException e1) {
    }
    try {
        for (DroidFileFormat droidFileFormat : list) {
            writer.write(droidFileFormat.toElement(true));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        list = droid.checkFileFormat(tocheck[1], VitamArgument.SHAALLONLY);
    } catch (CommandExecutionException e) {
        e.printStackTrace();
    }
    try {
        for (DroidFileFormat droidFileFormat : list) {
            writer.write(droidFileFormat.toElement(true));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        list = droid.checkFileFormat(tocheck[1], VitamArgument.SHAALLONLY);
        for (DroidFileFormat droidFileFormat : list) {
            System.out.println(droidFileFormat.toStringCsv());
        }
    } catch (CommandExecutionException e) {
        e.printStackTrace();
    }
}

From source file:fr.gouv.culture.vitam.eml.PstExtract.java

License:Open Source License

/**
 * Try to extract the following :/*from ww  w.  jav  a  2s.c o m*/
 * 
 * Taken from : http://www.significantproperties.org.uk/email-testingreport.html
 * 
 * message-id (Message-ID), References (References), In-Reply-To (In-Reply-To), Attachment
 * subject (Subject), keywords sent-date (Date), Received-date (in Received last date),
 * Trace-field (Received?)
 * 
 * 
 * From (From), To (To), CC (Cc), BCC (Bcc), Content-Type, Content-Transfer-Encoding
 * 
 * ? DomainKey-Signature, Sender, X-Original-Sender, X-Forwarded-Message-Id,
 * 
 * 1) Core property set
 * 
 * The core property set indicates the minimum amount of information that is considered
 * necessary to establish the authenticity and integrity of the email message
 * 
 * Local-part, Domain-part, Relationship, Subject, Trace-field , Message body with no mark-up,
 * Attachments
 * 
 * 2) Message thread scenario
 * 
 * Email is frequently used as a communication method between two or more people. To understand
 * the context in which a message was created it may be necessary to refer to earlier messages.
 * To identify the thread of a discussion, the following fields should be provided, in addition
 * to the core property set:
 * 
 * Local-part, Domain-part, Relationship, Subject, Trace-field, Message body with no mark-up,
 * Attachments, Message-ID, References
 * 
 * 3) Recommended property set
 * 
 * The recommended property set indicates additional information that should be provided in an
 * ideal scenario, if it is present within the email. The list
 * 
 * Local-part, Domain-part, Domain-literal (if present), Relationship, Subject, Trace-field,
 * Attachments, Message-ID, References, Sent-date, Received date, Display name, In-reply-to,
 * Keywords, Message body & associated mark-up (see table 6 for scenarios)
 * 
 * 
 * 
 * @param emlFile
 * @param filename
 * @param argument
 * @param config
 * @return
 */
public static Element extractInfoPst(File pstFile, VitamArgument argument, ConfigLoader config) {
    System.out.println("Start PST: " + (new Date().toString()));
    PstExtract extract = new PstExtract(pstFile.getAbsolutePath(), argument, config);
    PSTFolder folder = null;
    File oldDir = argument.currentOutputDir;
    try {
        PSTFile pstFile2 = new PSTFile(extract.filename);
        System.out.println(pstFile2.getMessageStore().getDisplayName());
        extract.currentRoot = extract.pstRoot;
        extract.currentRoot.addAttribute(EMAIL_FIELDS.filename.name, pstFile.getPath());
        // XXX FIXME multiple output
        if (argument.currentOutputDir == null) {
            if (config.outputDir != null) {
                argument.currentOutputDir = new File(config.outputDir);
            } else {
                argument.currentOutputDir = new File(pstFile.getParentFile().getAbsolutePath());
            }
        }
        if (config.extractFile) {
            extract.curPath = new File(argument.currentOutputDir, "PST_" + pstFile.getName());
            extract.curPath.mkdirs();
        } else if (extractSeparateXmlFolder) {
            extract.curPath = new File(argument.currentOutputDir, "PST_" + pstFile.getName());
            extract.curPath.mkdirs();
        }
        argument.currentOutputDir = extract.curPath;
        folder = pstFile2.getRootFolder();
    } catch (Exception err) {
        err.printStackTrace();
        argument.currentOutputDir = oldDir;
        return null;
    }
    if (extractSeparateXmlFolder) {
        try {
            extract.writer = new XMLWriter(System.out, StaticValues.defaultOutputFormat);
        } catch (UnsupportedEncodingException e1) {
            System.err.println(StaticValues.LBL.error_writer.get() + e1.toString());
        }
    }
    extract.extractInfoFolder(folder);
    DroidHandler.cleanTempFiles();
    extract.currentRoot.addAttribute("nbMsg", config.nbDoc.toString());
    System.out.println("Stop PST: " + (new Date().toString()));
    argument.currentOutputDir = oldDir;
    return extract.pstRoot;
}

From source file:fr.gouv.culture.vitam.extract.ExtractInfo.java

License:Open Source License

public static void main(String[] args) {
    if (args.length == 0) {
        System.err.println("need file as target");
        return;/*from  w w  w.ja va 2 s. c  om*/
    }
    StaticValues.initialize();
    Document document = DocumentFactory.getInstance().createDocument(StaticValues.CURRENT_OUTPUT_ENCODING);
    Element root = DocumentFactory.getInstance().createElement("extractkeywords");
    document.add(root);
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding(StaticValues.CURRENT_OUTPUT_ENCODING);
    XMLWriter writer = null;
    try {
        writer = new XMLWriter(System.out, format);
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
        return;
    }
    for (String string : args) {
        File file = new File(string);
        recursive(file, string, root, StaticValues.config, writer);
    }
    if (StaticValues.config.argument.outputModel == VitamOutputModel.OneXML) {
        try {
            writer.write(document);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:fr.gouv.culture.vitam.gui.VitamGui.java

License:Open Source License

/**
 * Main GUI constructor/*from ww  w .j a  va 2 s .c o m*/
 */
public VitamGui() {
    try {
        StaticValues.initialize();
        List<Image> images = new ArrayList<Image>();
        images.add(Toolkit.getDefaultToolkit().getImage(getClass().getResource(VITAM64_PNG)));
        images.add(Toolkit.getDefaultToolkit().getImage(getClass().getResource(VITAM32_PNG)));
        setIconImages(images);
        try {
            writer = new XMLWriter(System.out, StaticValues.defaultOutputFormat);
        } catch (UnsupportedEncodingException e1) {
            System.err.println(StaticValues.LBL.error_writer.get() + e1.toString());
            quit();
            return;
        }
        listMenuItem = new ArrayList<JMenuItem>();
        listButton = new ArrayList<JButton>();
        listAllMenuItem = new ArrayList<JMenuItem>();
        listAllButton = new ArrayList<JButton>();
        getContentPane().setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
        this.current_file = null;
        this.config = StaticValues.config;

        BorderLayout borderLayout = new BorderLayout();
        borderLayout.setVgap(5);
        getContentPane().setLayout(borderLayout);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                quit();
            }
        });
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

        Hashtable<String, String> listMenuItems = new Hashtable<String, String>();
        listMenuItems.put("menu", "menu.file/menu.edit/menu.tools/menu.droid/menu.help");
        listMenuItems.put("menu.file", "file.quit");
        listMenuItems.put("menu.edit", "edit.copy/edit.clear");
        listMenuItems.put("menu.tools",
                "+/tools.dir_digest/-/tools.digest/tools.dir_format_test/tools.dir_format_output");
        listMenuItems.put("menu.droid", "tools.pdfa");
        listMenuItems.put("menu.help", "help.about/help.config");

        setTitle(StaticValues.LBL.appName.get());
        setBackground(Color.white);

        /*
         * Toolbars
         */
        toolBar = new JToolBar("Toolbar");
        toolBar.setFloatable(false);
        toolBarWest = new JToolBar("Toolbar");
        toolBarWest.setFloatable(false);
        toolBarWest.setOrientation(JToolBar.VERTICAL);
        mb = new JMenuBar();
        createMenuBar(listMenuItems);
        getContentPane().add(toolBar, BorderLayout.NORTH);
        getContentPane().add(toolBarWest, BorderLayout.WEST);
        setJMenuBar(mb);
        changeButtonMenu(false);

        Dimension screenSize = new Dimension(java.awt.Toolkit.getDefaultToolkit().getScreenSize());
        int width = screenSize.width / 2;
        if (width < 700) {
            width = 700;
        }
        int height = (int) (screenSize.getHeight() / 2);
        if (height < 640) {
            height = 640;
        }
        screenSize.setSize(width, height);
        setSize(screenSize);

        texteOut = new JTextPane();
        texteOut.setEditable(false);
        texteErr = new JTextPane();
        texteErr.setEditable(false);

        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
        splitPane.setDividerSize(2);
        splitPane.setAutoscrolls(true);
        JScrollPane outPane = new JScrollPane(texteOut);
        outPane.setViewportBorder(UIManager.getBorder("TextPane.border"));
        JScrollPane errPane = new JScrollPane(texteErr);

        splitPane.setLeftComponent(outPane);
        splitPane.setRightComponent(errPane);
        splitPane.setDividerLocation((screenSize.height - 100) / 2);

        getContentPane().add(splitPane, BorderLayout.CENTER);

        // Redirection of System.out and System.err
        ConsoleOutputStream cos = new ConsoleOutputStream(texteOut, null);
        System.setOut(new PrintStream(cos, true));
        ConsoleOutputStream coserr = new ConsoleOutputStream(texteErr, Color.RED);
        System.setErr(new PrintStream(coserr, true));

        progressBar = new JProgressBar(0, 100);
        progressBar.setValue(0);
        progressBar.setStringPainted(true);
        getContentPane().add(progressBar, BorderLayout.PAGE_END);
        endProgressBar();

        frameDialog = new JFrame("Vitam Configuration");
        frameDialog.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                vitamGui.setEnabled(true);
                vitamGui.requestFocus();
                frameDialog.setVisible(false);
            }
        });
        configDialog = new VitamConfigDialog(frameDialog, this);
        configDialog.setOpaque(true); // content panes must be opaque
        frameDialog.setContentPane(configDialog);
        frameDialog.pack();
        frameDialog.setVisible(false);

        frameDigestDialog = new JFrame("Vitam Digest");
        frameDigestDialog.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                vitamGui.setEnabled(true);
                vitamGui.requestFocus();
                frameDigestDialog.setVisible(false);
            }
        });
        vitamDigestDialog = new VitamDigestDialog(frameDigestDialog, this);
        vitamDigestDialog.setOpaque(true); // content panes must be opaque
        frameDigestDialog.setContentPane(vitamDigestDialog);
        frameDigestDialog.pack();
        frameDigestDialog.setVisible(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:fr.gouv.culture.vitam.utils.XmlDom.java

License:Open Source License

/**
 * Attached file accessibility test//from   w  w  w . ja v a  2 s.c o  m
 * 
 * @param current_file
 * @param task
 *            optional
 * @param config
 * @param argument
 * @param checkDigest
 * @param checkFormat
 * @param showFormat
 * @return VitamResult
 */
static final public VitamResult all_tests_in_one(File current_file, RunnerLongTask task, ConfigLoader config,
        VitamArgument argument, boolean checkDigest, boolean checkFormat, boolean showFormat) {
    SAXReader saxReader = new SAXReader();
    VitamResult finalResult = new VitamResult();
    Element root = initializeCheck(argument, finalResult, current_file);
    try {
        Document document = saxReader.read(current_file);
        removeAllNamespaces(document);
        Node nodesrc = document.selectSingleNode("/digests");
        String src = null;
        String localsrc = current_file.getParentFile().getAbsolutePath() + File.separator;
        if (nodesrc != null) {
            nodesrc = nodesrc.selectSingleNode("@source");
            if (nodesrc != null) {
                src = nodesrc.getText() + "/";
            }
        }
        if (src == null) {
            src = localsrc;
        }
        @SuppressWarnings("unchecked")
        List<Node> nodes = document.selectNodes("//" + config.DOCUMENT_FIELD);
        if (nodes == null) {
            Element result = fillInformation(argument, root, "result", "filefound", "0");
            addDate(argument, config, result);
        } else {
            String number = "" + nodes.size();
            Element result = fillInformation(argument, root, "result", "filefound", number);
            XMLWriter writer = null;
            writer = new XMLWriter(System.out, StaticValues.defaultOutputFormat);
            int currank = 0;
            for (Node node : nodes) {
                currank++;
                Node attachment = node.selectSingleNode(config.ATTACHMENT_FIELD);
                if (attachment == null) {
                    continue;
                }
                Node file = attachment.selectSingleNode(config.FILENAME_ATTRIBUTE);
                if (file == null) {
                    continue;
                }
                Node mime = null;
                Node format = null;
                if (checkFormat) {
                    mime = attachment.selectSingleNode(config.MIMECODE_ATTRIBUTE);
                    format = attachment.selectSingleNode(config.FORMAT_ATTRIBUTE);
                }
                String sfile = null;
                String smime = null;
                String sformat = null;
                String sintegrity = null;
                String salgo = null;
                if (file != null) {
                    sfile = file.getText();
                }
                if (mime != null) {
                    smime = mime.getText();
                }
                if (format != null) {
                    sformat = format.getText();
                }
                // Now check
                // first existence check
                String ficname = src + sfile;
                Element check = fillInformation(argument, root, "check", "filename", sfile);
                File fic1 = new File(ficname);
                File fic2 = new File(localsrc + sfile);
                File fic = null;
                if (fic1.canRead()) {
                    fic = fic1;
                } else if (fic2.canRead()) {
                    fic = fic2;
                }
                if (fic == null) {
                    fillInformation(argument, check, "find", "status",
                            StaticValues.LBL.error_filenotfile.get());
                    addDate(argument, config, result);
                    finalResult.values[AllTestsItems.FileError.ordinal()]++;
                    finalResult.values[AllTestsItems.GlobalError.ordinal()]++;
                } else {
                    Element find = fillInformation(argument, check, "find", "status", "ok");
                    addDate(argument, config, find);
                    finalResult.values[AllTestsItems.FileSuccess.ordinal()]++;
                    if (checkDigest) {
                        @SuppressWarnings("unchecked")
                        List<Node> integrities = node.selectNodes(config.INTEGRITY_FIELD);
                        for (Node integrity : integrities) {
                            Node algo = integrity.selectSingleNode(config.ALGORITHME_ATTRIBUTE);
                            salgo = null;
                            sintegrity = null;
                            if (integrity != null) {
                                sintegrity = integrity.getText();
                                if (algo != null) {
                                    salgo = algo.getText();
                                } else {
                                    salgo = config.DEFAULT_DIGEST;
                                }
                            }
                            // Digest check
                            if (salgo == null) {
                                // nothing
                            } else if (salgo.equals(StaticValues.XML_SHA1)) {
                                salgo = "SHA-1";
                            } else if (salgo.equals(StaticValues.XML_SHA256)) {
                                salgo = "SHA-256";
                            } else if (salgo.equals(StaticValues.XML_SHA512)) {
                                salgo = "SHA-512";
                            } else {
                                salgo = null;
                            }

                            if (algo != null) {
                                Element eltdigest = Commands.checkDigest(fic, salgo, sintegrity);
                                if (eltdigest.selectSingleNode(".[@status='ok']") != null) {
                                    finalResult.values[AllTestsItems.DigestSuccess.ordinal()]++;
                                } else {
                                    finalResult.values[AllTestsItems.DigestError.ordinal()]++;
                                    finalResult.values[AllTestsItems.GlobalError.ordinal()]++;
                                }
                                addDate(argument, config, eltdigest);
                                addElement(writer, argument, check, eltdigest);
                            }
                        }
                    }
                    // Check format
                    if (checkFormat && config.droidHandler != null) {
                        try {
                            // Droid
                            List<DroidFileFormat> list = config.droidHandler.checkFileFormat(fic, argument);
                            Element cformat = Commands.droidFormat(list, smime, sformat, sfile, fic);
                            if (config.droidHandler != null) {
                                cformat.addAttribute("pronom", config.droidHandler.getVersionSignature());
                            }
                            if (config.droidHandler != null) {
                                cformat.addAttribute("droid", "6.1");
                            }
                            if (cformat.selectSingleNode(".[@status='ok']") != null) {
                                finalResult.values[AllTestsItems.FormatSuccess.ordinal()]++;
                            } else if (cformat.selectSingleNode(".[@status='warning']") != null) {
                                finalResult.values[AllTestsItems.FormatWarning.ordinal()]++;
                                finalResult.values[AllTestsItems.GlobalWarning.ordinal()]++;
                            } else {
                                finalResult.values[AllTestsItems.FormatError.ordinal()]++;
                                finalResult.values[AllTestsItems.GlobalError.ordinal()]++;
                            }
                            addDate(argument, config, cformat);
                            addElement(writer, argument, check, cformat);
                        } catch (Exception e) {
                            Element cformat = fillInformation(argument, check, "format", "status",
                                    "Error " + e.toString());
                            addDate(argument, config, cformat);
                            finalResult.values[AllTestsItems.SystemError.ordinal()]++;
                        }
                    }
                    // Show format
                    if (showFormat && config.droidHandler != null) {
                        Element showformat = Commands.showFormat(sfile, smime, sformat, fic, config, argument);
                        if (showformat.selectSingleNode(".[@status='ok']") != null) {
                            finalResult.values[AllTestsItems.ShowSuccess.ordinal()]++;
                        } else if (showformat.selectSingleNode(".[@status='warning']") != null) {
                            finalResult.values[AllTestsItems.ShowWarning.ordinal()]++;
                            finalResult.values[AllTestsItems.GlobalWarning.ordinal()]++;
                        } else {
                            finalResult.values[AllTestsItems.ShowError.ordinal()]++;
                            finalResult.values[AllTestsItems.GlobalError.ordinal()]++;
                        }
                        addDate(argument, config, showformat);
                        addElement(writer, argument, check, showformat);
                    }
                }
                addDate(argument, config, result);
                root = finalizeOneCheck(argument, finalResult, current_file, number);
                if (root != null) {
                    result = root.element("result");
                }
                if (task != null) {
                    float value = ((float) currank) / (float) nodes.size();
                    value *= 100;
                    task.setProgressExternal((int) value);
                }
            }
        }
        document = null;
    } catch (DocumentException e1) {
        Element result = fillInformation(argument, root, "result", "parsererror",
                StaticValues.LBL.error_error.get() + " " + e1 + " - " + StaticValues.LBL.error_parser.get()
                        + " (" + SAXReader.class.getName() + ")");
        addDate(argument, config, result);
        finalResult.values[AllTestsItems.SystemError.ordinal()]++;
    } catch (UnsupportedEncodingException e1) {
        Element result = fillInformation(argument, root, "result", "parsererror",
                StaticValues.LBL.error_error.get() + " " + e1 + " - " + StaticValues.LBL.error_parser.get()
                        + " (" + XMLWriter.class.getName() + ")");
        addDate(argument, config, result);
        finalResult.values[AllTestsItems.SystemError.ordinal()]++;
    }
    finalizeAllCheck(argument, finalResult);
    return finalResult;
}

From source file:fr.isima.ponge.wsprotocol.xml.XmlIOManager.java

License:Open Source License

/**
 * Writes a business protocol as an XML representation to a writer.
 *
 * @param protocol The protocol./*from  w ww  .j a va  2s .c o m*/
 * @param writer   The writer to use.
 * @throws IOException Thrown in case an I/O error occurs.
 */
@SuppressWarnings("unchecked")
public void writeBusinessProtocol(BusinessProtocol protocol, Writer writer) throws IOException {
    // Root
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("business-protocol"); //$NON-NLS-1$

    // Protocol
    root.addElement("name").setText(protocol.getName()); //$NON-NLS-1$
    writeExtraProperties(root, protocol);

    // States
    Iterator it = protocol.getStates().iterator();
    while (it.hasNext()) {
        State s = (State) it.next();
        Element el = root.addElement("state"); //$NON-NLS-1$
        el.addElement("name").setText(s.getName()); //$NON-NLS-1$
        el.addElement("final").setText(s.isFinalState() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        if (s.isInitialState()) {
            el.addElement("initial-state"); //$NON-NLS-1$
        }
        writeExtraProperties(el, s);
    }

    // Operations
    it = protocol.getOperations().iterator();
    while (it.hasNext()) {
        Operation o = (Operation) it.next();
        Message m = o.getMessage();
        String pol;
        if (m.getPolarity().equals(Polarity.POSITIVE)) {
            pol = "positive"; //$NON-NLS-1$
        } else if (m.getPolarity().equals(Polarity.NEGATIVE)) {
            pol = "negative"; //$NON-NLS-1$

        } else {
            pol = "null"; //$NON-NLS-1$
        }
        Element oel = root.addElement("operation"); //$NON-NLS-1$
        Element mel = oel.addElement("message"); //$NON-NLS-1$
        mel.addElement("name").setText(m.getName()); //$NON-NLS-1$
        mel.addElement("polarity").setText(pol); //$NON-NLS-1$
        oel.addElement("name").setText(o.getName()); //$NON-NLS-1$
        oel.addElement("source").setText(o.getSourceState().getName()); //$NON-NLS-1$
        oel.addElement("target").setText(o.getTargetState().getName()); //$NON-NLS-1$
        oel.addElement("kind").setText(o.getOperationKind().toString()); //$NON-NLS-1$
        writeExtraProperties(mel, m);
        writeExtraProperties(oel, o);
    }

    // Write
    XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint());
    xmlWriter.write(document);
}