Split results and make list

Joined
Apr 12, 2012
Messages
1
Reaction score
0
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top