use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project liferay-ide by liferay.
the class LiferayDisplayDescriptorHelper method addDescriptorOperations.
@Override
protected void addDescriptorOperations() {
AddNewPortletOperation anpOperation = new AddNewPortletOperation() {
@Override
public IStatus addNewPortlet(IDataModel model) {
IStatus status = Status.OK_STATUS;
IFile descriptorFile = getDescriptorFile();
if (descriptorFile != null) {
DOMModelEditOperation domModelOperation = new DOMModelEditOperation(descriptorFile) {
protected void createDefaultFile() {
createDefaultDescriptor(_DESCRIPTOR_TEMPLATE, getDescriptorVersion());
}
protected IStatus doExecute(IDOMDocument document) {
return doAddNewPortlet(document, model);
}
};
status = domModelOperation.execute();
}
return status;
}
};
addDescriptorOperation(anpOperation);
RemoveAllPortletsOperation rapOperation = new RemoveAllPortletsOperation() {
@Override
public IStatus removeAllPortlets() {
return removeAllPortlets();
}
};
addDescriptorOperation(rapOperation);
RemoveSampleElementsOperation rseOperation = new RemoveSampleElementsOperation() {
@Override
public IStatus removeSampleElements() {
return removeAllPortlets();
}
};
addDescriptorOperation(rseOperation);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project liferay-ide by liferay.
the class LiferayDisplayDescriptorHelper method getAllPortletCategories.
public String[] getAllPortletCategories() {
List<String> allPortletCategories = new ArrayList<>();
IFile descriptorFile = getDescriptorFile();
if (descriptorFile != null) {
DOMModelOperation op = new DOMModelReadOperation(descriptorFile) {
protected IStatus doExecute(IDOMDocument document) {
NodeList nodeList = document.getElementsByTagName("category");
if ((nodeList != null) && (nodeList.getLength() > 0)) {
for (int i = 0; i < nodeList.getLength(); i++) {
Element categoryElemnt = (Element) nodeList.item(i);
String categoryName = categoryElemnt.getAttribute("name");
if ((categoryName != null) && !categoryName.matches("\\s*")) {
allPortletCategories.add(categoryName);
}
}
}
return Status.OK_STATUS;
}
};
op.execute();
}
return allPortletCategories.toArray(new String[0]);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project liferay-ide by liferay.
the class LiferayPortletDescriptorHelper method configureLiferayPortletXml.
public IStatus configureLiferayPortletXml(String newPortletName) {
IStatus status = Status.OK_STATUS;
IFile descriptorFile = getDescriptorFile();
if (descriptorFile != null) {
DOMModelEditOperation operation = new DOMModelEditOperation(descriptorFile) {
protected IStatus doExecute(IDOMDocument document) {
Element rootElement = document.getDocumentElement();
NodeList portletNodes = rootElement.getElementsByTagName("portlet");
if (portletNodes.getLength() > 0) {
Element lastPortletElement = (Element) portletNodes.item(portletNodes.getLength() - 1);
Element portletName = NodeUtil.findChildElement(lastPortletElement, "portlet-name");
portletName.replaceChild(document.createTextNode(newPortletName), portletName.getFirstChild());
}
return Status.OK_STATUS;
}
};
status = operation.execute();
}
return status;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project liferay-ide by liferay.
the class LiferayPortletDescriptorHelper method addDescriptorOperations.
@Override
protected void addDescriptorOperations() {
AddNewPortletOperation apOperation = new AddNewPortletOperation() {
@Override
public IStatus addNewPortlet(IDataModel model) {
IStatus status = Status.OK_STATUS;
if (canAddNewPortlet(model)) {
IFile descriptorFile = getDescriptorFile();
if (descriptorFile != null) {
DOMModelEditOperation domModelOperation = new DOMModelEditOperation(descriptorFile) {
protected void createDefaultFile() {
createDefaultDescriptor(_DESCRIPTOR_TEMPLATE, getDescriptorVersion());
}
protected IStatus doExecute(IDOMDocument document) {
return doAddNewPortlet(document, model);
}
};
status = domModelOperation.execute();
}
}
return status;
}
};
addDescriptorOperation(apOperation);
RemoveAllPortletsOperation rapOperation = new RemoveAllPortletsOperation() {
@Override
public IStatus removeAllPortlets() {
return doRemoveAllPortlets();
}
};
addDescriptorOperation(rapOperation);
RemoveSampleElementsOperation rseOperation = new RemoveSampleElementsOperation() {
@Override
public IStatus removeSampleElements() {
return doRemoveAllPortlets();
}
};
addDescriptorOperation(rseOperation);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project liferay-ide by liferay.
the class PortletDescriptorHelper method configurePortletXml.
public IStatus configurePortletXml(String newPortletName) {
IFile descriptorFile = getDescriptorFile();
IStatus status = new DOMModelEditOperation(descriptorFile) {
protected IStatus doExecute(IDOMDocument document) {
Element rootElement = document.getDocumentElement();
NodeList portletNodes = rootElement.getElementsByTagName("portlet");
if (portletNodes.getLength() > 0) {
Element lastPortletElement = (Element) portletNodes.item(portletNodes.getLength() - 1);
Element portletName = NodeUtil.findChildElement(lastPortletElement, "portlet-name");
portletName.replaceChild(document.createTextNode(newPortletName), portletName.getFirstChild());
}
return Status.OK_STATUS;
}
}.execute();
return status;
}
Aggregations