Search in sources :

Example 1 with RootXmlResource

use of org.eclipse.sapphire.modeling.xml.RootXmlResource in project liferay-ide by liferay.

the class LiferayHookModelTests method strutsActionPathPossibleValuesService.

/**
 * @throws Exception
 */
@Test
public void strutsActionPathPossibleValuesService() throws Exception {
    if (shouldSkipBundleTests())
        return;
    final NewLiferayPluginProjectOp op = newProjectOp("testPossibleValues");
    op.setPluginType(PluginType.hook);
    final IProject hookProject = createAntProject(op);
    final IFolder webappRoot = LiferayCore.create(IWebProject.class, hookProject).getDefaultDocrootFolder();
    assertNotNull(webappRoot);
    final IFile hookXml = webappRoot.getFile("WEB-INF/liferay-hook.xml");
    assertEquals(true, hookXml.exists());
    final XmlResourceStore store = new XmlResourceStore(hookXml.getContents()) {

        public <A> A adapt(Class<A> adapterType) {
            if (IProject.class.equals(adapterType)) {
                return adapterType.cast(hookProject);
            }
            return super.adapt(adapterType);
        }
    };
    final Hook hook = Hook6xx.TYPE.instantiate(new RootXmlResource(store));
    assertNotNull(hook);
    final StrutsAction strutsAction = hook.getStrutsActions().insert();
    final Value<String> strutsActionPath = strutsAction.getStrutsActionPath();
    final Set<String> values = strutsActionPath.service(StrutsActionPathPossibleValuesService.class).values();
    assertNotNull(values);
    assertTrue(values.size() > 10);
}
Also used : Hook(com.liferay.ide.hook.core.model.Hook) IFile(org.eclipse.core.resources.IFile) IWebProject(com.liferay.ide.core.IWebProject) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) StrutsAction(com.liferay.ide.hook.core.model.StrutsAction) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) IProject(org.eclipse.core.resources.IProject) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) StrutsActionPathPossibleValuesService(com.liferay.ide.hook.core.model.internal.StrutsActionPathPossibleValuesService) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 2 with RootXmlResource

use of org.eclipse.sapphire.modeling.xml.RootXmlResource in project liferay-ide by liferay.

the class VersionedSchemaDefaultValueService method compute.

@Override
protected String compute() {
    String version = _defaultVersion;
    Resource elementResource = context(Element.class).resource();
    RootXmlResource resource = elementResource.adapt(RootXmlResource.class);
    if (resource != null) {
        Document document = resource.getDomDocument();
        if (document != null) {
            Node node = document.getDocumentElement();
            if (node != null) {
                String namespace = node.getNamespaceURI();
                Matcher matcher = _namespacePattern.matcher(namespace);
                if (matcher.matches()) {
                    version = matcher.group(1);
                }
            }
        }
    }
    return version.replaceAll(StringPool.UNDERSCORE, ".");
}
Also used : Matcher(java.util.regex.Matcher) Element(org.eclipse.sapphire.Element) Node(org.w3c.dom.Node) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) Resource(org.eclipse.sapphire.Resource) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) Document(org.w3c.dom.Document)

Example 3 with RootXmlResource

use of org.eclipse.sapphire.modeling.xml.RootXmlResource in project liferay-ide by liferay.

the class UploadWorkflowFileJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    try {
        String errorMsgs = KaleoUtil.checkWorkflowDefinitionForErrors(_workflowFile);
        if (!CoreUtil.empty(errorMsgs)) {
            UIUtil.async(new Runnable() {

                public void run() {
                    MessageDialog.openError(Display.getDefault().getActiveShell(), "Upload Kaleo Workflow", "Unable to upload kaleo workflow:\n\n" + errorMsgs);
                }
            });
            return Status.OK_STATUS;
        }
        JSONObject def = _kaleoConnection.getKaleoDefinitions().getJSONObject(0);
        int companyId = def.getInt("companyId");
        long groupId = def.getLong("groupId");
        long userId = _kaleoConnection.getUserByEmailAddress().getLong("userId");
        RootXmlResource rootXmlResource = new RootXmlResource(new XmlResourceStore(_workflowFile.getContents()));
        WorkflowDefinition workflowDefinition = WorkflowDefinition.TYPE.instantiate(rootXmlResource).nearest(WorkflowDefinition.class);
        String portalLocale = "en_US";
        try {
            portalLocale = _kaleoConnection.getPortalLocale(userId);
        } catch (Exception e) {
        }
        String name = workflowDefinition.getName().content();
        String titleMap = KaleoUtil.createJSONTitleMap(name, portalLocale);
        String content = CoreUtil.readStreamToString(_workflowFile.getContents());
        JSONArray drafts = _kaleoConnection.getKaleoDraftWorkflowDefinitions();
        /*
			 * go through to see if the file that is being uploaded has any
			 * existing drafts
			 */
        JSONObject existingDraft = null;
        if ((drafts != null) && (drafts.length() > 0)) {
            for (int i = 0; i < drafts.length(); i++) {
                JSONObject draft = drafts.getJSONObject(i);
                String draftName = draft.getString("name");
                if ((name != null) && name.equals(draftName)) {
                    if (existingDraft == null) {
                        existingDraft = draft;
                    } else {
                        boolean draftVersion = false;
                        if (draft.getInt("draftVersion") > existingDraft.getInt("draftVersion")) {
                            draftVersion = true;
                        }
                        boolean version = false;
                        if (draft.getInt("version") > existingDraft.getInt("version")) {
                            version = true;
                        }
                        if (draftVersion || version) {
                            existingDraft = draft;
                        }
                    }
                }
            }
        }
        if (existingDraft != null) {
            _kaleoConnection.updateKaleoDraftDefinition(name, titleMap, content, existingDraft.getInt("version"), existingDraft.getInt("draftVersion"), companyId, userId);
        }
        _kaleoConnection.publishKaleoDraftDefinition(name, titleMap, content, companyId + "", userId + "", groupId + "");
    } catch (Exception e) {
        return KaleoUI.createErrorStatus("Error uploading new kaleo workflow file.", e);
    }
    if (_runnable != null) {
        _runnable.run();
    }
    return Status.OK_STATUS;
}
Also used : JSONObject(org.json.JSONObject) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) JSONArray(org.json.JSONArray) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource)

