use of com.centurylink.mdw.plugin.project.extensions.ExtensionModule in project mdw-designer by CenturyLinkCloud.
the class ProjectPersist method fromStream.
public WorkflowProject fromStream(InputStream inStream) {
InputSource src = new InputSource(inStream);
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
try {
// hold these until everything else is parsed
final Map<String, Map<String, String>> extensionMods = new HashMap<String, Map<String, String>>();
workflowProject.setDefaultFilesToIgnoreDuringUpdate();
SAXParser parser = parserFactory.newSAXParser();
parser.parse(src, new DefaultHandler() {
// attributes for workflow project
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (qName.equals("mdw-workflow")) {
// outer element
} else if (qName.equals("sourceProject")) {
workflowProject.setSourceProjectName(attrs.getValue("name"));
workflowProject.setAuthor(attrs.getValue("author"));
workflowProject.setProduction(Boolean.parseBoolean(attrs.getValue("production")));
} else if (qName.equals("mdwFramework")) {
workflowProject.setMdwVersion(attrs.getValue("version"));
} else if (qName.equals("webLogic")) {
workflowProject.getServerSettings().setHost(attrs.getValue("host"));
workflowProject.getServerSettings().setPort(Integer.parseInt(attrs.getValue("port")));
} else if (qName.equals("server")) {
String container = attrs.getValue("container");
if (container != null)
workflowProject.getServerSettings().setContainerType(ContainerType.valueOf(container));
workflowProject.getServerSettings().setHost(attrs.getValue("host"));
workflowProject.getServerSettings().setPort(Integer.parseInt(attrs.getValue("port")));
workflowProject.setWebContextRoot(attrs.getValue("contextRoot"));
} else if (qName.equals("database")) {
workflowProject.getMdwDataSource().setJdbcUrlWithCredentials(attrs.getValue("jdbcUrl"));
workflowProject.getMdwDataSource().setSchemaOwner(attrs.getValue("schemaOwner"));
} else if (qName.equals("repository")) {
workflowProject.getMdwVcsRepository().setProvider(attrs.getValue("provider"));
String repoUrl = attrs.getValue("url");
if (repoUrl != null && repoUrl.trim().length() > 0)
workflowProject.getMdwVcsRepository().setRepositoryUrlWithCredentials(repoUrl);
String branch = attrs.getValue("branch");
if (branch != null && branch.trim().length() > 0)
workflowProject.getMdwVcsRepository().setBranch(branch);
String localPath = attrs.getValue("localPath");
if (localPath == null || localPath.trim().length() == 0)
// compatibility
localPath = attrs.getValue("localDir");
if (localPath != null && localPath.trim().length() > 0)
workflowProject.getMdwVcsRepository().setLocalPath(localPath);
String pkgPrefixes = attrs.getValue("pkgPrefixes");
if (pkgPrefixes != null && pkgPrefixes.trim().length() > 0)
workflowProject.getMdwVcsRepository().setPkgPrefixes(PluginUtil.arrayToList(pkgPrefixes.split("\\s*,\\s*")));
} else if (qName.equals("filesToIgnore")) {
workflowProject.setFilesToIgnoreDuringUpdate(attrs.getValue("duringUpdate"));
} else {
// extension modules (need fully parsed workflowProject,
// so save)
Map<String, String> attrMap = new HashMap<String, String>();
for (int i = 0; i < attrs.getLength(); i++) attrMap.put(attrs.getQName(i), attrs.getValue(i));
extensionMods.put(qName, attrMap);
}
}
});
inStream.close();
// null
workflowProject.setRemote(workflowProject.getMdwVersion() == null);
// remote
if ("Git".equals(workflowProject.getMdwVcsRepository().getProvider()))
workflowProject.setPersistType(PersistType.Git);
else if (workflowProject.getMdwDataSource().getJdbcUrl() != null)
workflowProject.setPersistType(PersistType.Database);
else
workflowProject.setPersistType(PersistType.None);
if (!workflowProject.isRemote()) {
// process extensions
for (ExtensionModule extension : WorkflowProjectManager.getInstance().getAvailableExtensions(workflowProject)) {
for (String extensionName : extensionMods.keySet()) extension.readConfigElement(extensionName, extensionMods.get(extensionName), workflowProject);
}
} else {
// undo defaults
workflowProject.setFilesToIgnoreDuringUpdate(null);
}
} catch (Exception ex) {
PluginMessages.log(ex);
return null;
}
return workflowProject;
}
Aggregations