package org.jenkinsci.plugins.IBM_zOS_Connector;


import hudson.model.Run;
import hudson.scm.ChangeLogParser;
import hudson.scm.RepositoryBrowser;
import org.apache.commons.digester3.Digester;
import org.xml.sax.SAXException;

import java.io.*;

/**
 * <h1>SCLMChangeLogParser</h1>
 *
 * Parser of changelog.xml from SCLM.
 *
 * @author <a href="mailto:candiduslynx@gmail.com">Alexander Shcherbakov</a>
 *
 * @version 1.0
 *
 * @see SCLMChangeLogSet
 * @see LogSet
 * @see ChangeLogParser
 */
public class SCLMChangeLogParser extends ChangeLogParser {
    /**
     * Parse changelog.xml.
     *
     * @param build Current build.
     * @param browser Current browser.
     * @param changelogFile changelog.xml
     *
     * @return SCLMChangeLogSet from changelog.xml.
     *
     */
    @Override
    public SCLMChangeLogSet parse(Run build, RepositoryBrowser<?> browser,
                                                            File changelogFile)
        throws IOException,
        SAXException
    {
        Digester digester = new Digester();

        // Parse fields.
        digester.addObjectCreate("*/changelog", LogSet.class);
        digester.addSetProperties("*/changelog");
        digester.addObjectCreate("*/changelog/entry", LogSet.Entry.class);
        digester.addSetProperties("*/changelog/entry");
        digester.addBeanPropertySetter("*/changelog/entry/date", "changeDate");
        digester.addBeanPropertySetter("*/changelog/entry/project");
        digester.addBeanPropertySetter("*/changelog/entry/alternate");
        digester.addBeanPropertySetter("*/changelog/entry/group");
        digester.addBeanPropertySetter("*/changelog/entry/type");
        digester.addBeanPropertySetter("*/changelog/entry/name");
        digester.addBeanPropertySetter("*/changelog/entry/version");
        digester.addBeanPropertySetter("*/changelog/entry/userID");
        digester.addBeanPropertySetter("*/changelog/entry/changeGroup");
        digester.addBeanPropertySetter("*/changelog/entry/editType");
        digester.addSetNext("*/changelog/entry", "addEntry");

        // Do the actual parsing
        InputStreamReader reader = new InputStreamReader(new FileInputStream(changelogFile), "UTF-8");
        LogSet temp = (LogSet)digester.parse(reader);
        reader.close();

        // Convert to SCLMChangeLogSet
        SCLMChangeLogSet res = new SCLMChangeLogSet(build,browser);
        res.fromLogSet(temp);
        return res;
    }
}

@@ -221,16 +221,71 @@
 ption;%0A%0A
+import javax.xml.parsers.ParserConfigurationException;%0A
 import j
@@ -1099,24 +1099,773 @@
 igester();%0A%0A
+        digester.setXIncludeAware(false);%0A%0A        if (!Boolean.getBoolean(SCLMChangeLogParser.class.getName() + %22.UNSAFE%22)) %7B%0A            try %7B%0A                digester.setFeature(%22http://apache.org/xml/features/disallow-doctype-decl%22, true);%0A                digester.setFeature(%22http://xml.org/sax/features/external-general-entities%22, false);%0A                digester.setFeature(%22http://xml.org/sax/features/external-parameter-entities%22, false);%0A                digester.setFeature(%22http://apache.org/xml/features/nonvalidating/load-external-dtd%22, false);%0A            %7D%0A            catch ( ParserConfigurationException ex) %7B%0A                throw new SAXException(%22Failed to securely configure Zos changelog parser%22, ex);%0A            %7D%0A        %7D%0A%0A
         // P

fix digester security configuration (#13)