List of usage examples for org.dom4j.io OutputFormat setEncoding
public void setEncoding(String encoding)
From source file:eu.scape_project.planning.plato.wf.CreateExecutablePlan.java
License:Apache License
/** * Generates the preservation action plan other plan information and stores * it in the plan./*w w w . j av a 2 s. c om*/ * * @throws PlanningException * if an error occurred */ public void generatePreservationActionPlan() throws PlanningException { try { Document papDoc = generator.generatePreservationActionPlanDocument( plan.getSampleRecordsDefinition().getCollectionProfile(), plan.getExecutablePlanDefinition(), plan); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding(PlanXMLConstants.ENCODING); XMLWriter writer = new XMLWriter(out, outputFormat); writer.write(papDoc); writer.close(); ByteStream bs = new ByteStream(); bs.setData(out.toByteArray()); bs.setSize(out.size()); DigitalObject digitalObject = new DigitalObject(); digitalObject.setFullname(PreservationActionPlanGenerator.FULL_NAME); digitalObject.setContentType("application/xml"); digitalObject.setData(bs); digitalObjectManager.moveDataToStorage(digitalObject); if (plan.getPreservationActionPlan() != null && plan.getPreservationActionPlan().isDataExistent()) { bytestreamsToRemove.add(plan.getPreservationActionPlan().getPid()); } plan.setPreservationActionPlan(digitalObject); addedBytestreams.add(digitalObject.getPid()); plan.getPreservationActionPlan().touch(); } catch (IOException e) { log.error("Error generating preservation action plan {}.", e.getMessage()); throw new PlanningException("Error generating preservation action plan.", e); } catch (StorageException e) { log.error("An error occurred while storing the executable plan: {}", e.getMessage()); throw new PlanningException("An error occurred while storing the profile", e); } }
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 ww w . j a v a2s.com*/ 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 {/*ww w . j a v a 2 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 www. 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.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 ww w. jav a2s . 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:GnuCash.GnuCashDocument.java
License:Open Source License
public void writeToXML(String filename) throws FileNotFoundException, UnsupportedEncodingException, IOException, DocumentException { String suffix = ""; OutputStream out = null;/* ww w . j av a 2 s.c o m*/ OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); setBook(); //should we save as copy? //expect explicit TRUE for safety if (!Settings.getInstance().get("jPortfolioView", "file", "saveAsCopy").equals("false")) { suffix = ".copy"; } out = new FileOutputStream(filename.concat(suffix)); //should we compress the file? if (Settings.getInstance().get("jPortfolioView", "file", "compressFile").equals("true")) { out = new GZIPOutputStream(out); } XMLWriter writer = new XMLWriter(out, outformat); writer.write(book.getDocument()); writer.flush(); if (out instanceof GZIPOutputStream) { ((GZIPOutputStream) out).finish(); } modified = false; }
From source file:gov.guilin.util.SettingUtils.java
License:Open Source License
/** * /* ww w . jav a 2 s .c o m*/ * * @param setting * */ public static void set(Setting setting) { try { File guilinXmlFile = new ClassPathResource(CommonAttributes.XML_PATH).getFile(); Document document = new SAXReader().read(guilinXmlFile); List<Element> elements = document.selectNodes("/guilin/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(guilinXmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }
From source file:gtu._work.etc.HotnoteMakerUI.java
License:Open Source License
private void initGUI() { try {/*from w w w. j ava 2 s . c o m*/ ToolTipManager.sharedInstance().setInitialDelay(0); BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("hott notes - checklist", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(612, 348)); { checkListArea = new JTextArea(); jScrollPane1.setViewportView(checkListArea); checkListArea.addMouseListener(new MouseAdapter() { String randomColor() { StringBuilder sb = new StringBuilder().append("#"); for (int ii = 0; ii < 6; ii++) { sb.append(RandomUtil.randomChar('a', 'b', 'c', 'd', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9')); } return sb.toString(); } void saveXml(Document document, File file) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-16"); XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(file), format); writer.write(document); } catch (IOException e) { JCommonUtil.handleException(e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { JCommonUtil.handleException(e); } } } } public void mouseClicked(MouseEvent evt) { if (!JMouseEventUtil.buttonLeftClick(2, evt)) { return; } if (StringUtils.isEmpty(checkListArea.getText())) { JCommonUtil ._jOptionPane_showMessageDialog_error("checklist area is empty!"); return; } File file = JCommonUtil._jFileChooser_selectFileOnly_saveFile(); if (file == null) { JCommonUtil._jOptionPane_showMessageDialog_error("file is not correct!"); return; } //XXX StringTokenizer tok = new StringTokenizer(checkListArea.getText(), "\t\n\r\f"); List<String> list = new ArrayList<String>(); String tmp = null; for (; tok.hasMoreElements();) { tmp = ((String) tok.nextElement()).trim(); System.out.println(tmp); list.add(tmp); } //XXX Document document = DocumentHelper.createDocument(); Element rootHot = document.addElement("hottnote"); rootHot.addAttribute("creationtime", new Timestamp(System.currentTimeMillis()).toString()); rootHot.addAttribute("lastmodified", new Timestamp(System.currentTimeMillis()).toString()); rootHot.addAttribute("type", "checklist"); //appearence Element appearenceE = rootHot.addElement("appearence"); appearenceE.addAttribute("alpha", "204"); Element fontE = appearenceE.addElement("font"); fontE.addAttribute("face", "Default"); fontE.addAttribute("size", "0"); Element styleE = appearenceE.addElement("style"); styleE.addElement("bg2color").addAttribute("color", randomColor()); styleE.addElement("bgcolor").addAttribute("color", randomColor()); styleE.addElement("textcolor").addAttribute("color", randomColor()); styleE.addElement("titlecolor").addAttribute("color", randomColor()); //behavior rootHot.addElement("behavior"); //content Element contentE = rootHot.addElement("content"); Element checklistE = contentE.addElement("checklist"); for (String val : list) { checklistE.addElement("item").addCDATA(val); } //desktop Element desktopE = rootHot.addElement("desktop"); desktopE.addElement("position").addAttribute("x", RandomUtil.numberStr(3)) .addAttribute("y", RandomUtil.numberStr(3)); desktopE.addElement("size").addAttribute("height", "200").addAttribute("width", "200"); //title Element titleE = rootHot.addElement("title"); titleE.addCDATA(StringUtils.defaultIfEmpty(checkListTitle.getText(), DateFormatUtils.format(System.currentTimeMillis(), "dd/MM/yyyy"))); if (!file.getName().toLowerCase().endsWith(".hottnote")) { file = new File(file.getParentFile(), file.getName() + ".hottnote"); } saveXml(document, file); JCommonUtil._jOptionPane_showMessageDialog_info("completed!\n" + file); } }); } } { checkListTitle = new JTextField(); checkListTitle.setToolTipText("title"); jPanel1.add(checkListTitle, BorderLayout.NORTH); } } } pack(); this.setSize(633, 415); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }
From source file:iqq.app.service.impl.IMResourceServiceImpl.java
License:Apache License
@Override public void writeXml(Document document, File xmlFile) { try {//from ww w.j a va 2 s . c o m OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML? outputFormat.setEncoding("UTF-8");// XML? outputFormat.setIndent(true);// ? outputFormat.setIndent(" ");// TAB? outputFormat.setNewlines(true);// ?? XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(xmlFile), outputFormat); xmlWriter.write(document); xmlWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:iqq.app.util.XmlUtils.java
License:Apache License
/** * XML/*w ww . j ava 2 s.co m*/ * * @param document * @param xmlFile * @throws IOException */ public static void writeXml(String filename, Document document) throws IOException { LOG.debug("XML: " + filename); OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML? outputFormat.setEncoding("UTF-8");// XML? outputFormat.setIndent(true);// ? outputFormat.setIndent(" ");// TAB? outputFormat.setNewlines(true);// ?? synchronized (document) { XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(filename), outputFormat); xmlWriter.write(document); xmlWriter.close(); } }