View Javadoc

1   package utility;
2   
3   import org.apache.commons.io.FileUtils;
4   import org.junit.After;
5   import org.junit.Before;
6   import org.junit.Test;
7   import org.kuali.ole.docstore.xstream.BaseTestCase;
8   import org.slf4j.Logger;
9   import org.slf4j.LoggerFactory;
10  
11  import java.io.File;
12  import java.net.URL;
13  import java.util.regex.Matcher;
14  import java.util.regex.Pattern;
15  
16  /**
17   * Created by IntelliJ IDEA.
18   * User: Sreekanth
19   * Date: 6/4/12
20   * Time: 11:21 AM
21   * To change this template use File | Settings | File Templates.
22   */
23  public class XMLUtility_UT
24          extends BaseTestCase {
25      private static final Logger LOG = LoggerFactory.getLogger(XMLUtility_UT.class);
26  
27  
28  
29      @Before
30      public void setUp() throws Exception {
31          }
32  
33      @After
34      public void tearDown() throws Exception {
35          //To change body of created methods use File | Settings | File Templates.
36      }
37  
38      @Test
39      public void testAllTextUsingRegEx() throws Exception {
40          String filePath = "/org/kuali/ole/utility/license/OLE-License-ONIXPL.xml";
41          URL resource = getClass().getResource(filePath);
42          File file = new File(resource.toURI());
43          String sampleText = FileUtils.readFileToString(file);
44          String[] content = sampleText.split("content>");
45          for (int i = 0; i < content.length; i++) {
46              if (i % 2 == 0) {
47                  if (content[i].contains("additionalAttributes")) {
48                      LOG.debug("additionalAttributes");
49                      LOG.debug("======================");
50                      getText(content[i]);
51                  }
52              }
53              else {
54  
55                  LOG.debug("content");
56                  LOG.debug("======================");
57                  getText(content[i]);
58              }
59  
60          }
61  
62      }
63  
64      private void getText(String input) {
65          String reg = "<.*>(.*)<\\/.*?>";
66          Pattern p = Pattern.compile(reg);
67          Matcher m = p.matcher(input);
68  
69          while (m.find()) {
70              String s1 = m.group(1);
71              LOG.debug(s1);
72          }
73      }
74  
75  }
76