src/share/jaxws_classes/com/sun/tools/internal/jxc/NGCCRuntimeEx.java

Print this page




  66         File dir = new File(baseDir);
  67         if (dir.exists()) {
  68             return dir;
  69         } else {
  70             SAXParseException e = new SAXParseException(
  71                                 Messages.BASEDIR_DOESNT_EXIST.format(dir.getAbsolutePath()),
  72                                 getLocator());
  73             errorHandler.error(e);
  74             throw e;    // we can't recover from this error
  75         }
  76     }
  77 
  78     /**
  79      * This takes the include list provided by the user in the config file
  80      * It converts the user values to {@link Pattern}
  81      * @param includeContent
  82      *        The include list specified by the user
  83      * @return
  84      *        A list of regular expression patterns {@link Pattern}
  85      */
  86     public List<Pattern> getIncludePatterns(List includeContent ) {
  87         List<Pattern> includeRegexList = new ArrayList<Pattern>();
  88         for (int i = 0 ; i < includeContent.size(); i ++){
  89             String includes = (String)includeContent.get(i);
  90             String regex = convertToRegex(includes);
  91             Pattern pattern = Pattern.compile(regex);
  92             includeRegexList.add(pattern);
  93         }
  94         return includeRegexList;
  95     }
  96 
  97 
  98     /**
  99      * This takes the exclude list provided by the user in the config file
 100      * It converts the user values to {@link Pattern}
 101      * @param excludeContent
 102      *        The exclude list specified by the user
 103      * @return
 104      *        A list of regular expression patterns {@link Pattern}
 105      */
 106     public List getExcludePatterns(List excludeContent ) {
 107         List excludeRegexList = new ArrayList();
 108         for (int i = 0 ; i < excludeContent.size(); i ++){
 109             String excludes = (String)excludeContent.get(i);
 110             String regex = convertToRegex(excludes);
 111             Pattern pattern = Pattern.compile(regex);
 112             excludeRegexList.add(pattern);
 113         }
 114         return excludeRegexList;
 115     }
 116 
 117 
 118     /**
 119      * This will tokenize the pattern and convert it into a regular expression
 120      * @param pattern
 121      */
 122     private String convertToRegex(String pattern) {
 123         StringBuilder regex = new StringBuilder();
 124         char nc = ' ';
 125         if (pattern.length() >0 ) {
 126 
 127             for ( int i = 0 ; i < pattern.length(); i ++ ) {
 128                 char c = pattern.charAt(i);
 129                 int j = i;
 130                 nc = ' ';
 131                 if ((j+1) != pattern.length()) {
 132                     nc = pattern.charAt(j+1);
 133                 }
 134                 //escape single '.'
 135                 if ((c=='.') && ( nc !='.')){
 136                     regex.append('\\');
 137                     regex.append('.');
 138                     //do not allow patterns like a..b
 139                 } else if ((c=='.') && ( nc =='.')){
 140                     continue;
 141                     // "**" gets replaced by ".*"
 142                 } else if ((c=='*') && (nc == '*')) {
 143                     regex.append(".*");
 144                     break;
 145                     //'*' replaced by anything but '.' i.e [^\\.]+
 146                 } else if (c=='*') {
 147                     regex.append("[^\\.]+");
 148                     continue;
 149                     //'?' replaced by anything but '.' i.e [^\\.]
 150                 } else if (c=='?') {
 151                     regex.append("[^\\.]");
 152                     //else leave the chars as they occur in the pattern
 153                 } else
 154                     regex.append(c);
 155             }
 156 
 157         }
 158 
 159         return regex.toString();


  66         File dir = new File(baseDir);
  67         if (dir.exists()) {
  68             return dir;
  69         } else {
  70             SAXParseException e = new SAXParseException(
  71                                 Messages.BASEDIR_DOESNT_EXIST.format(dir.getAbsolutePath()),
  72                                 getLocator());
  73             errorHandler.error(e);
  74             throw e;    // we can't recover from this error
  75         }
  76     }
  77 
  78     /**
  79      * This takes the include list provided by the user in the config file
  80      * It converts the user values to {@link Pattern}
  81      * @param includeContent
  82      *        The include list specified by the user
  83      * @return
  84      *        A list of regular expression patterns {@link Pattern}
  85      */
  86     public List<Pattern> getIncludePatterns(List<String> includeContent ) {
  87         List<Pattern> includeRegexList = new ArrayList<Pattern>();
  88         for (String includes : includeContent) {

  89             String regex = convertToRegex(includes);
  90             Pattern pattern = Pattern.compile(regex);
  91             includeRegexList.add(pattern);
  92         }
  93         return includeRegexList;
  94     }
  95 
  96 
  97     /**
  98      * This takes the exclude list provided by the user in the config file
  99      * It converts the user values to {@link Pattern}
 100      * @param excludeContent
 101      *        The exclude list specified by the user
 102      * @return
 103      *        A list of regular expression patterns {@link Pattern}
 104      */
 105     public List getExcludePatterns(List<String> excludeContent ) {
 106         List<Pattern> excludeRegexList = new ArrayList<Pattern>();
 107         for (String excludes : excludeContent) {

 108             String regex = convertToRegex(excludes);
 109             Pattern pattern = Pattern.compile(regex);
 110             excludeRegexList.add(pattern);
 111         }
 112         return excludeRegexList;
 113     }
 114 
 115 
 116     /**
 117      * This will tokenize the pattern and convert it into a regular expression
 118      * @param pattern
 119      */
 120     private String convertToRegex(String pattern) {
 121         StringBuilder regex = new StringBuilder();
 122         char nc = ' ';
 123         if (pattern.length() >0 ) {
 124 
 125             for ( int i = 0 ; i < pattern.length(); i ++ ) {
 126                 char c = pattern.charAt(i);

 127                 nc = ' ';
 128                 if ((i +1) != pattern.length()) {
 129                     nc = pattern.charAt(i +1);
 130                 }
 131                 //escape single '.'
 132                 if (c == '.' &&  nc != '.'){
 133                     regex.append('\\');
 134                     regex.append('.');
 135                     //do not allow patterns like a..b
 136                 } else if (c == '.'){
 137                     continue;
 138                     // "**" gets replaced by ".*"
 139                 } else if ((c=='*') && (nc == '*')) {
 140                     regex.append(".*");
 141                     break;
 142                     //'*' replaced by anything but '.' i.e [^\\.]+
 143                 } else if (c=='*') {
 144                     regex.append("[^\\.]+");
 145                     continue;
 146                     //'?' replaced by anything but '.' i.e [^\\.]
 147                 } else if (c=='?') {
 148                     regex.append("[^\\.]");
 149                     //else leave the chars as they occur in the pattern
 150                 } else
 151                     regex.append(c);
 152             }
 153 
 154         }
 155 
 156         return regex.toString();