Commit 72cc7ce0 authored by Frank Bergmann's avatar Frank Bergmann

- importing

parent a4f4985d
/**
*
*/
package org.projectopen.browser;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JViewport;
import javax.swing.table.TableModel;
/**
* @author fraber
*
*/
public class DynfieldListPanel extends JScrollPane {
private static final long serialVersionUID = 7110486062789525401L;
private JTable attrsTable = null;
private String objectType = null;
protected String getObjectType() { return objectType; }
protected void setObjectType(String oType) { this.objectType = oType; }
/**
* This method initializes objectTable
*
* @return javax.swing.JTable
*/
private JTable getObjectTable(String objectType) {
if (attrsTable == null) {
attrsTable = new JTable();
TableModel model = new DynfieldListTableModel(objectType);
attrsTable.setModel(model);
}
return attrsTable;
}
public DynfieldListPanel(String objectType) {
super();
this.setObjectType(objectType);
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setPreferredSize(new Dimension(500,300));
// this.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
// this.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
JViewport port = new JViewport();
JTable attrTable = getObjectTable(objectType);
// attrTable.setPreferredScrollableViewportSize(new Dimension(800,600));
port.setView(attrTable);
this.setViewport(port);
attrTable.setFillsViewportHeight(true);
attrTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
/**
* @param args
*/
public static void main(String[] args) {
String objectType = "im_ticket";
JFrame frame = new JFrame("DynField panel");
JComponent panel = new DynfieldListPanel(objectType);
frame.add(panel);
frame.pack();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setVisible(true);
}
}
package org.projectopen.browser;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.projectopen.dynfield.ProjopDynfieldAttribute;
import org.projectopen.rest.ProjopObject;
@SuppressWarnings("unchecked")
/**
* This table model represents the dynamic fields
* that belong to a certain object type
*/
public class DynfieldListTableModel extends AbstractTableModel {
private static final long serialVersionUID = -181295859700418641L;
static final String cname[] = {
"ID", "Name", "Table", "Column",
"Type", "Widget", "Hard Coded?", "Sort Order"
};
static final String cvar[] = {
"attribute_id", "pretty_name", "table_name", "attribute_name",
"datatype", "widget_name", "also_hard_coded_p", "sort_order"
};
static final Class ctype[] = {
String.class, String.class, String.class, String.class,
String.class, String.class, String.class, String.class
};
private String objectType = null;
public DynfieldListTableModel(String oType) {
super();
this.objectType = oType;
}
public String getColumnName(int columnIndex) {
return cname[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return ctype[columnIndex];
}
@Override
public int getColumnCount() {
return cname.length;
}
@Override
public int getRowCount() {
List attrs = ProjopDynfieldAttribute.getAttributesFromObjectType(objectType);
return attrs.size();
}
@Override
public Object getValueAt(int row, int col) {
List attrs = ProjopDynfieldAttribute.getAttributesFromObjectType(objectType);
ProjopObject a = (ProjopObject)attrs.get(row);
String colName = cvar[col];
String value = a.get(colName);
return value;
}
}
/**
*
*/
package org.projectopen.browser;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.GridBagConstraints;
import java.awt.Font;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import org.projectopen.rest.ProjopCategory;
import org.projectopen.rest.ProjopObject;
import org.projectopen.rest.RESTClient;
/**
* @author fraber
*
*/
public class NewCompanyPanel extends JPanel {
private static final long serialVersionUID = 1L;
private JLabel topemptyLabel = null;
private JLabel nameLabel = null;
private JLabel pathLabel = null;
private JLabel statusLabel = null;
private JLabel typeLabel = null;
private JLabel loweremptyLabel = null;
private JTextField nameTextField = null;
private JTextField pathTextField1 = null;
private JComboBox statusComboBox = null;
private JComboBox typeComboBox = null;
private JLabel leftemptyLabel = null;
private JLabel rightemptyLabel = null;
private JButton newButton = null;
/**
* This method initializes nameTextField
*
* @return javax.swing.JTextField
*/
private JTextField getNameTextField() {
if (nameTextField == null) {
nameTextField = new JTextField();
nameTextField.setPreferredSize(new Dimension(150, 20));
}
return nameTextField;
}
/**
* This method initializes pathTextField1
*
* @return javax.swing.JTextField
*/
private JTextField getPathTextField1() {
if (pathTextField1 == null) {
pathTextField1 = new JTextField();
pathTextField1.setPreferredSize(new Dimension(150, 20));
}
return pathTextField1;
}
/**
* This method initializes statusComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getStatusComboBox() {
if (statusComboBox == null) {
Object[] cats = ProjopCategory.comboBoxCategories("Intranet Company Status");
statusComboBox = new JComboBox(cats);
statusComboBox.setEnabled(true);
statusComboBox.setName("Status");
statusComboBox.setEditable(false);
statusComboBox.setFont(new Font("Dialog", Font.PLAIN, 12));
}
return statusComboBox;
}
/**
* This method initializes typeComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getTypeComboBox() {
if (typeComboBox == null) {
Object[] cats = ProjopCategory.comboBoxCategories("Intranet Company Type");
typeComboBox = new JComboBox(cats);
typeComboBox.setEditable(false);
typeComboBox.setName("Type");
typeComboBox.setFont(new Font("Dialog", Font.PLAIN, 12));
}
return typeComboBox;
}
/**
* This method initializes newButton
*
* @return javax.swing.JButton
*/
private JButton getNewButton() {
if (newButton == null) {
newButton = new JButton();
newButton.setText("New Company");
newButton.setFont(new Font("Dialog", Font.PLAIN, 12));
// Save the new parameters
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
ProjopObject userObject = new ProjopObject("im_company");
userObject.set("company_name", nameTextField.getText());
userObject.set("company_nr", pathTextField1.getText());
userObject.set("company_path", pathTextField1.getText());
int companyStatusId = ProjopCategory.categoryIdFromCategory("Intranet Company Status", statusComboBox.getSelectedItem());
int companyTypeId = ProjopCategory.categoryIdFromCategory("Intranet Company Type", typeComboBox.getSelectedItem());
userObject.set("company_status_id",""+companyStatusId);
userObject.set("company_type_id",""+companyTypeId);
int objectId = RESTClient.defaultInstance().restCreateObject(userObject);
final JFrame f = new JFrame("User Created");
JPanel p = new JPanel();
p.add(new JLabel("User created: " + objectId));
f.add(p);
f.pack();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
f.setVisible(false);
}
});
f.setVisible(true);
}
};
newButton.addActionListener(actionListener);
}
return newButton;
}
/**
* @param args
*/
public static void main(String[] args) {
JFrame frame = new JFrame("New Company");
JPanel panel = new NewCompanyPanel();
frame.add(panel);
frame.pack();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setVisible(true);
}
/**
* This is the default constructor
*/
public NewCompanyPanel() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
gridBagConstraints14.gridx = 2;
gridBagConstraints14.anchor = GridBagConstraints.WEST;
gridBagConstraints14.gridy = 5;
GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
gridBagConstraints13.gridx = 3;
gridBagConstraints13.gridy = 0;
rightemptyLabel = new JLabel();
rightemptyLabel.setText(" ");
GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
gridBagConstraints12.gridx = 0;
gridBagConstraints12.gridy = 0;
leftemptyLabel = new JLabel();
leftemptyLabel.setText(" ");
GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
gridBagConstraints11.fill = GridBagConstraints.VERTICAL;
gridBagConstraints11.gridy = 4;
gridBagConstraints11.weightx = 1.0;
gridBagConstraints11.anchor = GridBagConstraints.WEST;
gridBagConstraints11.gridx = 2;
GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
gridBagConstraints10.fill = GridBagConstraints.VERTICAL;
gridBagConstraints10.gridy = 3;
gridBagConstraints10.weightx = 1.0;
gridBagConstraints10.anchor = GridBagConstraints.WEST;
gridBagConstraints10.gridx = 2;
GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
gridBagConstraints8.fill = GridBagConstraints.VERTICAL;
gridBagConstraints8.gridy = 2;
gridBagConstraints8.weightx = 1.0;
gridBagConstraints8.anchor = GridBagConstraints.WEST;
gridBagConstraints8.gridx = 2;
GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
gridBagConstraints7.fill = GridBagConstraints.VERTICAL;
gridBagConstraints7.gridy = 1;
gridBagConstraints7.weightx = 1.0;
gridBagConstraints7.anchor = GridBagConstraints.WEST;
gridBagConstraints7.gridx = 2;
GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
gridBagConstraints5.gridx = 1;
gridBagConstraints5.anchor = GridBagConstraints.EAST;
gridBagConstraints5.gridy = 6;
loweremptyLabel = new JLabel();
loweremptyLabel.setText(" ");
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.gridx = 1;
gridBagConstraints4.anchor = GridBagConstraints.EAST;
gridBagConstraints4.gridy = 4;
typeLabel = new JLabel();
typeLabel.setText("Type");
typeLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.gridx = 1;
gridBagConstraints3.anchor = GridBagConstraints.EAST;
gridBagConstraints3.gridy = 3;
statusLabel = new JLabel();
statusLabel.setText("Status");
statusLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.gridx = 1;
gridBagConstraints2.anchor = GridBagConstraints.EAST;
gridBagConstraints2.gridy = 2;
pathLabel = new JLabel();
pathLabel.setText("Path");
pathLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 1;
gridBagConstraints1.anchor = GridBagConstraints.EAST;
gridBagConstraints1.gridy = 1;
nameLabel = new JLabel();
nameLabel.setText("Name");
nameLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.anchor = GridBagConstraints.EAST;
gridBagConstraints.gridy = 0;
topemptyLabel = new JLabel();
topemptyLabel.setText(" ");
this.setSize(300, 200);
this.setLayout(new GridBagLayout());
this.add(topemptyLabel, gridBagConstraints);
this.add(nameLabel, gridBagConstraints1);
this.add(pathLabel, gridBagConstraints2);
this.add(statusLabel, gridBagConstraints3);
this.add(typeLabel, gridBagConstraints4);
this.add(loweremptyLabel, gridBagConstraints5);
this.add(getNameTextField(), gridBagConstraints7);
this.add(getPathTextField1(), gridBagConstraints8);
this.add(getStatusComboBox(), gridBagConstraints10);
this.add(getTypeComboBox(), gridBagConstraints11);
this.add(leftemptyLabel, gridBagConstraints12);
this.add(rightemptyLabel, gridBagConstraints13);
this.add(getNewButton(), gridBagConstraints14);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
*
*/
package org.projectopen.browser;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableModel;
/**
* @author fraber
*
*/
public class ObjectListPanel extends JPanel {
private static final long serialVersionUID = 1L;
private JScrollPane objectScrollPane = null;
private JTable objectTable = null;
private String objectType = null;
/**
* This method initializes objectScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getObjectScrollPane(String objectType) {
if (objectScrollPane == null) {
objectScrollPane = new JScrollPane();
JTable objectTable = getObjectTable(objectType);
objectScrollPane.setViewportView(objectTable);
objectTable.setFillsViewportHeight(true);
objectTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
return objectScrollPane;
}
/**
* This method initializes objectTable
*
* @return javax.swing.JTable
*/
private JTable getObjectTable(String objectType) {
if (objectTable == null) {
objectTable = new JTable();
TableModel model = new ObjectListTableModel(objectType);
objectTable.setModel(model);
System.out.println();
}
return objectTable;
}
public ObjectListPanel(String objectType) {
super();
this.setObjectType(objectType);
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.gridy = 0;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.gridx = 0;
this.setSize(300, 200);
this.setLayout(new GridBagLayout());
this.add(getObjectScrollPane(objectType), gridBagConstraints);
}
protected String getObjectType() {
return objectType;
}
protected void setObjectType(String oType) {
if (oType != this.objectType) {
this.objectType = oType;
}
}
/**
* @param args
*/
public static void main(String[] args) {
String objectType = "im_ticket";
JFrame frame = new JFrame("Objects");
JComponent panel = new ObjectListPanel(objectType);
frame.add(panel);
frame.pack();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setVisible(true);
}
}
package org.projectopen.browser;
import java.util.AbstractMap;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.projectopen.rest.ProjopObject;
import org.projectopen.rest.ProjopObjectType;
@SuppressWarnings("unchecked")
public class ObjectListTableModel extends AbstractTableModel {
private static final long serialVersionUID = 2655637231029122476L;
private String objectType = null;
public ObjectListTableModel(String oType) {
super();
this.objectType = oType;
}
public String getColumnName(int columnIndex) {
ProjopObjectType oType = (ProjopObjectType)ProjopObjectType.getObjectType(objectType);
List varList = oType.getVarList();
Object o = varList.get(columnIndex);
return (String)o;
}
public Class getColumnClass(int columnIndex) {
return String.class;
}
@Override
public int getColumnCount() {
ProjopObjectType oType = (ProjopObjectType)ProjopObjectType.getObjectType(objectType);
if (null == oType) { return 0; }
AbstractMap instances = oType.getInstances();
if (null == instances || instances.isEmpty()) { return 0; }
ProjopObject first = (ProjopObject)instances.values().iterator().next();
if (null == first) { return 0; }
return first.getVars().size();
}
@Override
public int getRowCount() {
ProjopObjectType oType = (ProjopObjectType)ProjopObjectType.getObjectType(objectType);
if (null == oType) { return 0; }
AbstractMap instances = oType.getInstances();
if (null == instances || instances.isEmpty()) { return 0; }
return instances.size();
}
@Override
public Object getValueAt(int row, int col) {
ProjopObjectType oType = (ProjopObjectType)ProjopObjectType.getObjectTypes().get(this.objectType);
if (null == oType) { return null; }
AbstractMap instances = oType.getInstances();
if (null == instances || instances.isEmpty()) { return null; }
ProjopObject o = (ProjopObject)instances.values().toArray()[row];
return o.getVars().values().toArray()[col];
}
}
package org.projectopen.custportal;
import java.util.List;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;
import org.projectopen.rest.ProjopProject;
import org.projectopen.rest.RESTClient;
public class CustomerPortalProjectTableModel extends AbstractTableModel {
private String[] columnNames = {"Project Name", "Project Manager", "Status"};
private String[] varNames = {"project_name", "project_manager_id", "project_status_id"};
private List data;
public CustomerPortalProjectTableModel() {
initialize();
}
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.size();
}
public String getColumnName(int col) {
return columnNames[col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public Object getValueAt(int row, int col) {
ProjopProject project = (ProjopProject)data.get(row);
return(project.get(varNames[col]));
}
private void initialize() {
RESTClient rest = RESTClient.defaultInstance();
data = rest.fromQuery("im_project", "project_id = 79055");
System.out.println("CustomerPortalProjectTableModel initialized");
}
}
package org.projectopen.custportal;
import java.awt.LayoutManager;
import java.awt.datatransfer.DataFlavor;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDropEvent;
import java.io.File;
import java.util.List;
import javax.swing.*;
import javax.swing.table.TableModel;
import org.projectopen.timesheet.TrayIconStarter;
import org.projectopen.custportal.CustomerPortalProjectTableModel;
public class ProjectList extends JPanel {
public ProjectList() {
// TODO Auto-generated constructor stub
}
/**
* This is the default constructor
*/
public ProjectList(TrayIconStarter p) {
super();
initialize();
}
public ProjectList(LayoutManager arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public ProjectList(boolean arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public ProjectList(LayoutManager arg0, boolean arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
}
private void initialize () {
String[] columnNames = {"Project","PM", "Status"};
Object[][] data = {
{"P1", "PM1", "open"},
{"P2", "PM1", "open"},
{"P3", "PM2", "closed"}
};
TableModel model = new CustomerPortalProjectTableModel();
JTable table = new JTable(model);
this.add(table);
table.setDropTarget(new DropTarget() {
private static final long serialVersionUID = 1377460693690256015L;
public synchronized void drop(DropTargetDropEvent evt) {
try {
evt.acceptDrop(DnDConstants.ACTION_COPY);
List<File> droppedFiles = (List)evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
for (File file : droppedFiles) {
// process files
System.out.println(file.toString());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
/**
*
*/
/**
* @author fraber
*
*/
package org.projectopen.custportal;
\ No newline at end of file
/*
* Copyright (c) 1995 - 2008 Sun Microsystems, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Sun Microsystems nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.projectopen.debug;
import java.awt.*;
import javax.swing.*;
/**
* Simple debug panel for the ]po[ Time Sheet application.
* @author Frank Bergmann (frank.bergmann@project-open.com)
*/
public class DebugPanel extends JPanel implements Logger {
private static final long serialVersionUID = 6001389192607262150L;
protected JTextField textField;
protected JTextArea textArea;
private final static String newline = "\n";
public DebugPanel() {
super(new GridBagLayout());
textArea = new JTextArea(60, 80);
textArea.setEditable(false);
// use a small font for loads of debugging output...
textArea.setFont(new Font("Tahoma", Font.PLAIN, 11));
JScrollPane scrollPane = new JScrollPane(textArea);
//Add Components to this panel.
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
add(scrollPane, c);
}
public void logMessage(int level, String domain, String message, String details) {
String levelString = "undefined";
switch (level) {
case Logger.DEBUG: levelString = "DEBUG"; break;
case Logger.INFO: levelString = "INFO"; break;
case Logger.WARNING: levelString = "WARNING"; break;
case Logger.ERROR: levelString = "ERROR"; break;
case Logger.FATAL: levelString = "FATAL"; break;
}
String msg = levelString + ": " + domain + ": " + message;
textArea.append(msg + newline);
if (null != details && "" != details) {
textArea.append(details + newline);
}
//Make sure the new text is visible, even if there
//was a selection in the text area.
textArea.setCaretPosition(textArea.getDocument().getLength());
}
}
package org.projectopen.debug;
/*
* Copyright (C) 2010 ]project-open[
*
* This program is free software. You can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option)
* any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @author Frank Bergmann (frank.bergmann@project-open.com)
*
*/
import java.io.*;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import com.sun.org.apache.xerces.internal.parsers.DOMParser;
/**
* Simple XML Document printer.
* This class is used to debug the replies from the
* ]po[ REST Web Service.
*
* @autor Frank Bergmann <frank.bergmann@project-open.com>
*/
public class DomPrinter
{
boolean validation = true;
DOMParser myDOMParser;
String xmlFile = null;
InputStream stream = null;
Document doc;
public DomPrinter(String fileName) { xmlFile = fileName; }
public DomPrinter(InputStream s) { stream = s; }
/**
* Print out the contents of an correctly initialized
* DomPrinter.
*
* However, to print out an Element it's easier to use
* the static walk() method below.
*/
public void print()
{
try {
myDOMParser = (DOMParser) new DOMParser();
//To validate or not
myDOMParser.setFeature( "http://xml.org/sax/features/validation", validation);
if (xmlFile != null) {
myDOMParser.parse(xmlFile);
} else {
InputSource source = new InputSource (stream);
myDOMParser.parse(source);
}
doc = myDOMParser.getDocument();
walk(doc);
}
catch(Exception e) { System.out.println("Errors " + e); }
}
/**
* Walk the DOM tree and print as you go
* @param node
*/
public static void walk(Node node)
{
if (node == null) { return; }
int type = node.getNodeType();
switch(type) {
case Node.DOCUMENT_NODE: {
System.out.println("<?xml version=\"1.0\" encoding=\"" + "UTF-8" + "\"?>");
break;
}
case Node.ELEMENT_NODE: {
System.out.print('<' + node.getNodeName() );
NamedNodeMap nnm = node.getAttributes();
if(nnm != null ) {
int len = nnm.getLength() ;
Attr attr;
for ( int i = 0; i < len; i++ ) {
attr = (Attr)nnm.item(i);
System.out.print(' ' + attr.getNodeName() + "=\"" + attr.getNodeValue() + '"' );
}
}
System.out.print('>');
break;
}
case Node.ENTITY_REFERENCE_NODE: {
System.out.print('&' + node.getNodeName() + ';' );
break;
}
case Node.CDATA_SECTION_NODE: {
System.out.print( "<![CDATA[" + node.getNodeValue() + "]]>" );
break;
}
case Node.TEXT_NODE: {
System.out.print(node.getNodeValue());
break;
}
case Node.PROCESSING_INSTRUCTION_NODE: {
System.out.print("<?" + node.getNodeName());
String data = node.getNodeValue();
if ( data != null && data.length() > 0 ) {
System.out.print(' ');
System.out.print(data);
}
System.out.println("?>");
break;
}
}
// recurse
for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
walk(child);
}
// without this the ending tags will miss
if ( type == Node.ELEMENT_NODE ) {
System.out.print("</" + node.getNodeName() + ">");
}
}
}
\ No newline at end of file
package org.projectopen.debug;
/**
* Simple logger interface.
*
* We use this interface to allow the TrayIconStarter
* (or other starter classes) to be used to display
* debug and error messages to the user.
*
* @author Frank Bergmann
*
*/
public interface Logger {
public static final int DEBUG = 0; // Normal operations
public static final int INFO = 1; // Inform user about a situation which might not be an error
public static final int WARNING = 2; // System can deal with the issue itself.
public static final int ERROR = 3; // Important application error - requires user action
public static final int FATAL = 4; // Can't continue the application after that
/**
* Print out an error message at a suitable location.
* @param level Debug level between 0=DEBUG and 4=FATAL.
* Please see static constants
* @param domain Short sized error domain ("Application error", "Server error", ...)
* @param message Medium sized Message string (20-300 characters)
* @param details Details of the message (potentially very long)
*/
public void logMessage(int level, String domain, String message, String details);
}
package org.projectopen.debug;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import org.projectopen.serverstatus.TrayIconServiceStarter;
public class SystemLogger implements Logger {
public void logMessage(int level, String domain, String message, String details) {
String levelString = "undefined";
switch (level) {
case Logger.DEBUG: levelString = "DEBUG"; break;
case Logger.INFO: levelString = "INFO"; break;
case Logger.WARNING: levelString = "WARNING"; break;
case Logger.ERROR: levelString = "ERROR"; break;
case Logger.FATAL: levelString = "FATAL"; break;
}
String msg = levelString + ": " + domain + ": " + message;
System.out.println(msg);
}
}
/**
*
*/
/**
* @author fraber
*
*/
package org.projectopen.debug;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment