use of org.jboss.ide.eclipse.freemarker.model.LibraryMacroDirective in project liferay-ide by liferay.
the class MacroLibrary method load.
private void load() {
try {
List macros = new ArrayList();
// $NON-NLS-1$
String search = "#macro ";
int index = content.indexOf(search);
int startIndex = index;
char startChar = content.charAt(index - 1);
char endChar;
if (startChar == '[')
endChar = ']';
else
endChar = '>';
while (startIndex > 0) {
int stackCount = 0;
boolean inString = false;
// find the end
int endIndex = Integer.MIN_VALUE;
boolean escape = false;
while (content.length() > index && index >= 0) {
boolean doEscape = false;
char c = content.charAt(index++);
if (!escape) {
if (c == '\"')
inString = !inString;
else if (c == '\\' && inString)
doEscape = true;
else if (c == startChar)
stackCount++;
else if (c == endChar) {
if (stackCount > 0)
stackCount--;
else {
endIndex = index - 1;
break;
}
}
}
escape = doEscape;
}
if (endIndex > 0) {
String sub = content.substring(startIndex, endIndex);
MacroDirective macroDirective = new LibraryMacroDirective(namespace, sub, startIndex - 1, endIndex - index + 2);
macros.add(macroDirective);
index = content.indexOf(startChar + search, endIndex);
if (index >= 0)
index++;
startIndex = index;
endIndex = Integer.MIN_VALUE;
} else {
break;
}
}
this.macros = (MacroDirective[]) macros.toArray(new MacroDirective[macros.size()]);
if (null != file)
this.lastUpdatedTime = file.getModificationStamp();
} catch (Exception e) {
macros = new MacroDirective[0];
Plugin.log(e);
}
}
Aggregations