@@ -0,0 +1,3318 @@
+package com.wizzardo.http.framework.template.taglib.g;%0A%0Aimport com.wizzardo.http.Handler;%0Aimport com.wizzardo.http.framework.di.DependencyFactory;%0Aimport com.wizzardo.http.framework.template.*;%0Aimport com.wizzardo.http.mapping.UrlMapping;%0Aimport com.wizzardo.http.mapping.UrlTemplate;%0A%0Aimport java.util.Collections;%0Aimport java.util.Map;%0A%0A/**%0A * Created by wizzardo on 13.06.15.%0A */%0Apublic class CreateLink extends Tag implements RenderableString %7B%0A%0A    protected UrlMapping%3CHandler%3E urlMapping = DependencyFactory.getDependency(UrlMapping.class);%0A%0A    @Override%0A    public Tag init(Map%3CString, String%3E attrs, Body body, String offset) %7B%0A        String controller = attrs.remove(%22controller%22);%0A        String action = attrs.remove(%22action%22);%0A        String base = attrs.remove(%22base%22);%0A        String fragment = attrs.remove(%22fragment%22);%0A        boolean absolute = Boolean.valueOf(attrs.remove(%22absolute%22));%0A%0A        append(offset);%0A        beforeAppendUrl();%0A%0A        ExpressionHolder%3CMap%3CString, Object%3E%3E params = asExpression(remove(attrs, %22params%22, %22%5B:%5D%22), false);%0A%0A        UrlTemplate template = urlMapping.getUrlTemplate(controller + %22.%22 + action);%0A%0A        if (template == null)%0A            throw new IllegalStateException(%22can not find mapping for controller '%22 + controller + %22' and action:'%22 + action + %22'%22);%0A%0A        if (base != null) %7B%0A            add(model -%3E new RenderResult(template.getUrl(base, params.getRaw(model))));%0A        %7D else if (absolute)%0A            add(model -%3E new RenderResult(template.getAbsoluteUrl(params.getRaw(model))));%0A        else%0A            add(model -%3E new RenderResult(template.getRelativeUrl(params.getRaw(model))));%0A%0A        if (fragment != null && fragment.length() %3E 0) %7B%0A            append(%22#%22).append(fragment);%0A        %7D%0A%0A        afterAppendUrl();%0A        append(%22%5Cn%22);%0A%0A        return this;%0A    %7D%0A%0A    protected void beforeAppendUrl() %7B%0A    %7D%0A%0A    protected void afterAppendUrl() %7B%0A    %7D%0A%0A    @Override%0A    public String render(Map%3CString, Object%3E attrs) %7B%0A        String controller = (String) attrs.remove(%22controller%22);%0A        String action = (String) attrs.remove(%22action%22);%0A        String base = (String) attrs.remove(%22base%22);%0A        String fragment = (String) attrs.remove(%22fragment%22);%0A        boolean absolute = Boolean.valueOf((String) attrs.remove(%22absolute%22));%0A%0A        Map%3CString, Object%3E params = (Map) attrs.remove(%22params%22);%0A        if (params == null)%0A            params = Collections.emptyMap();%0A%0A        UrlTemplate template = getUrlTemplate(controller, action);%0A        if (template == null)%0A            throw new IllegalStateException(%22can not find mapping for controller '%22 + controller + %22' and action:'%22 + action + %22'%22);%0A%0A        String url;%0A%0A        if (base != null) %7B%0A            url = template.getUrl(base, params);%0A        %7D else if (absolute)%0A            url = template.getAbsoluteUrl(params);%0A        else%0A            url = template.getRelativeUrl(params);%0A%0A        if (fragment != null && fragment.length() %3E 0)%0A            return url + %22#%22 + fragment;%0A%0A%0A        return url;%0A    %7D%0A%0A    protected UrlTemplate getUrlTemplate(String name) %7B%0A        return urlMapping.getUrlTemplate(name);%0A    %7D%0A%0A    protected UrlTemplate getUrlTemplate(String controller, String action) %7B%0A        return getUrlTemplate(controller + %22.%22 + action);%0A    %7D%0A%7D%0A

add CreateLink tag