use of org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter in project webtools.sourceediting by eclipse.
the class CreatingJSPExpression method testCreateJSPExpression.
public void testCreateJSPExpression() throws IOException {
// First make (empty) structuredDocument
IModelManager modelManager = StructuredModelManager.getModelManager();
IStructuredModel model = modelManager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
assertTrue("model could not be created!", model != null);
// Now, assigning use a page directive, but leaving embedded type the same as default
model.getStructuredDocument().setText(this, "<%@ page contentType=\"text/html\" language=\"java\" %>");
Document doc = ((IDOMModel) model).getDocument();
Element jspexpression = doc.createElement("jsp:expression");
((IDOMElement) jspexpression).setJSPTag(true);
doc.appendChild(jspexpression);
Text javacode = doc.createTextNode(" // some java code here; if (x <0) return new String(\"0\") else return new String (\"1\"); ");
jspexpression.appendChild(javacode);
Text cdatasection = doc.createCDATASection(" // some cdata java code here; if (x <0) return new String(\"0\") else return new String (\"1\"); ");
doc.appendChild(cdatasection);
// format's not needed, just prettier ... not sure why
// it won't work right on whole document.
new NodeFormatter().format(jspexpression);
new NodeFormatter().format(cdatasection);
System.out.println("document text: ");
System.out.println(model.getStructuredDocument().get());
}
use of org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter in project liferay-ide by liferay.
the class MavenUtil method createNewLiferayProfileNode.
public static Node createNewLiferayProfileNode(Document pomDocument, NewLiferayProfile newLiferayProfile) {
Node newNode = null;
String liferayVersion = newLiferayProfile.getLiferayVersion().content();
try {
String runtimeName = newLiferayProfile.getRuntimeName().content();
ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(ServerUtil.getRuntime(runtimeName));
Element root = pomDocument.getDocumentElement();
Element profiles = NodeUtil.findChildElement(root, "profiles");
if (profiles == null) {
newNode = profiles = NodeUtil.appendChildElement(root, "profiles");
}
Element newProfile = null;
if (profiles != null) {
NodeUtil.appendTextNode(profiles, "\n");
newProfile = NodeUtil.appendChildElement(profiles, "profile");
NodeUtil.appendTextNode(profiles, "\n");
if (newNode == null) {
newNode = newProfile;
}
}
if (newProfile != null) {
IPath serverDir = liferayRuntime.getAppServerDir();
IPath autoDeployDir = serverDir.removeLastSegments(1).append("deploy");
NodeUtil.appendTextNode(newProfile, "\n\t");
NodeUtil.appendChildElement(newProfile, "id", newLiferayProfile.getId().content());
NodeUtil.appendTextNode(newProfile, "\n\t");
Element propertiesElement = NodeUtil.appendChildElement(newProfile, "properties");
NodeUtil.appendTextNode(newProfile, "\n\t");
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.version", liferayVersion);
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.maven.plugin.version", liferayVersion);
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.auto.deploy.dir", autoDeployDir.toOSString());
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.app.server.deploy.dir", liferayRuntime.getAppServerDeployDir().toOSString());
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.app.server.lib.global.dir", liferayRuntime.getAppServerLibGlobalDir().toOSString());
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.app.server.portal.dir", liferayRuntime.getAppServerPortalDir().toOSString());
NodeUtil.appendTextNode(propertiesElement, "\n\t");
NodeFormatter formatter = new NodeFormatter();
formatter.format(newNode);
}
} catch (Exception e) {
LiferayMavenCore.logError("Unable to add new liferay profile.", e);
}
return newNode;
}
Aggregations