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);
}
}
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;
}
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;
}
Aggregations