Split results and make list

Discussion in 'Java' started by phys1cx, Apr 12, 2012.

  1. phys1cx

    phys1cx

    Joined:
    Apr 12, 2012
    Messages:
    1
    What I want and what my program does:

    Reading xml file and making string of it, after that collect part of strings that I needed by substring replace and regex. Current output is like this:

    Rezultat: index=linux AND ("status installed" OR "Installed:" OR "Updated:" OR "|install") | stats count AS "Total installed packages"
    Rezultat: index=linux AND ("status installed" OR "Installed:" OR "Updated:" OR "|install") | timechart bins=1000 count AS "Installed packages"
    Rezultat: index=linux AND ("status installed" OR "Installed:" OR "Updated:" OR "|install") | rex mode=sed "s/status installed\s+([^\s]+)\s*(.*)/\1.\2/g" | rex mode=sed "s/\|install[^\|]*\|([^\|]+)\|([^\|]*)\|([^\|]*).*/ \1.\2.\3/g" | rex field=_raw "(?<package>[^\s]+$)" | regex | sort - _time | table host _time package | convert timeformat="%H:%M:%S %d.%m.%Y." ctime(_time) | rename host AS Host _time AS Time package AS Package

    So as you can see I meanged to get strings (queries that I want), now I need to make in program option for user to chose if he wants 1,2 or 3rd result. Any idea how can I make it? (I need to make my results selectable because in next part of program thay must be performed in comand line (cmd)).

    My current code:


    public static void main (String argv []){
    try {

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.parse (new File("x.xml"));


    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");

    //initialize StreamResult with File object to save to file
    StreamResult result = new StreamResult(new StringWriter());
    DOMSource source = new DOMSource(doc);
    transformer.transform(source, result);

    String xmlString = result.getWriter().toString();
    //Print XML
    //System.out.println(xmlString);


    String str = xmlString;
    String editedXML = str.replace("<![CDATA[", "").replace("]]>", "");
    //Print editedXML
    //System.out.println(editedXML);
    //editedXML = editedXML.replace("\\s{1}[^\\=\\s]+=\\\"?\\$[^\\$]+\\$\\\"?", "");
    // \s{1}[^\=]+=\"?\$[^\$]+\$\"?
    //\\s{1}[^\\=\\s]+=\\\"?\\$[^\\$]+\\$\\\"?


    //Pattern regex = Pattern.compile("module", Pattern.MULTILINE | Pattern.DOTALL);
    Pattern regex = Pattern.compile("<param name=\"search\">(.*?)</param>", Pattern.MULTILINE);
    Matcher matcher = regex.matcher(editedXML);
    while(matcher.find())
    {
    String search = matcher.group(1);
    Pattern regexSearch = Pattern.compile("\\s{1}[^\\=\\s]+=\\\"?\\$[^\\$]+\\$\\\"?", Pattern.MULTILINE);
    Matcher matcherSearch = regexSearch.matcher(search);
    String searchParsed = search;

    while(matcherSearch.find()){
    String foundPattern = matcherSearch.group(0);
    searchParsed = searchParsed.replace((CharSequence) foundPattern, (CharSequence) "");
    //System.out.println("Rezultat: " + searchParsed);
    }
    String novistr = searchParsed;
    String novieditedXML = novistr.replace(" AND AND", " AND");

    System.out.println("Rezultat: " + novieditedXML);
    }



    Please any idea?
    phys1cx, Apr 12, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. needin4mation@gmail.com
    Replies:
    2
    Views:
    444
    needin4mation@gmail.com
    May 5, 2006
  2. Carlos Ribeiro
    Replies:
    11
    Views:
    677
    Alex Martelli
    Sep 17, 2004
  3. Ken Fine
    Replies:
    3
    Views:
    514
    Steven Cheng [MSFT]
    Jul 23, 2008
  4. trans.  (T. Onoma)

    split on '' (and another for split -1)

    trans. (T. Onoma), Dec 27, 2004, in forum: Ruby
    Replies:
    10
    Views:
    193
    Florian Gross
    Dec 28, 2004
  5. Sam Kong
    Replies:
    5
    Views:
    213
    Rick DeNatale
    Aug 12, 2006
Loading...

Share This Page