Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Split results and make list

Reply
Thread Tools

Split results and make list

 
 
phys1cx phys1cx is offline
Junior Member
Join Date: Apr 2012
Posts: 1
 
      04-12-2012
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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I make this more efficient? (combining DataSet results with the results of a DB lookup.) Ken Fine ASP .Net 3 07-23-2008 08:11 AM
How can I split database results with ExecuteReader and Split? needin4mation@gmail.com ASP .Net 2 05-05-2006 10:36 PM
split on '' (and another for split -1) trans. (T. Onoma) Ruby 10 12-28-2004 06:36 AM
Small inconsistency between string.split and "".split Carlos Ribeiro Python 11 09-17-2004 05:57 PM
Why does split operate over multiple lines in the absence of "ms" ? And why doesn't $_ work with split? Sara Perl Misc 6 04-12-2004 09:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57