use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project webtools.sourceediting by eclipse.
the class AbstractCommand method formatChild.
protected void formatChild(Element child) {
if (child instanceof IDOMNode) {
IDOMModel model = ((IDOMNode) child).getModel();
try {
// tell the model that we are about to make a big model change
model.aboutToChangeModel();
IStructuredFormatProcessor formatProcessor = new FormatProcessorXML();
formatProcessor.formatNode(child);
} finally {
// tell the model that we are done with the big model change
model.changedModel();
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.
the class HookDescriptorHelper method doSetCustomJSPDir.
public IStatus doSetCustomJSPDir(IDOMDocument document, IDataModel model) {
// <hook> element
Element rootElement = document.getDocumentElement();
String customJSPsFolder = model.getStringProperty(CUSTOM_JSPS_FOLDER);
IWebProject lrproject = LiferayCore.create(IWebProject.class, project);
if (lrproject != null) {
IPath defaultWebappRootFolderFullPath = lrproject.getDefaultDocrootFolder().getFullPath();
String relativeJspFolderPath = ProjectUtil.getRelativePathFromDocroot(lrproject, defaultWebappRootFolderFullPath.append(customJSPsFolder).toPortableString());
Element customJspElement = null;
// check for existing element
NodeList nodeList = rootElement.getElementsByTagName("custom-jsp-dir");
if ((nodeList != null) && (nodeList.getLength() > 0)) {
customJspElement = (Element) nodeList.item(0);
NodeUtil.removeChildren(customJspElement);
Node textNode = document.createTextNode(relativeJspFolderPath);
customJspElement.appendChild(textNode);
} else {
// need to insert customJspElement before any <service>
NodeList serviceTags = rootElement.getElementsByTagName("service");
if ((serviceTags != null) && (serviceTags.getLength() > 0)) {
customJspElement = NodeUtil.insertChildElement(rootElement, serviceTags.item(0), "custom-jsp-dir", relativeJspFolderPath);
} else {
customJspElement = NodeUtil.appendChildElement(rootElement, "custom-jsp-dir", relativeJspFolderPath);
// append a newline text node
rootElement.appendChild(document.createTextNode(System.getProperty("line.separator")));
}
}
// format the new node added to the model;
FormatProcessorXML processor = new FormatProcessorXML();
processor.formatNode(customJspElement);
}
return Status.OK_STATUS;
}
use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.
the class JSFLiferayPortletDescriptorHelper method _updateJSFLiferayPortletXMLTo62.
private IStatus _updateJSFLiferayPortletXMLTo62(IDOMDocument document) {
Element rootElement = document.getDocumentElement();
NodeList portletNodes = rootElement.getElementsByTagName("portlet");
if (portletNodes.getLength() > 1) {
Element lastPortletElement = (Element) portletNodes.item(portletNodes.getLength() - 1);
Node headerPortletClassElement = lastPortletElement.getElementsByTagName("header-portlet-css").item(0);
NodeUtil.insertChildElement(lastPortletElement, headerPortletClassElement, "requires-namespaced-parameters", "false");
new FormatProcessorXML().formatNode(lastPortletElement);
}
return Status.OK_STATUS;
}
use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.
the class WebXMLDescriptorHelper method doAddTagLib.
protected IStatus doAddTagLib(IDOMDocument document, TagLibRefType tagLibRefType) {
if (tagLibReferenceExists(document, tagLibRefType)) {
return Status.OK_STATUS;
}
String typeId = document.getDocumentTypeId();
Element rootElement = document.getDocumentElement();
if ((typeId != null) && typeId.contains("2.3")) {
Element taglibNextSibling = NodeUtil.findChildElement(rootElement, "resource-env-ref");
if (taglibNextSibling == null) {
taglibNextSibling = NodeUtil.findChildElement(rootElement, "resource-ref");
}
if (taglibNextSibling == null) {
taglibNextSibling = NodeUtil.findChildElement(rootElement, "security-constraint");
}
if (taglibNextSibling == null) {
taglibNextSibling = NodeUtil.findChildElement(rootElement, "login-config");
}
if (taglibNextSibling == null) {
taglibNextSibling = NodeUtil.findChildElement(rootElement, "security-role");
}
if (taglibNextSibling == null) {
taglibNextSibling = NodeUtil.findChildElement(rootElement, "env-entry");
}
if (taglibNextSibling == null) {
taglibNextSibling = NodeUtil.findChildElement(rootElement, "ejb-ref");
}
if (taglibNextSibling == null) {
taglibNextSibling = NodeUtil.findChildElement(rootElement, "ejb-local-ref");
}
Element taglib = NodeUtil.insertChildElement(rootElement, taglibNextSibling, "taglib", StringPool.EMPTY);
NodeUtil.appendChildElement(taglib, "taglib-uri", tagLibRefType.getTaglibURI());
NodeUtil.appendChildElement(taglib, "taglib-location", tagLibRefType.getTaglibLocation());
if (taglibNextSibling == null) {
rootElement.appendChild(document.createTextNode(System.getProperty("line.separator")));
}
// format the new node added to the model;
FormatProcessorXML processor = new FormatProcessorXML();
processor.formatNode(taglib);
} else {
Element jspConfig = NodeUtil.findChildElement(rootElement, "jsp-config");
if (jspConfig == null) {
jspConfig = NodeUtil.appendChildElement(rootElement, "jsp-config");
}
Element taglib = NodeUtil.appendChildElement(jspConfig, "taglib");
NodeUtil.appendChildElement(taglib, "taglib-uri", tagLibRefType.getTaglibURI());
NodeUtil.appendChildElement(taglib, "taglib-location", tagLibRefType.getTaglibLocation());
rootElement.appendChild(document.createTextNode(System.getProperty("line.separator")));
// format the new node added to the model;
FormatProcessorXML processor = new FormatProcessorXML();
processor.formatNode(jspConfig);
}
return Status.OK_STATUS;
}
use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project liferay-ide by liferay.
the class ExtPluginFacetInstall method fixTilesDefExtFile.
protected void fixTilesDefExtFile() {
IWebProject webproject = LiferayCore.create(IWebProject.class, project);
IFolder webappRoot = webproject.getDefaultDocrootFolder();
IFile tilesDefExtFile = webappRoot.getFile("WEB-INF/ext-web/docroot/WEB-INF/tiles-defs-ext.xml");
if (FileUtil.notExists(tilesDefExtFile)) {
return;
}
try {
IDOMModel domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tilesDefExtFile);
domModel.aboutToChangeModel();
IDOMDocument document = domModel.getDocument();
Element root = document.getDocumentElement();
Element def = document.createElement("definition");
def.setAttribute("name", StringPool.EMPTY);
root.appendChild(def);
root.appendChild(document.createTextNode("\n"));
new FormatProcessorXML().formatNode(def);
domModel.changedModel();
domModel.save();
domModel.releaseFromEdit();
tilesDefExtFile.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (Exception e) {
ProjectCore.logError(e);
}
}
Aggregations