Search in sources :

Example 26 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML 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)

Example 27 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.

the class ServiceBuilderDescriptorHelper method doAddDefaultEntity.

protected IStatus doAddDefaultEntity(IDOMDocument document) {
    String entityName = _generateSampleEntityName(document);
    Element rootElement = document.getDocumentElement();
    // new <entity> element
    Element entityElement = document.createElement("entity");
    entityElement.setAttribute("local-service", "true");
    entityElement.setAttribute("name", entityName);
    entityElement.setAttribute("remote-service", "true");
    // <!-- PK fields -->
    _appendComment(entityElement, " PK fields ");
    Element columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", _generateEntityId(entityName));
    columnElem.setAttribute("primary", "true");
    columnElem.setAttribute("type", "long");
    // <!-- Group instance -->
    _appendComment(entityElement, " Group instance ");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "groupId");
    columnElem.setAttribute("type", "long");
    // <!-- Aduit fields -->
    _appendComment(entityElement, " Audit fields ");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "companyId");
    columnElem.setAttribute("type", "long");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "userId");
    columnElem.setAttribute("type", "long");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "userName");
    columnElem.setAttribute("type", "String");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "createDate");
    columnElem.setAttribute("type", "Date");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "modifiedDate");
    columnElem.setAttribute("type", "Date");
    // <!-- Other fields -->
    _appendComment(entityElement, " Other fields ");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "field1");
    columnElem.setAttribute("type", "String");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "field2");
    columnElem.setAttribute("type", "boolean");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "field3");
    columnElem.setAttribute("type", "int");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "field4");
    columnElem.setAttribute("type", "Date");
    columnElem = NodeUtil.appendChildElement(entityElement, "column");
    columnElem.setAttribute("name", "field5");
    columnElem.setAttribute("type", "String");
    // <!-- Order -->
    _appendComment(entityElement, " Order ");
    Element orderElem = NodeUtil.appendChildElement(entityElement, "order");
    orderElem.setAttribute("by", "asc");
    NodeUtil.appendChildElement(orderElem, "order-column").setAttribute("name", "field1");
    // <!-- Finder methods -->
    _appendComment(entityElement, " Finder methods ");
    Element finderElem = NodeUtil.appendChildElement(entityElement, "finder");
    finderElem.setAttribute("name", "Field2");
    finderElem.setAttribute("return-type", "Collection");
    NodeUtil.appendChildElement(finderElem, "finder-column").setAttribute("name", "field2");
    // Insert the <entity> element
    Node refNode = NodeUtil.findFirstChild(rootElement, "exceptions");
    if (refNode == null) {
        NodeUtil.findFirstChild(rootElement, "service-builder-import");
    }
    rootElement.insertBefore(entityElement, refNode);
    new FormatProcessorXML().formatNode(entityElement);
    rootElement.appendChild(document.createTextNode(_NEW_LINE));
    return Status.OK_STATUS;
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 28 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.

the class ServiceBuilderDescriptorHelper method doAddEntity.

protected IStatus doAddEntity(IDOMDocument document, String entityName) {
    NodeList entities = document.getElementsByTagName("entity");
    for (int i = 0; i < entities.getLength(); ++i) {
        Node entity = entities.item(i);
        if (entity instanceof Element) {
            String name = ((Element) entity).getAttribute("name");
            if ((name != null) && name.equals(entityName)) {
                return Status.OK_STATUS;
            }
        }
    }
    Element rootElement = document.getDocumentElement();
    // new <entity> element
    Element entityElement = document.createElement("entity");
    entityElement.setAttribute("name", entityName);
    // Insert the <entity> element
    Node refNode = NodeUtil.findFirstChild(rootElement, "exceptions");
    if (refNode == null) {
        NodeUtil.findFirstChild(rootElement, "service-builder-import");
    }
    rootElement.insertBefore(entityElement, refNode);
    new FormatProcessorXML().formatNode(entityElement);
    rootElement.appendChild(document.createTextNode(_NEW_LINE));
    return Status.OK_STATUS;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Aggregations

FormatProcessorXML (org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)28 Element (org.w3c.dom.Element)16 Node (org.w3c.dom.Node)14 NodeList (org.w3c.dom.NodeList)9 IStructuredFormatProcessor (org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor)8 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)6 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)6 CoreException (org.eclipse.core.runtime.CoreException)3 IWebProject (com.liferay.ide.core.IWebProject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IFile (org.eclipse.core.resources.IFile)2 ITemplateContext (com.liferay.ide.core.templates.ITemplateContext)1 ITemplateOperation (com.liferay.ide.core.templates.ITemplateOperation)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IFolder (org.eclipse.core.resources.IFolder)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1