View Javadoc
1   package org.esigate.aggregator;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   import java.util.regex.Matcher;
6   import java.util.regex.Pattern;
7   
8   import org.esigate.Driver;
9   import org.esigate.DriverFactory;
10  
11  /**
12   * ElementAttributs's Factory
13   * 
14   * @author athaveau
15   */
16  final class ElementAttributesFactory {
17      private ElementAttributesFactory() {
18  
19      }
20  
21      /**
22       * Parse the tag and return the ElementAttributes
23       * 
24       * @param tag
25       *            the tag to parse
26       * @return ElementAttributes
27       */
28      static ElementAttributes createElementAttributes(String tag) {
29          // Parsing strings
30          // <!--$includetemplate$aggregated2$templatewithparams.jsp$-->
31          // or
32          // <!--$includeblock$aggregated2$$(block)$myblock$-->
33          // in order to retrieve driver, page and name attributes
34          Pattern pattern = Pattern.compile("(?<=\\$)(?:[^\\$]|\\$\\()*(?=\\$)");
35          Matcher matcher = pattern.matcher(tag);
36          List<String> listparameters = new ArrayList<>();
37          while (matcher.find()) {
38              listparameters.add(matcher.group());
39          }
40  
41          String[] parameters = listparameters.toArray(new String[listparameters.size()]);
42  
43          Driver driver;
44          String page = "";
45          String name = null;
46  
47          if (parameters.length > 1) {
48              driver = DriverFactory.getInstance(parameters[1]);
49          } else {
50              driver = DriverFactory.getInstance();
51          }
52  
53          if (parameters.length > 2) {
54              page = parameters[2];
55          }
56  
57          if (parameters.length > 3) {
58              name = parameters[3];
59          }
60          return new ElementAttributes(driver, page, name);
61  
62      }
63  }