1

Assume I have this kind of file

SCHEDULE AEP#GSAE3_SCO_D99008 TIMEZONE ECT
DESCRIPTION "APOLLO_ MQFT SENDING JOBS"
ON RUNCYCLE RULE1 "FREQ=DAILY;"
:
AEP#GSAE3_SCO_D99008_ASUP_ORD_V4
 SCRIPTNAME "-job Z3_SCO_D99008_ASUP_ORD_V4 -user BECKDEL1 -i 04093800 -c C"
 STREAMLOGON batchatl
 DESCRIPTION "Take Customer Order to be send in MQFT format"
 TASKTYPE SAP
 RECOVERY STOP
 AT 2145 TIMEZONE ECT
NEEDS 1 AEP#GSAE_SCO

...
END

This is file from TWS (Tivoli Workload Scheduler). What I want to get is JSON or XML file looks like:

{
"Jobstream":"AEP#GSAE3_SCO_D99008",
"Timezone": "ECT",
"Description": "APOLLO_ MQFT SENDING JOBS",
"Jobs": {[
    "Job": "AEP#GSAE3_SCO_D99008_ASUP_ORD_V4",
    "SAP_JOB": "Z3_SCO_D99008_ASUP_ORD_V4",
    "SAP_USER": "BECKDEL1",
    "Id": 04093800,
    "Streamlogon": "batchatl",
    "Description": "Take Customer Order to be send in MQFT format",
    "Tasktype": "SAP",
    "Recovery": "STOP",
    "AT": 2145,
    "TIMEZONE": "ECT"
],[...]}

What I need to read to understand how can I parse this kind of file? I tried to use BufferReader and Scanner in Java. I already have 2 Java classes: JobStream and Job. JobStream:

public class Jobstream {
    private String name;
    private String timeZone;
    private String description;
    private ArrayList<Job> jobs;

    public Jobstream(String name, String timeZone, String description) {
        this.name = name;
        this.timeZone = timeZone;
        this.description = description;
        this.jobs = new ArrayList<>();
    }

    public void appendJob(Job job) {
        this.jobs.add(job);
    }
}

And Job:

public class Job {

    private String name;
    private String sapName;
    private String sapUser;
    private int id;
    private String logon;
    private String description;
    private String type;
    private String recovery;
    private int at;
    private String timezone;

    public Job(String name, String sapName, String sapUser,
               int id, String logon, String description,
               String type, String recovery, int at, String timezone) {
        this.name = name;
        this.sapName = sapName;
        this.sapUser = sapUser;
        this.id = id;
        this.logon = logon;
        this.description = description;
        this.type = type;
        this.recovery = recovery;
        this.at = at;
        this.timezone = timezone;
    }
}

So that's structure.

It will be awesome if you tell me the way I can make it.

Have a nice day!

P.S. I'm NOT asking to help me to write a parser. I'm just asking to help me to find information I need to write it by MYSELF.

  • So what have you tried? Are you expecting StackOverflow to write your parser for you? – yole Jul 08 '15 at 09:01
  • The _nested array_ is just a bunch of child nodes added to a parent node "Jobs". The same way that the "Jobstream", "Timezone", "Description" etc child nodes are attached to the root parent node of the document. – Ceiling Gecko Jul 08 '15 at 09:04
  • @yole, not write a parser, just tell me what I need to read to quickly write some code to parse it. I wrote it in last subparagraph. – Aleksei Slaikovskii Jul 08 '15 at 09:06
  • @CeilingGecko I made 2 classes: Job and Jobstream. In Jobstream I have a field ArrayList -- so I know how to store jobs :) I need some readings to make my parsing skill appears. – Aleksei Slaikovskii Jul 08 '15 at 09:07
  • [Here's a good SO question](http://stackoverflow.com/questions/4142046/create-xml-file-using-java) detailing how to construct an XML file. Parsing is all about processing the data you read. I'm assuming you already know how to read the data. The question above should provide details on how to process that read data into an XML file. Feel free to search for similar questions for JSON creation. – Ceiling Gecko Jul 08 '15 at 09:12
  • @CeilingGecko thank you. – Aleksei Slaikovskii Jul 08 '15 at 09:13
  • @AlexeySlaykovsky did you managed to build a parser for Tivoli Workload Scheduler file? I want to write a tool to visualize the TWS schedule & jobs. would be great if we have this parser opensourced – Selvakumar Esra Aug 01 '19 at 07:06

0 Answers0