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);
}
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, ".");
}
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;
}
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;
}
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, ".");
}
Aggregations