Solved

get a value from a content string

Posted on 2004-04-25
10
283 Views
Last Modified: 2010-03-31
xmlurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2FagtGetDocsViewXML%3Fopenagent%26u%3Dc956395%26uname%3DJoe+Blogg%26start%3D1%26count%3D9999%26viewname%3Dfrmgicsissueview%26frmname%3D%26frmtype%3DView&xslurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2Fviewreport.xsl

I do have a method to decode the content string, however I need a method to pass in this content string and get the values for xmlurl and xslurl.

Thanks
pcorreya
0
Comment
Question by:pcorreya
  • 3
  • 2
  • 2
  • +1
10 Comments
 
LVL 7

Accepted Solution

by:
vbandaru earned 43 total points
ID: 10911717
The String Object has an overloaded method called indexOf. You should be able to use that in conjunction with substring to get the xmlurl and xslurl.

something like this.

String contentString="xmlurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2FagtGetDocsViewXML%3Fopenagent%26u%3Dc956395%26uname%3DJoe+Blogg%26start%3D1%26count%3D9999%26viewname%3Dfrmgicsissueview%26frmname%3D%26frmtype%3DView&xslurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2Fviewreport.xsl";

String xmlurl= contentString.substring(7,contentString.indexOf("xslurl")-1);

String xslurl= contentString.substring(contentString.indexOf("xslurl")+7);
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 41 total points
ID: 10912076
Or you can use regular expressions:

            String x = "xmlurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2FagtGetDocsViewXML%3Fopenagent%26u%3Dc956395%26uname%3DJoe+Blogg%26start%3D1%26count%3D9999%26viewname%3Dfrmgicsissueview%26frmname%3D%26frmtype%3DView&xslurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2Fviewreport.xsl";
            x = URLDecoder.decode(x, "UTF-8");
            final String RE = "xmlurl=(.+)\\?.+xslurl=(.+)";
            Pattern p = Pattern.compile(RE);
            Matcher m = p.matcher(x);
            if (m.matches()) {
                  System.out.println(m.group(1));
                  System.out.println(m.group(2));
            }
0
 
LVL 92

Expert Comment

by:objects
ID: 10914093
vbandaru is right, the only additional thing you may want to do is decode the urls:

import java.net.*;

public class extracturls
{
      public static void main(String[] args)
      {
            String contentString="xmlurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2FagtGetDocsViewXML%3Fopenagent%26u%3Dc956395%26uname%3DJoe+Blogg%26start%3D1%26count%3D9999%26viewname%3Dfrmgicsissueview%26frmname%3D%26frmtype%3DView&xslurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2Fviewreport.xsl";

            String xmlurl= URLDecoder.decode(contentString.substring(7,contentString.indexOf("xslurl")-1));

            String xslurl= URLDecoder.decode(contentString.substring(contentString.indexOf("xslurl")+7));
            
            System.out.println(xmlurl);
            System.out.println(xslurl);
      }
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10914109
>>vbandaru is right

? So i'm wrong am i? ;-)

In any case, your comment is redundant - you obviously have not read the question:

>>I do have a method to decode the content string, ...
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

by:pcorreya
ID: 10914501
Thanks you all for your contribution, however it would be nice to have a class that I can use to pass it the content string and the lookup field and return its value.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 41 total points
ID: 10914808
try something like:

     public static String extractField(String contentString, String lookup)
     {
          String[] pairs = contentString.split("&");
          for (int i=0; i<pairs.length; i++)
          {
              String[] keyvalue = pairs[i].split("=");
              if (keyvalue[0].equals(lookup)) return keyvalue[1];
          }
          return null;
     }
0
 
LVL 1

Author Comment

by:pcorreya
ID: 10927241
objects, i am getting the message Method split(java.lang.String) not found in class java.lang.String
0
 
LVL 92

Expert Comment

by:objects
ID: 10927304
it only became available in 1.4.
you'll need to use StringTokenizer in previous versions.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now