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      @Before
29      public void setUp() throws Exception {
30      }
31  
32      @After
33      public void tearDown() throws Exception {
34          //To change body of created methods use File | Settings | File Templates.
35      }
36  
37      @Test
38      public void testAllTextUsingRegEx() throws Exception {
39          String filePath = "/org/kuali/ole/utility/license/OLE-License-ONIXPL.xml";
40          URL resource = getClass().getResource(filePath);
41          File file = new File(resource.toURI());
42          String sampleText = FileUtils.readFileToString(file);
43          String[] content = sampleText.split("content>");
44          for (int i = 0; i < content.length; i++) {
45              if (i % 2 == 0) {
46                  if (content[i].contains("additionalAttributes")) {
47                      LOG.debug("additionalAttributes");
48                      LOG.debug("======================");
49                      getText(content[i]);
50                  }
51              } else {
52  
53                  LOG.debug("content");
54                  LOG.debug("======================");
55                  getText(content[i]);
56              }
57  
58          }
59  
60      }
61  
62      private void getText(String input) {
63          String reg = "<.*>(.*)<\\/.*?>";
64          Pattern p = Pattern.compile(reg);
65          Matcher m = p.matcher(input);
66  
67          while (m.find()) {
68              String s1 = m.group(1);
69              LOG.debug(s1);
70          }
71      }
72  
73  }
74