All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.fedora.client.BatchBuildIngestGUI Maven / Gradle / Ivy

Go to download

The Fedora Client is a Java Library that allows API access to a Fedora Repository. The client is typically one part of a full Fedora installation.

The newest version!
/*
 * -----------------------------------------------------------------------------
 *
 * 

License and Copyright: The contents of this file are subject to the * Apache License, Version 2.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of * the License at * http://www.fedora-commons.org/licenses.

* *

Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License.

* *

The entire file consists of original code.

*

Copyright © 2008 Fedora Commons, Inc.
*

Copyright © 2002-2007 The Rector and Visitors of the University of * Virginia and Cornell University
* All rights reserved.

* * ----------------------------------------------------------------------------- */ package fedora.client; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JRadioButton; import javax.swing.ButtonGroup; import java.awt.BorderLayout; import java.awt.FileDialog; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import fedora.client.Administrator; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import javax.swing.JFileChooser; import java.util.Properties; import java.util.HashMap; import java.awt.Dimension; import java.awt.Graphics; import java.awt.FontMetrics; import javax.swing.Box; import javax.swing.JFrame; import javax.swing.JComponent; import fedora.swing.mdi.MDIDesktopPane; /** * *

* Title: BatchBuildIngestGUI.java *

*

* Description: *

* * @author [email protected] * @version $Id: BatchBuildIngestGUI.java 5166 2006-10-25 11:05:45Z eddie $ */ public class BatchBuildIngestGUI extends JInternalFrame { private static final long serialVersionUID = 1L; // private static File s_lastDir; private JTextField m_templateField = new JTextField("", 10); private JTextField m_specsField = new JTextField("", 10); private JTextField m_objectsField = new JTextField("", 10); private JTextField m_pidsField = new JTextField("", 10); private JRadioButton m_xmlMap = new JRadioButton("xml"); private JRadioButton m_textMap = new JRadioButton("text"); private ButtonGroup buttonGroup = new ButtonGroup(); private JRadioButton m_foxmlMap = new JRadioButton("foxml"); private JRadioButton m_metsMap = new JRadioButton("mets"); private ButtonGroup templateButtonGroup = new ButtonGroup(); private Dimension unitDimension = null; private Dimension browseMin = null; private Dimension browsePref = null; private Dimension browseMax = null; private Dimension textMin = null; private Dimension textPref = null; private Dimension textMax = null; private Dimension okMin = null; private Dimension okPref = null; private Dimension okMax = null; private static HashMap formatMap = new HashMap(); private MDIDesktopPane mdiDesktopPane = null; BatchOutput batchOutput = new BatchOutput("Batch Build and Ingest Output"); private final String host; private final String port; private final String user; private final String pass; public BatchBuildIngestGUI(JFrame parent, MDIDesktopPane mdiDesktopPane, String host, int port, String user, String pass) { super("Batch Build and Ingest", true, // resizable true, // closable true, // maximizable true);// iconifiable this.host = host; this.port = Integer.toString(port); this.user = user; this.pass = pass; formatMap.put("foxml1.0", "FOXML"); formatMap.put("metslikefedora1", "METS"); this.mdiDesktopPane = mdiDesktopPane; JButton btn = new JButton("Build and Ingest this batch"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { buildBatch(); } }); JPanel entryPanel = new JPanel(); entryPanel.setLayout(new BorderLayout()); entryPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); entryPanel.add(new JLabel("Build and Ingest Criteria"), BorderLayout.NORTH); JPanel labelPanel = new JPanel(); labelPanel.setLayout(new GridLayout(0, 3)); Graphics graphicsTemp = parent.getGraphics(); FontMetrics fmTemp = graphicsTemp.getFontMetrics(); int maxWidth = 0; { int[] temp = fmTemp.getWidths(); for (int i = 0; i < temp.length; i++) { if (temp[i] > maxWidth) { maxWidth = temp[i]; } } } unitDimension = new Dimension((new Float(1.5 * maxWidth)).intValue(), fmTemp.getHeight()); browseMin = new Dimension(12 * unitDimension.width, unitDimension.height); // 9*unitDimension.width browseMax = new Dimension(2 * browseMin.width, 2 * browseMin.height); browsePref = browseMin; textMin = new Dimension(22 * unitDimension.width, unitDimension.height); textMax = new Dimension(2 * textMin.width, 2 * textMin.height); textPref = textMin; okMin = new Dimension(9 * unitDimension.width, unitDimension.height); okMax = new Dimension((new Float(1.5 * okMin.width)).intValue(), (new Float(1.5 * okMin.height)).intValue()); okPref = okMax; labelPanel.add(new JLabel("Object template (input file)")); labelPanel.add(sized(m_templateField, textMin, textPref, textMax)); JButton templateBtn = new JButton("browse..."); templateBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { templateAction(); } }); labelPanel.add(sized(templateBtn, browseMin, browsePref, browseMax)); /* * templateButtonGroup.add(m_foxmlMap); m_foxmlMap.setSelected(true); * templateButtonGroup.add(m_metsMap); JPanel templatePanel = new * JPanel(); * * templatePanel.setLayout(new BorderLayout()); * templatePanel.add(m_foxmlMap, BorderLayout.WEST); * templatePanel.add(new JLabel("Template file (input file)"), * BorderLayout.NORTH); templatePanel.add(m_metsMap, * BorderLayout.CENTER); labelPanel.add(sized (templatePanel, browseMin, * browsePref, browseMax)); * * labelPanel.add(sized (m_templateField, textMin, textPref, textMax)); * JButton templateBtn=new JButton("browse..."); * templateBtn.addActionListener(new ActionListener() { public void * actionPerformed(ActionEvent e) { templateAction(); } }); * * labelPanel.add(sized (templateBtn, browseMin, browsePref, * browseMax)); */ labelPanel.add(new JLabel("XML specs (input directory)")); labelPanel.add(sized(m_specsField, textMin, textPref, textMax)); JButton specsBtn = new JButton("browse..."); specsBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { specsAction(); } }); labelPanel.add(sized(specsBtn, browseMin, browsePref, browseMax)); labelPanel.add(new JLabel("Fedora objects (output directory)")); labelPanel.add(sized(m_objectsField, textMin, textPref, textMax)); JButton objectsBtn = new JButton("browse..."); objectsBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { objectsAction(); } }); labelPanel.add(sized(objectsBtn, browseMin, browsePref, browseMax)); buttonGroup.add(m_xmlMap); m_xmlMap.setSelected(true); buttonGroup.add(m_textMap); JPanel jPanel = new JPanel(); jPanel.setLayout(new BorderLayout()); jPanel.add(m_xmlMap, BorderLayout.WEST); jPanel.add(new JLabel("object processing map (output file)"), BorderLayout.NORTH); jPanel.add(m_textMap, BorderLayout.CENTER); labelPanel.add(sized(jPanel, browseMin, browsePref, browseMax)); labelPanel.add(sized(m_pidsField, textMin, textPref, textMax)); JButton pidsBtn = new JButton("browse..."); pidsBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pidsAction(); } }); labelPanel.add(sized(pidsBtn, browseMin, browsePref, browseMax)); // labelPanel.add(sized (m_textMap, browseMin, browsePref, browseMax)); entryPanel.add(labelPanel, BorderLayout.WEST); getContentPane().setLayout(new BorderLayout()); getContentPane().add(entryPanel, BorderLayout.CENTER); getContentPane().add(sized(btn, okMin, okPref, okMax, true), BorderLayout.SOUTH); setFrameIcon(new ImageIcon(this.getClass().getClassLoader() .getResource("images/standard/general/New16.gif"))); pack(); setSize(getSize().width + 20, getSize().height * 2); // setSize(400,400); } private final void sizeIt(JComponent jc, Dimension min, Dimension pref, Dimension max) { jc.setMinimumSize(min); jc.setPreferredSize(pref); jc.setMaximumSize(max); } private final Box sized(JComponent jc, Dimension min, Dimension pref, Dimension max, boolean centered) { sizeIt(jc, min, pref, max); Box box = Box.createHorizontalBox(); if (centered) { box.add(Box.createGlue()); } box.add(jc); if (centered) { box.add(Box.createGlue()); } return box; } private final Box sized(JComponent jc, Dimension min, Dimension pref, Dimension max) { return sized(jc, min, pref, max, false); } public void buildBatch() { try { if (!m_templateField.getText().equals("") && !m_specsField.getText().equals("") && !m_objectsField.getText().equals("") && !m_pidsField.getText().equals("")) { Properties properties = new Properties(); properties.setProperty("merge-objects", "yes"); properties.setProperty("ingest", "yes"); properties.setProperty("template", m_templateField.getText()); properties.setProperty("specifics", m_specsField.getText()); properties.setProperty("objects", m_objectsField.getText()); properties.setProperty("ingested-pids", m_pidsField.getText()); properties.setProperty("pids-format", m_xmlMap.isSelected() ? "xml" : "text"); properties.setProperty("server-fqdn", host); properties.setProperty("server-port", port); properties.setProperty("username", user); properties.setProperty("password", pass); properties.setProperty("server-protocol", Administrator .getProtocol()); // properties.setProperty("object-format",m_foxmlMap.isSelected()? // "foxml1.0" : "metslikefedora1"); // Verify format of template file to see if it is a METS or // FOXML template BufferedReader br = new BufferedReader(new FileReader( m_templateField.getText())); String line; String objectFormat = null; while ((line = br.readLine()) != null) { if (line.indexOf("




© 2015 - 2025 Weber Informatics LLC | Privacy Policy