Search in sources :

Example 1 with ITemplateOperation

use of com.liferay.ide.core.templates.ITemplateOperation in project liferay-ide by liferay.

the class LayoutTplUtil method getTemplateSource.

public static String getTemplateSource(LayoutTplElement layouttpl) {
    StringBuffer buffer = new StringBuffer();
    try {
        ITemplateOperation templateOperation = null;
        if (layouttpl.getBootstrapStyle().content()) {
            templateOperation = TemplatesCore.getTemplateOperation("com.liferay.ide.layouttpl.core.layoutTemplate.bootstrap");
        } else {
            templateOperation = TemplatesCore.getTemplateOperation("com.liferay.ide.layouttpl.core.layoutTemplate.legacy");
        }
        _createLayoutTplContext(templateOperation, layouttpl);
        templateOperation.setOutputBuffer(buffer);
        templateOperation.execute(new NullProgressMonitor());
    } catch (Exception ex) {
        LayoutTplCore.logError("Error getting template source.", ex);
    }
    return buffer.toString();
}
Also used : ITemplateOperation(com.liferay.ide.core.templates.ITemplateOperation) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor)

Example 2 with ITemplateOperation

use of com.liferay.ide.core.templates.ITemplateOperation in project liferay-ide by liferay.

the class LayoutTplUtil method saveToFile.

public static void saveToFile(LayoutTplElement diagramElement, IFile file, IProgressMonitor monitor) {
    try {
        ITemplateOperation op = null;
        if (diagramElement.getBootstrapStyle().content()) {
            op = TemplatesCore.getTemplateOperation("com.liferay.ide.layouttpl.core.layoutTemplate.bootstrap");
        } else {
            op = TemplatesCore.getTemplateOperation("com.liferay.ide.layouttpl.core.layoutTemplate.legacy");
        }
        _createLayoutTplContext(op, diagramElement);
        op.setOutputFile(file);
        op.execute(monitor);
    } catch (Exception e) {
        LayoutTplCore.logError(e);
    }
}
Also used : ITemplateOperation(com.liferay.ide.core.templates.ITemplateOperation)

Example 3 with ITemplateOperation

use of com.liferay.ide.core.templates.ITemplateOperation in project liferay-ide by liferay.

the class WizardUtil method createDefaultServiceBuilderFile.

public static void createDefaultServiceBuilderFile(IFile serviceBuilderFile, String descriptorVersion, boolean useSampleTemplate, String packagePath, String namespace, Object author, IProgressMonitor monitor) throws CoreException {
    ITemplateOperation templateOp = null;
    if (useSampleTemplate) {
        templateOp = TemplatesCore.getTemplateOperation("com.liferay.ide.service.core.defaultServiceXmlFile");
    } else {
        templateOp = TemplatesCore.getTemplateOperation("com.liferay.ide.service.core.emptyServiceXmlFile");
    }
    ITemplateContext context = templateOp.getContext();
    context.put("version", descriptorVersion);
    context.put("version_", descriptorVersion.replace('.', '_'));
    context.put("package_path", packagePath);
    context.put("namespace", namespace);
    context.put("author", author);
    try {
        StringBuffer sb = new StringBuffer();
        templateOp.setOutputBuffer(sb);
        templateOp.execute(monitor);
        CoreUtil.prepareFolder((IFolder) serviceBuilderFile.getParent());
        serviceBuilderFile.create(new ByteArrayInputStream(sb.toString().getBytes("UTF-8")), IResource.FORCE, null);
        FormatProcessorXML processor = new FormatProcessorXML();
        processor.formatFile(serviceBuilderFile);
    } catch (Exception e) {
        ProjectCore.logError(e);
    }
}
Also used : ITemplateOperation(com.liferay.ide.core.templates.ITemplateOperation) ByteArrayInputStream(java.io.ByteArrayInputStream) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML) ITemplateContext(com.liferay.ide.core.templates.ITemplateContext) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

ITemplateOperation (com.liferay.ide.core.templates.ITemplateOperation)3 ITemplateContext (com.liferay.ide.core.templates.ITemplateContext)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 FormatProcessorXML (org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)1