Search in sources :

Example 1 with PerformFileModel

use of apps.PerformFileModel in project JMRI by JMRI.

the class PerformFileModelXml method load.

@Override
public boolean load(Element shared, Element perNode) throws JmriException {
    boolean result = true;
    String fileName = FileUtil.getAbsoluteFilename(shared.getAttribute("name").getValue());
    PerformFileModel m = new PerformFileModel();
    m.setFileName(fileName);
    InstanceManager.getDefault(StartupActionsManager.class).addAction(m);
    return result;
}
Also used : PerformFileModel(apps.PerformFileModel) StartupActionsManager(apps.StartupActionsManager)

Example 2 with PerformFileModel

use of apps.PerformFileModel in project JMRI by JMRI.

the class ReportPanel method sendButtonActionPerformed.

@SuppressWarnings("unchecked")
public void sendButtonActionPerformed(java.awt.event.ActionEvent e) {
    try {
        sendButton.setEnabled(false);
        log.debug("initial checks");
        InternetAddress email = new InternetAddress(emailField.getText());
        email.validate();
        log.debug("start send");
        //NO18N
        String charSet = "UTF-8";
        //NOI18N
        String requestURL = "http://jmri.org/problem-report.php";
        MultipartMessage msg = new MultipartMessage(requestURL, charSet);
        // add reporter email address
        log.debug("start creating message");
        msg.addFormField("reporter", emailField.getText());
        // add if to Cc sender
        msg.addFormField("sendcopy", checkCopy.isSelected() ? "yes" : "no");
        // add problem summary
        msg.addFormField("summary", summaryField.getText());
        // build detailed error report (include context if selected)
        String report = descField.getText() + "\r\n";
        if (checkContext.isSelected()) {
            //NOI18N
            report += "=========================================================\r\n";
            report += (new ReportContext()).getReport(checkNetwork.isSelected() && checkNetwork.isEnabled());
        }
        msg.addFormField("problem", report);
        log.debug("start adding attachments");
        // add panel file if OK
        if (checkPanel.isSelected()) {
            log.debug("prepare panel attachment");
            // Check that some startup panel files have been loaded
            for (PerformFileModel m : InstanceManager.getDefault(StartupActionsManager.class).getActions(PerformFileModel.class)) {
                String fn = m.getFileName();
                File f = new File(fn);
                log.debug("add startup panel file: {}", f);
                msg.addFilePart("logfileupload[]", f);
            }
            // Check that a manual panel file has been loaded
            File file = jmri.configurexml.LoadXmlUserAction.getCurrentFile();
            if (file != null) {
                log.debug("add manual panel file: {}", file.getPath());
                msg.addFilePart("logfileupload[]", jmri.configurexml.LoadXmlUserAction.getCurrentFile());
            } else {
                // No panel file loaded
                log.warn("No manual panel file loaded - not sending");
            }
        }
        // add profile files if OK
        if (checkProfile.isSelected()) {
            log.debug("prepare profile attachment");
            // Check that a profile has been loaded
            Profile profile = ProfileManager.getDefault().getActiveProfile();
            File file = profile.getPath();
            if (file != null) {
                log.debug("add profile: {}", file.getPath());
                // Now zip-up contents of profile
                // Create temp file that will be deleted when Java quits
                File temp = File.createTempFile("profile", ".zip");
                temp.deleteOnExit();
                FileOutputStream out = new FileOutputStream(temp);
                ZipOutputStream zip = new ZipOutputStream(out);
                addDirectory(zip, file);
                zip.close();
                out.close();
                msg.addFilePart("logfileupload[]", temp);
            } else {
                // No profile loaded
                log.warn("No profile loaded - not sending");
            }
        }
        // add the log if OK
        if (checkLog.isSelected()) {
            log.debug("prepare log attachments");
            // search for an appender that stores a file
            for (java.util.Enumeration<org.apache.log4j.Appender> en = org.apache.log4j.Logger.getRootLogger().getAllAppenders(); en.hasMoreElements(); ) {
                // does this have a file?
                org.apache.log4j.Appender a = en.nextElement();
                // see if it's one of the ones we know
                if (log.isDebugEnabled()) {
                    log.debug("check appender {}", a);
                }
                try {
                    org.apache.log4j.FileAppender f = (org.apache.log4j.FileAppender) a;
                    log.debug("find file: {}", f.getFile());
                    msg.addFilePart("logfileupload[]", new File(f.getFile()), "application/octet-stream");
                } catch (ClassCastException ex) {
                }
            }
        }
        log.debug("done adding attachments");
        // finalise and get server response (if any)
        log.debug("posting report...");
        List<String> response = msg.finish();
        log.debug("send complete");
        log.debug("server response:");
        boolean checkResponse = false;
        for (String line : response) {
            log.debug("               :{}", line);
            if (line.contains("<p>Message successfully sent!</p>")) {
                checkResponse = true;
            }
        }
        if (checkResponse) {
            JOptionPane.showMessageDialog(null, rb.getString("InfoMessage"), rb.getString("InfoTitle"), JOptionPane.INFORMATION_MESSAGE);
            // close containing Frame
            getTopLevelAncestor().setVisible(false);
        } else {
            // TODO add Bundle to folder and use ErrorTitle key in NamedBeanBundle props
            JOptionPane.showMessageDialog(null, rb.getString("ErrMessage"), rb.getString("ErrTitle"), JOptionPane.ERROR_MESSAGE);
            sendButton.setEnabled(true);
        }
    } catch (IOException ex) {
        log.error("Error when attempting to send report: " + ex);
        sendButton.setEnabled(true);
    } catch (AddressException ex) {
        log.error("Invalid email address: " + ex);
        // TODO add Bundle to folder and use ErrorTitle key in NamedBeanBundle props
        JOptionPane.showMessageDialog(null, rb.getString("ErrAddress"), rb.getString("ErrTitle"), JOptionPane.ERROR_MESSAGE);
        sendButton.setEnabled(true);
    }
}
Also used : MultipartMessage(jmri.util.MultipartMessage) InternetAddress(javax.mail.internet.InternetAddress) StartupActionsManager(apps.StartupActionsManager) IOException(java.io.IOException) Profile(jmri.profile.Profile) PerformFileModel(apps.PerformFileModel) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) AddressException(javax.mail.internet.AddressException) File(java.io.File)

Example 3 with PerformFileModel

use of apps.PerformFileModel in project JMRI by JMRI.

the class PerformFileModelXml method store.

/**
     * Default implementation for storing the model contents
     *
     * @param o Object to store, of type PerformActonModel
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element e = new Element("perform");
    PerformFileModel g = (PerformFileModel) o;
    e.setAttribute("name", FileUtil.getPortableFilename(g.getFileName()));
    e.setAttribute("type", "XmlFile");
    e.setAttribute("class", this.getClass().getName());
    return e;
}
Also used : PerformFileModel(apps.PerformFileModel) Element(org.jdom2.Element)

Aggregations

PerformFileModel (apps.PerformFileModel)3 StartupActionsManager (apps.StartupActionsManager)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 AddressException (javax.mail.internet.AddressException)1 InternetAddress (javax.mail.internet.InternetAddress)1 Profile (jmri.profile.Profile)1 MultipartMessage (jmri.util.MultipartMessage)1 Element (org.jdom2.Element)1