Search in sources :

Example 1 with LibraryMacroDirective

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LibraryMacroDirective(org.jboss.ide.eclipse.freemarker.model.LibraryMacroDirective) MacroDirective(org.jboss.ide.eclipse.freemarker.model.MacroDirective) LibraryMacroDirective(org.jboss.ide.eclipse.freemarker.model.LibraryMacroDirective) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 LibraryMacroDirective (org.jboss.ide.eclipse.freemarker.model.LibraryMacroDirective)1 MacroDirective (org.jboss.ide.eclipse.freemarker.model.MacroDirective)1