Example 4 with RootXmlResource

use of org.eclipse.sapphire.modeling.xml.RootXmlResource in project liferay-ide by liferay.

the class PortletsNode method _getPortletAppModelElement.

private PortletApp _getPortletAppModelElement() {
    if (_modelElement == null) {
        IFile portletXmlFile = ProjectUtil.getPortletXmlFile(this._parent.getProject());
        if ((portletXmlFile != null) && portletXmlFile.exists()) {
            try {
                IStructuredModel portletXmlModel = StructuredModelManager.getModelManager().getModelForRead(portletXmlFile);
                IModelStateListener listener = new IModelStateListener() {

                    public void modelAboutToBeChanged(IStructuredModel model) {
                    }

                    public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
                    }

                    public void modelChanged(IStructuredModel model) {
                        _refresh();
                    }

                    public void modelDirtyStateChanged(IStructuredModel model, boolean dirty) {
                        _refresh();
                    }

                    public void modelReinitialized(IStructuredModel structuredModel) {
                        _refresh();
                    }

                    public void modelResourceDeleted(IStructuredModel model) {
                        _refresh();
                    }

                    public void modelResourceMoved(IStructuredModel oldModel, IStructuredModel newModel) {
                        _refresh();
                    }

                    private void _refresh() {
                        portletXmlModel.removeModelStateListener(this);
                        if (!PortletsNode.this._modelElement.disposed()) {
                            PortletsNode.this._modelElement.dispose();
                        }
                        PortletsNode.this._modelElement = null;
                        PortletsNode.this._parent.refresh();
                    }
                };
                portletXmlModel.addModelStateListener(listener);
                _modelElement = PortletApp.TYPE.instantiate(new RootXmlResource(new XmlResourceStore(portletXmlFile.getContents())));
            } catch (Exception e) {
                PortletUIPlugin.logError(e);
            }
        }
    }
    return _modelElement;
}
Also used : IFile(org.eclipse.core.resources.IFile) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) IModelStateListener(org.eclipse.wst.sse.core.internal.provisional.IModelStateListener)

Example 5 with RootXmlResource

use of org.eclipse.sapphire.modeling.xml.RootXmlResource in project liferay-ide by liferay.

the class VersionedDTDDefaultValueService method compute.

@Override
protected String compute() {
    String defaultVersion = null;
    Resource resource = context(Element.class).resource();
    RootXmlResource xmlResource = resource.adapt(RootXmlResource.class);
    if (xmlResource != null) {
        Document document = xmlResource.getDomDocument();
        if ((document != null) && (document.getDoctype() != null)) {
            String systemId = document.getDoctype().getSystemId();
            Matcher matcher = _systemIdPattern.matcher(systemId);
            if (matcher.matches()) {
                defaultVersion = matcher.group(1);
            }
        }
    }
    if (defaultVersion == null) {
        // default should be 6.0.0
        defaultVersion = "6.0.0";
    }
    return defaultVersion.replaceAll(StringPool.UNDERSCORE, ".");
}
Also used : Matcher(java.util.regex.Matcher) Element(org.eclipse.sapphire.Element) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) Resource(org.eclipse.sapphire.Resource) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) Document(org.w3c.dom.Document)

Aggregations

RootXmlResource (org.eclipse.sapphire.modeling.xml.RootXmlResource)9 XmlResourceStore (org.eclipse.sapphire.modeling.xml.XmlResourceStore)7 IFile (org.eclipse.core.resources.IFile)5 IProject (org.eclipse.core.resources.IProject)3 Element (org.eclipse.sapphire.Element)3 Test (org.junit.Test)3 IWebProject (com.liferay.ide.core.IWebProject)2 Hook (com.liferay.ide.hook.core.model.Hook)2 StrutsAction (com.liferay.ide.hook.core.model.StrutsAction)2 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)2 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)2 Matcher (java.util.regex.Matcher)2 IFolder (org.eclipse.core.resources.IFolder)2 IPath (org.eclipse.core.runtime.IPath)2 Resource (org.eclipse.sapphire.Resource)2 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)1 ILiferayProject (com.liferay.ide.core.ILiferayProject)1 StrutsActionPathPossibleValuesCacheService (com.liferay.ide.hook.core.model.internal.StrutsActionPathPossibleValuesCacheService)1 StrutsActionPathPossibleValuesService (com.liferay.ide.hook.core.model.internal.StrutsActionPathPossibleValuesService)1 Action (com.liferay.ide.kaleo.core.model.Action)1