Last active
January 22, 2018 11:27
-
-
Save dileeph/65f00fbd98daa841f20182031d9b3f22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Pattern scriptletstartreg = Pattern.compile("<%[^-|@]"); | |
final Pattern scriptletendreg = Pattern.compile("[^-]%>"); | |
final List<Scriptlet> scripts = new ArrayList<>(); | |
//--start else--// | |
//--current code --// | |
currentPageTldPrefix.keySet().forEach(key -> { | |
Pattern regexForEachTagPrefixPattern = Pattern.compile(key); | |
Matcher match = regexForEachTagPrefixPattern.matcher(line); | |
if (match.find()) { | |
String tag = match.group(0); | |
String name = StringUtils.removePattern(tag, "<[\\s]*[\\w]*[\\s]*:[\\s]*"); | |
name = StringUtils.removePattern(name, "[^\\w]"); | |
detail.addToTaglibMap(currentPageTldPrefix.get(key), name); | |
/*ognl code*/ | |
Matcher ognlmatch = ognlPattern.matcher(line); | |
if (ognlmatch.find()) { | |
System.out.println(">>> OGNL " + ognlmatch.group(0) + " tag" + name); | |
} | |
} | |
}); | |
/*Scriptlet code */ | |
long count = scripts.stream().count(); | |
if (count > 0) { | |
Stream<Scriptlet> stream = scripts.stream(); | |
Scriptlet lastIndex = stream.skip(count - 1).findFirst().get(); | |
if (!lastIndex.isClosed()) { | |
Matcher y = scriptletendreg.matcher(line); | |
if (y.find()) { | |
lastIndex.setEnd(y.start()); | |
lastIndex.setEndTag(y.group(0)); | |
lastIndex.setLoc(lastIndex.getLoc() + 1); | |
}else{ | |
if(!StringUtils.isBlank(line)){ | |
lastIndex.setLoc(lastIndex.getLoc() + 1); | |
} | |
} | |
} | |
} | |
Matcher m = scriptletstartreg.matcher(line); | |
while (m.find()) { | |
Scriptlet s = new Scriptlet(m.start(), m.group(0)); | |
Matcher y = scriptletendreg.matcher(line); | |
if (y.find(m.start())) { | |
s.setEnd(y.start()); | |
s.setEndTag(y.group(0)); | |
} | |
scripts.add(s); | |
} | |
} | |
//--end else--// | |
==================================== | |
class Scriptlet { | |
private int start; | |
private int end; | |
private int loc = 1; | |
private String startTag; | |
private String endTag; | |
private boolean closed; | |
public Scriptlet(int start, String startTag) { | |
this.start = start; | |
this.startTag = startTag; | |
} | |
public int getStart() { | |
return start; | |
} | |
public void setStart(int start) { | |
this.start = start; | |
} | |
public int getEnd() { | |
return end; | |
} | |
public void setEnd(int end) { | |
this.end = end; | |
this.closed = true; | |
} | |
public boolean isClosed() { | |
return closed; | |
} | |
public void setClosed(boolean closed) { | |
this.closed = closed; | |
} | |
public String getStartTag() { | |
return startTag; | |
} | |
public void setStartTag(String startTag) { | |
this.startTag = startTag; | |
} | |
public String getEndTag() { | |
return endTag; | |
} | |
public void setEndTag(String endTag) { | |
this.endTag = endTag; | |
} | |
public int getLoc() { | |
return loc; | |
} | |
public void setLoc(int loc) { | |
this.loc = loc; | |
} | |
@Override | |
public String toString() { | |
return "Scriptlet [start=" + start + ", end=" + end + ", loc=" + loc + ", startTag=" + startTag | |
+ ", endTag=" + endTag + ", closed=" + closed + "]"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment