Search in sources :

Example 1 with NodeFormatter

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());
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeFormatter(org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter) Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) Text(org.w3c.dom.Text) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Document(org.w3c.dom.Document) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 2 with NodeFormatter

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) NodeFormatter(org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter) Node(org.w3c.dom.Node) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) Element(org.w3c.dom.Element) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

NodeFormatter (org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter)2 Element (org.w3c.dom.Element)2 ILiferayRuntime (com.liferay.ide.server.core.ILiferayRuntime)1 URISyntaxException (java.net.URISyntaxException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 Text (org.w3c.dom.Text)1