package org.greenstone.admin.gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Writer; import javax.swing.*; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; //import org.apache.tools.ant.Project; //import org.apache.tools.ant.ProjectHelper; import org.greenstone.gsdl3.util.GSPath; import org.greenstone.gsdl3.util.GlobalProperties; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Iterator; import java.util.Properties; import java.util.Set; public class Mat extends adminUI_Pane{ JButton start_button; JButton enable_disable_button; JButton option_button; JButton description_control_button; JButton control_description_button; JPanel description_control_button_pane; JPanel control_content_pane; JPanel control_button_pane; JPanel control_description_pane; JLabel install_path; JLabel oai_temp_directory; JTextField install_path_text; JTextField oai_temp_directory_text; JCheckBox web_tool_checkbox; JCheckBox java_tool_checkbox; SimpleDateFormat sdf; private GlobalProperties globalProperty = null; private final String fileSeparator = File.separator; private GSPath gspath = null; static final int left_margin = 7; static final int right_margin = 7; static final int HORIZONTAL_GAP = 5; static final int VERTICAL_GAP = 5; String install_options_filePath = null; static String extension_list_path; static String extension_buildProperty_path; static String extension_runtimeProperty_path; static String extension_log_path; static String extension_log_directory; static String extension_path; static String os_type; static String oai_folder; static String web_xml_path; static final String InstallCompleteMsg = "The extension (Mat) has been installed successfully."; static final String InstallErrorMsg = "Sorry, the extension (Mat) could not be installed. Please try again!"; static final String DownloadCompleteMsg = "The extension (Mat) has been downloaded successfully."; static final String DownloadErrorMsg = "Sorry, the extension (Mat) could not be downloaded. Please try again!"; public Mat(){} public Mat (String extensionName){ group = new String(); description = new String(); download_type = new String(); extension_name = extensionName; url = new String(); configurable = new Boolean(false); os_type = System.getProperty("os.name"); String gsdl3Home = get_GSDL3HOME(); extension_list_path = gsdl3Home+fileSeparator+"ext"+fileSeparator+"extension_project_list.xml"; extension_buildProperty_path = gsdl3Home+fileSeparator+"ext"+fileSeparator+"mat"+fileSeparator+"build.properties"; extension_runtimeProperty_path = gsdl3Home+fileSeparator+"ext"+fileSeparator+"mat"+fileSeparator+"properties.xml"; extension_log_path = gsdl3Home+fileSeparator+"ext"+fileSeparator+"logs"+fileSeparator+"mat"+fileSeparator+"extension_log.xml"; extension_log_directory = gsdl3Home+fileSeparator+"ext"+fileSeparator+"logs"+fileSeparator+"mat"; extension_path = gsdl3Home+fileSeparator+"ext"+fileSeparator+"mat"+fileSeparator; oai_folder = gsdl3Home+fileSeparator+"ext"+fileSeparator+"mat"+fileSeparator+"tmp"+fileSeparator; web_xml_path = gsdl3Home+fileSeparator+"web"+fileSeparator+"WEB-INF"+fileSeparator+"web.xml"; start_button = new JButton("Analyse"); start_button.setPreferredSize(new Dimension(50,25)); start_button.setMaximumSize(new Dimension(50,25)); start_button.setName("Analyse"); start_button.setEnabled(false); start_button.addActionListener(new aListener(this)); enable_disable_button = new JButton("Enable"); enable_disable_button.setName("enable_disable"); enable_disable_button.setVisible(false); enable_disable_button.addActionListener(new aListener(this)); enable_disable_button.setPreferredSize(new Dimension(50,25)); enable_disable_button.setMaximumSize(new Dimension(50,25)); option_button = new JButton("Options"); option_button.setName("options"); option_button.addActionListener(new aListener(this)); control_description_button = new JButton("Description"); control_description_button.setName("control_description"); control_description_button.addActionListener(new aListener(this)); description_control_button = new JButton("Control Panel"); description_control_button.setName("description_control"); description_control_button.addActionListener(new aListener(this)); description_control_button.setEnabled(getCommandStatus("install")); description_control_button_pane = new JPanel(new GridLayout(1,3)); description_pane = new JScrollPane (); control_pane = new JPanel (); descriptionTextArea = new JTextArea(); button_pane = new JPanel(); oai_temp_directory = new JLabel(); oai_temp_directory.setText("OAI temporary download directory:"); oai_temp_directory_text = new JTextField(); oai_temp_directory_text.setText(oai_folder); oai_temp_directory_text.setEditable(false); oai_temp_directory_text.setBackground(Color.WHITE); install_path = new JLabel(); install_path.setText("Metadata Quality Tool is installed in:"); install_path_text = new JTextField(); install_path_text.setText(extension_path); install_path_text.setEditable(false); install_path_text.setBackground(Color.WHITE); web_tool_checkbox = new JCheckBox("Web OAI Collection Building"); web_tool_checkbox.setBorder(BorderFactory.createEmptyBorder(0,0,0,0)); web_tool_checkbox.setVisible(false); java_tool_checkbox = new JCheckBox("Local Collection Analysis"); java_tool_checkbox.addItemListener(new checkBoxStatus(this)); java_tool_checkbox.setBorder(BorderFactory.createEmptyBorder(0,0,0,0)); GridLayout gridLayout3 = new GridLayout(3,3); gridLayout3.setVgap(VERTICAL_GAP); control_content_pane = new JPanel(gridLayout3); control_content_pane.setBorder(BorderFactory.createEmptyBorder(5, left_margin, 5, right_margin)); GridLayout gridLayout2 = new GridLayout(1,2); gridLayout2.setHgap(HORIZONTAL_GAP); control_button_pane = new JPanel(gridLayout2); control_button_pane.setBorder(BorderFactory.createEmptyBorder(5, left_margin, 5, right_margin)); GridLayout gridLayout1 = new GridLayout(2,2); gridLayout1.setVgap(VERTICAL_GAP); control_description_pane = new JPanel(gridLayout1); control_description_pane.setBorder(BorderFactory.createEmptyBorder(5, left_margin, 5, right_margin)); control_pane = new JPanel(); control_pane.setLayout(new BoxLayout(control_pane, BoxLayout.Y_AXIS)); setup(); setupControlPane(); loadProjectInformation(); }; public JPanel getControlPane(){ return control_pane; } public JPanel getButtonPane(){ return button_pane; } public JPanel getDescriptionPane(){ description_control_button_pane.add(Box.createRigidArea(new Dimension(18,5))); description_control_button_pane.add(description_control_button); description_control_button_pane.add(Box.createRigidArea(new Dimension(18,5))); main_pane = new JPanel(new BorderLayout()); main_pane.add(description_pane, BorderLayout.CENTER); main_pane.add(description_control_button_pane, BorderLayout.SOUTH); return main_pane; } private void setupControlPane(){ control_content_pane.add(java_tool_checkbox); control_content_pane.add(Box.createRigidArea(new Dimension(10,5))); control_content_pane.add(Box.createRigidArea(new Dimension(10,5))); JPanel tempPane = new JPanel(new BorderLayout()); tempPane.add(Box.createRigidArea(new Dimension(18,5)), BorderLayout.WEST); tempPane.add(start_button, BorderLayout.CENTER); control_content_pane.add(tempPane); control_content_pane.add(Box.createRigidArea(new Dimension(10,5))); control_content_pane.add(Box.createRigidArea(new Dimension(10,5))); //control_content_pane.add(web_tool_checkbox); control_content_pane.add(Box.createRigidArea(new Dimension(10,5))); control_content_pane.add(Box.createRigidArea(new Dimension(10,5))); control_content_pane.add(Box.createRigidArea(new Dimension(10,5))); /* JPanel tempPane2 = new JPanel(new BorderLayout()); tempPane2.add(Box.createRigidArea(new Dimension(18,5)), BorderLayout.WEST); tempPane2.add(enable_disable_button, BorderLayout.CENTER); control_content_pane.add(tempPane2); control_content_pane.add(Box.createRigidArea(new Dimension(10,5))); control_content_pane.add(Box.createRigidArea(new Dimension(10,5))); */ control_description_pane.add(install_path); control_description_pane.add(install_path_text); control_description_pane.add(oai_temp_directory); control_description_pane.add(oai_temp_directory_text); control_button_pane.add(control_description_button); control_button_pane.add(option_button); control_content_pane.setAlignmentX(Component.LEFT_ALIGNMENT); control_pane.add(control_content_pane); control_description_pane.setAlignmentX(Component.LEFT_ALIGNMENT); control_pane.add(control_description_pane); control_button_pane.setAlignmentX(Component.LEFT_ALIGNMENT); control_pane.add(control_button_pane); } protected Object[][] getConfigureContent(){ return null; } public Boolean isConfigurable(){ return configurable ; } public String getDestinationLocation(){ return destination_folder; } public String getDownloadLocation(){ return url; } public String getDownloadType(){ return download_type; } protected void loadProjectInformation(){ Element rootNode = getRootElement(extension_list_path); NodeList projectNodeList = rootNode.getElementsByTagName(EXTENSION); for(int i = 0; i < projectNodeList.getLength(); i++){ Element projectNode = (Element)projectNodeList.item(i); NodeList nameNodeList = projectNode.getElementsByTagName(NAME); String name = nameNodeList.item(0).getChildNodes().item(0).getNodeValue(); if(name.equalsIgnoreCase(extension_name)){ NodeList groupNodeList = projectNode.getElementsByTagName(GROUP); group = groupNodeList.item(0).getChildNodes().item(0).getNodeValue(); NodeList stepList = projectNode.getElementsByTagName(STEP); GridLayout gl = new GridLayout(stepList.getLength(),1); gl.setVgap(5); button_pane.setLayout(gl); for (int y = 0; y< stepList.getLength(); y++){ Node e = stepList.item(y); Element stepElement = (Element) e; JButton button = new JButton(); String command = stepElement.getAttribute("action"); button.setText(stepElement.getAttribute("label")); button.setName(command); button.addActionListener(new aListener(this)); boolean status = getCommandStatus(command); button.setEnabled(status); if(stepElement.getAttribute("action").equalsIgnoreCase(DOWNLOAD)){ download_type = stepElement.getAttribute("method"); url = stepElement.getElementsByTagName("source").item(0).getChildNodes().item(0).getNodeValue(); //destination_folder = stepElement.getElementsByTagName("destination").item(0).getChildNodes().item(0).getNodeValue(); destination_folder = extension_path; } if(stepElement.getAttribute("action").equalsIgnoreCase("Install_option")){ //install_options_filePath = stepElement.getAttribute("filePath"); install_options_filePath = extension_path+"build.properties"; } button_pane.add(button); } } } } public boolean getCommandStatus (String command){ Element root = getRootElement(extension_list_path); NodeList extensionList = root.getElementsByTagName("extension"); boolean s = false; for(int i = 0; i < extensionList.getLength(); i++){ Element projectNode = (Element)extensionList.item(i); NodeList nameNodeList = projectNode.getElementsByTagName(NAME); String name = nameNodeList.item(0).getChildNodes().item(0).getNodeValue(); if(name.equalsIgnoreCase(extension_name)){ Element actionElement = (Element)extensionList.item(0); NodeList individual_extension_detail_list = actionElement.getElementsByTagName("sequence_list"); Node sequenceListNode = individual_extension_detail_list.item(0); NodeList sequenceDetailList = sequenceListNode.getChildNodes(); for(int j = 0; j < sequenceDetailList.getLength(); j++){ Node n = sequenceDetailList.item(j); if(n instanceof Element){ Element e = (Element)n; if(e.getAttribute("action").equalsIgnoreCase(command)){ String status = e.getAttribute("status"); Boolean bv = Boolean.valueOf(status); s = bv.booleanValue(); } } } } }// return s; } public void updateButtonPane(){ String gsdl3Home = get_GSDL3HOME(); Element root = getRootElement(extension_list_path); NodeList extensionList = root.getElementsByTagName("extension"); for(int a = 0; a < extensionList.getLength(); a++){ Element projectNode = (Element)extensionList.item(a); NodeList nameNodeList = projectNode.getElementsByTagName(NAME); String name = nameNodeList.item(0).getChildNodes().item(0).getNodeValue(); if(name.equalsIgnoreCase(extension_name)){ //System.out.println(extension_name); NodeList actionList = projectNode.getElementsByTagName("sequence_list"); //System.out.println(actionList.getLength()); Node x = actionList.item(0); NodeList stepList = x.getChildNodes(); for(int i = 0; i