List of usage examples for org.dom4j.io OutputFormat createPrettyPrint
public static OutputFormat createPrettyPrint()
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 v a 2s.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.digest.DigestCompute.java
License:Open Source License
public static int createDigest(File src, File dst, File ftar, File fglobal, boolean oneDigestPerFile, List<File> filesToScan) { try {//from w w w . ja v a2 s. co m Element global = null; Document globalDoc = null; if (fglobal != null) { global = XmlDom.factory.createElement("digests"); global.addAttribute("source", src.getAbsolutePath()); globalDoc = XmlDom.factory.createDocument(global); } OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(StaticValues.CURRENT_OUTPUT_ENCODING); XMLWriter writer = new XMLWriter(format); int error = 0; int currank = 0; for (File file : filesToScan) { currank++; Element result = DigestCompute.checkDigest(StaticValues.config, src, file); if (result.selectSingleNode(".[@status='ok']") == null) { System.err.println(StaticValues.LBL.error_error.get() + StaticValues.LBL.error_computedigest.get() + StaticValues.getSubPath(file, src)); error++; } else if (oneDigestPerFile) { Element rootElement = XmlDom.factory.createElement("digest"); Document unique = XmlDom.factory.createDocument(rootElement); rootElement.add(result); FileOutputStream out = null; String shortname = StaticValues.getSubPath(file, src); String shortnameWithoutFilename = shortname.substring(0, shortname.lastIndexOf(file.getName())); File fdirout = new File(dst, shortnameWithoutFilename); fdirout.mkdirs(); File fout = new File(fdirout, file.getName() + "_digest.xml"); try { out = new FileOutputStream(fout); writer.setOutputStream(out); writer.write(unique); writer.close(); } catch (FileNotFoundException e) { System.err.println( StaticValues.LBL.error_error.get() + fout.getAbsolutePath() + " " + e.toString()); error++; } catch (IOException e) { System.err.println( StaticValues.LBL.error_error.get() + fout.getAbsolutePath() + " " + e.toString()); if (out != null) { try { out.close(); } catch (IOException e1) { } } error++; } result.detach(); } if (fglobal != null) { global.add(result); } } if (ftar != null) { currank++; Element result = DigestCompute.checkDigest(StaticValues.config, src, ftar); if (result.selectSingleNode(".[@status='ok']") == null) { System.err.println(StaticValues.LBL.error_error.get() + StaticValues.LBL.error_computedigest.get() + ftar.getAbsolutePath()); error++; } else if (oneDigestPerFile) { Element rootElement = XmlDom.factory.createElement("digest"); Document unique = XmlDom.factory.createDocument(rootElement); rootElement.add(result); FileOutputStream out = null; File fout = new File(dst, ftar.getName() + "_tar_digest.xml"); try { out = new FileOutputStream(fout); writer.setOutputStream(out); writer.write(unique); writer.close(); } catch (FileNotFoundException e) { System.err.println( StaticValues.LBL.error_error.get() + fout.getAbsolutePath() + " " + e.toString()); error++; } catch (IOException e) { System.err.println( StaticValues.LBL.error_error.get() + fout.getAbsolutePath() + " " + e.toString()); if (out != null) { try { out.close(); } catch (IOException e1) { } } error++; } result.detach(); } if (fglobal != null) { global.add(result); } } if (fglobal != null) { if (error > 0) { global.addAttribute("status", "error"); } else { global.addAttribute("status", "ok"); } XmlDom.addDate(VitamArgument.ONEXML, StaticValues.config, global); FileOutputStream out; try { out = new FileOutputStream(fglobal); writer.setOutputStream(out); writer.write(globalDoc); writer.close(); } catch (FileNotFoundException e) { System.err.println( StaticValues.LBL.error_error.get() + fglobal.getAbsolutePath() + " " + e.toString()); error++; } catch (IOException e) { System.err.println( StaticValues.LBL.error_error.get() + fglobal.getAbsolutePath() + " " + e.toString()); error++; } } if (error > 0) { System.err.println(StaticValues.LBL.error_error.get() + " Digest" + " [ " + currank + (error > 0 ? " (" + StaticValues.LBL.error_error.get() + error + " ) " : "") + " ]"); return -error; } return currank; } catch (UnsupportedEncodingException e) { System.err.println(StaticValues.LBL.error_error.get() + " " + e.toString()); return -1; } }
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 ww. j a v a 2 s .c o m*/ } 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.utils.StaticValues.java
License:Open Source License
public final static void initialize() { StaticValues.LABELS = new PreferencesResourceBundle(Locale.getDefault()); config = new ConfigLoader(CONFIG_VITAM); defaultOutputFormat = OutputFormat.createPrettyPrint(); defaultOutputFormat.setEncoding(CURRENT_OUTPUT_ENCODING); if (LBL.option_langue.get().equalsIgnoreCase("fr")) { HELP_COMMAND = "Necessite au moins \"--print fichier\" ou \"--convertpdfa source destination\" ou \"--checkdigest fichier\" ou \"--createdigest 5-args\" comme argument\n" + "\tObligatoirement un parmis (-p,--print fichier | -3,--convertpdfa source destination | -4,--checkdigest fichier | -5,--createdigest 5-args)\n" + "\tou -5,--createdigest source cible (-notar | fichiertar) (-noglobal | globaldir/prefix) (-noperfile | -perfile) [5 arguments obligatoires]\n" + "\t[-r,--root racine du xsd (defaut=" + config.CURRENT_XSD_ROOT + ")]\n" + "\t[-ff,--filefield champ (defaut=" + config.ATTACHMENT_FIELD + ")]\n" + "\t[-fa,--fileattrib attribut (defaut=" + config.FILENAME_ATTRIBUTE + ")]\n" + "\t[-ma,--mimeattrib attribut (defaut=" + config.MIMECODE_ATTRIBUTE + ")]\n" + "\t[-ta,--formatattrib attribut (defaut=" + config.FORMAT_ATTRIBUTE + ")]\n" + "\t[-df,--digestfield champ (defaut=" + config.INTEGRITY_FIELD + ")]\n" + "\t[-aa,--algoattrib attribut (defaut=" + config.ALGORITHME_ATTRIBUTE + ")]\n" + "\t[-n,--signature fichier (defaut=" + config.SIGNATURE_FILE + ")]\n" + "\t[-c,--container fichier (defaut=" + config.CONTAINER_SIGNATURE_FILE + ")]\n" + "\t[-4,--checkdigest fichier (defaut=faux)]\n" + "\t[-f,--checkformat (defaut=faux)]\n" + "\t[-a,--checkarchives (defaut=" + config.argument.archive + ") | -na,--notcheckarchives]\n" + "\t[-v,--checkrecursive (defaut=" + config.argument.recursive + ") | -nv,--notcheckrecusrive]\n" + "\t[-h,--computesha algo (o algo=SHA-1,SHA-256,SHA-512 ou un sous-ensemble, defaut=" + config.argument.sha1 + ":" + config.argument.sha256 + ":" + config.argument.sha512 + ") | -nh,--notcomputesha]\n" + "\t[-e,--extensionrecur filtre_liste_a_virgule (defaut=pas de filtre sur l'extension)]\n" + "\t[-o,--showformat (defaut=faux)]\n" + "\t[-x,--formatoutput format (in TXT|XML|XMLS, defaut=XML)]\n" + "\t[-1,--outputfile fichier (defaut=STDOUT)]\n" + "\t[-z,--preventxfmt (defaut=" + config.preventXfmt + ") | -nz,--notpreventxfmt]\n" + "\t[-3,--convertpdfa source destination (defaut=faux)]\n" + "\t[-k,--msperkb msParKo (defaut=" + config.msPerKB + ")]\n" + "\t[-t,--lowlimitms limiteBasseEnMs (default=" + config.lowLimitMs + ")]\n" + "\t[-y,--extractkeyword (defaut=" + config.argument.extractKeyword + ") | -ny,--notextractkeyword]\n" + "\t[-i,--ranklimit limitRankOccur (default=" + config.rankLimit + ")]\n" + "\t[-w,--wordlimit limitWordOccur (default=" + config.wordLimit + ")]\n" + "\t[--help] pour imprimer cette aide\n" + "\t[-0,--config configurationFile (defaut=vitam-config.xml)]"; } else {/*from w w w.j av a2 s. c o m*/ HELP_COMMAND = "Need at least \"--print filename\" or \"--convertpdfa from to\" or \"--checkdigest filename\" or \"--createdigest 5-args\" as argument\n" + "\tMandatory one of (-p,--print filename | -3,--convertpdfa from to | -4,--checkdigest filename | -5,--createdigest 5-args)\n" + "\twhere -5,--createdigest source target (-notar | tarfile) (-noglobal | globaldir/prefix) (-noperfile | -perfile) [5 mandatory arguments]\n" + "\t[-r,--root root of xsd (default=" + config.CURRENT_XSD_ROOT + ")]\n" + "\t[-ff,--filefield field (default=" + config.ATTACHMENT_FIELD + ")]\n" + "\t[-fa,--fileattrib attribute (default=" + config.FILENAME_ATTRIBUTE + ")]\n" + "\t[-ma,--mimeattrib attribute (default=" + config.MIMECODE_ATTRIBUTE + ")]\n" + "\t[-ta,--formatattrib attribute (default=" + config.FORMAT_ATTRIBUTE + ")]\n" + "\t[-df,--digestfield field (default=" + config.INTEGRITY_FIELD + ")]\n" + "\t[-aa,--algoattrib attribute (default=" + config.ALGORITHME_ATTRIBUTE + ")]\n" + "\t[-n,--signature filename (default=" + config.SIGNATURE_FILE + ")]\n" + "\t[-c,--container filename (default=" + config.CONTAINER_SIGNATURE_FILE + ")]\n" + "\t[-4,--checkdigest filename (default=false)]\n" + "\t[-f,--checkformat (default=false)]\n" + "\t[-a,--checkarchives (default=" + config.argument.archive + ") | -na,--notcheckarchives]\n" + "\t[-v,--checkrecursive (default=" + config.argument.recursive + ") | -nv,--notcheckrecusrive]\n" + "\t[-h,--computesha algo (where algo=SHA-1,SHA-256,SHA-512 or subset default=" + config.argument.sha1 + ":" + config.argument.sha256 + ":" + config.argument.sha512 + ") | -nh,--notcomputesha]\n" + "\t[-e,--extensionrecur filter_in_comma_separated_list (default=no extension filter)]\n" + "\t[-o,--showformat (default=false)]\n" + "\t[-x,--formatoutput format (in TXT|XML|XMLS, default=XML)]\n" + "\t[-1,--outputfile filename (default=STDOUT)]\n" + "\t[-z,--preventxfmt (default=" + config.preventXfmt + ") | -nz,--notpreventxfmt]\n" + "\t[-3,--convertpdfa from to (default=false)]\n" + "\t[-k,--msperkb msPerKB (default=" + config.msPerKB + ")]\n" + "\t[-t,--lowlimitms lowLimitInMs (default=" + config.lowLimitMs + ")]\n" + "\t[-y,--extractkeyword (default=" + config.argument.extractKeyword + ") | -ny,--notextractkeyword]\n" + "\t[-i,--ranklimit limitRankOccur (default=" + config.rankLimit + ")]\n" + "\t[-w,--wordlimit limitWordOccur (default=" + config.wordLimit + ")]\n" + "\t[--help] to print help\n" + "\t[-0,--config configurationFile (default=vitam-config.xml)]"; } Logger.getRootLogger().setLevel(Level.OFF); }
From source file:fr.gouv.culture.vitam.writer.XmlWriter.java
License:Open Source License
public void write() throws IOException { FileOutputStream out = new FileOutputStream(file); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(StaticValues.CURRENT_OUTPUT_ENCODING); XMLWriter writer = new XMLWriter(out, format); writer.write(document);//from w w w . j a v a 2s . c o m writer.close(); out.close(); document.clearContent(); document = null; DocumentFactory factory = DocumentFactory.getInstance(); document = factory.createDocument(StaticValues.CURRENT_OUTPUT_ENCODING); Element root = factory.createElement(rootname); document.setRootElement(root); StaticValues.freeMemory(); }
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 w w . j a v a2 s .com*/ * @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); }
From source file:fullyMeshedNet.FullyMeshedNet.java
License:Open Source License
@Override public void exportToFile(File saveFile) { String extension = FrevoMain.getExtension(saveFile); if (extension.equals("net")) { System.out.println("Exporting Pajek network file to " + saveFile.getName()); try {/* ww w.j a v a 2 s. c o m*/ // Create file FileWriter fstream = new FileWriter(saveFile); BufferedWriter out = new BufferedWriter(fstream); out.write("*Vertices " + this.nodes); out.newLine(); // input neurons for (int i = 1; i < input_nodes + 1; i++) { out.write(i + " \"I" + i + "\""); out.newLine(); } for (int h = input_nodes + 1; h < nodes - output_nodes + 1; h++) { out.write(h + " \"H" + (h - input_nodes) + "\""); out.newLine(); } int a = 1; for (int o = nodes - output_nodes + 1; o < nodes + 1; o++) { out.write(o + " \"O" + a + "\""); out.newLine(); a++; } // Edges out.write("*Edges"); out.newLine(); for (int n = 0; n < input_nodes - 1; n++) { for (int p = n + 1; p < input_nodes; p++) { if (n != p) { out.write((n + 1) + " " + (p + 1) + " " + 0); out.newLine(); } } } for (int n = input_nodes; n < nodes; n++) { for (int from = 0; from < nodes; from++) { out.write((n + 1) + " " + (from + 1) + " " + weight[from][n]); out.newLine(); } } // Close the output stream out.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } else if (extension.equals("xml")) { System.out.println("Saving to XML"); Document doc = DocumentHelper.createDocument(); doc.addDocType("CompleteNetwork", null, System.getProperty("user.dir") + "//Components//Representations//CompleteNetwork//src//CompleteNetwork.dtd"); Element cnetwork = doc.addElement("CompleteNetwork"); this.exportToXmlElement(cnetwork); OutputFormat format = OutputFormat.createPrettyPrint(); format.setLineSeparator(System.getProperty("line.separator")); try { saveFile.createNewFile(); FileWriter out = new FileWriter(saveFile); BufferedWriter bw = new BufferedWriter(out); XMLWriter wr = new XMLWriter(bw, format); wr.write(doc); wr.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:gestionecassa.backends.XmlDataBackend.java
License:Open Source License
@Override public void saveArticlesList(ArticlesList lista) throws IOException { Document document = DocumentHelper.createDocument(); Element root = document.addElement("article_groups"); Collection<ArticleGroup> groups = lista.getGroupsList(); for (ArticleGroup group : groups) { Element tempGroup = root.addElement("group"); tempGroup.addElement("name").addText(group.getName()); tempGroup.addElement("id").addText(group.getId() + ""); for (Article art : group.getList()) { Element tempArt = tempGroup.addElement("article"); tempArt.addElement("name").addText(art.getName()); tempArt.addElement("price").addText(art.getPrice() + ""); tempArt.addElement("id").addText(art.getId() + ""); if (art.hasOptions()) { tempArt.addAttribute("options", "true"); Element tempOpzioni = tempArt.addElement("options"); Collection<ArticleOption> options = art.getOptions(); for (ArticleOption option : options) { tempOpzioni.addElement("option").addText(option.getName()); } //FIXME aggiungi altre parti di ArticleOption } else { tempArt.addAttribute("options", "false"); }//from w w w. ja v a2 s . com } } // for debug purposes OutputFormat format = OutputFormat.createPrettyPrint(); // lets write to a file XMLWriter writer = new XMLWriter(new FileWriter(ArtListFile), format); //XMLWriter writer = new XMLWriter(new FileWriter(fileName)); writer.write(document); writer.close(); }
From source file:gestionecassa.backends.XmlDataBackend.java
License:Open Source License
@Override public void saveAdminsList(Collection<Admin> lista) throws IOException { Document document = DocumentHelper.createDocument(); Element root = document.addElement("admins"); for (Admin admin : lista) { Element tempAdmin = root.addElement("admin"); tempAdmin.addElement("id").addText(admin.getId() + ""); tempAdmin.addElement("username").addText(admin.getUsername()); tempAdmin.addElement("password").addText(admin.getPassword()); }// w w w. j a v a 2s. c o m // for debug purposes OutputFormat format = OutputFormat.createPrettyPrint(); // lets write to a file XMLWriter writer = new XMLWriter(new FileWriter(AdminListFile), format); //XMLWriter writer = new XMLWriter(new FileWriter(fileName)); writer.write(document); writer.close(); }
From source file:gestionecassa.backends.XmlDataBackend.java
License:Open Source License
@Override public void saveCassiereList(Collection<Cassiere> lista) throws IOException { Document document = DocumentHelper.createDocument(); Element root = document.addElement("cassieri"); for (Cassiere cassiere : lista) { Element tempCassiere = root.addElement("cassiere"); tempCassiere.addElement("id").addText(cassiere.getId() + ""); tempCassiere.addElement("username").addText(cassiere.getUsername()); tempCassiere.addElement("password").addText(cassiere.getPassword()); }/* w w w . jav a 2 s . co m*/ // for debug purposes OutputFormat format = OutputFormat.createPrettyPrint(); // lets write to a file XMLWriter writer = new XMLWriter(new FileWriter(CassiereListFile), format); //XMLWriter writer = new XMLWriter(new FileWriter(fileName)); writer.write(document); writer.close(); }