| /***************************************************************************** |
| * Copyright (c) 2017 CEA LIST and others. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Francois LE FEVRE (CEA) francois.le-fevre@cea.fr - Initial API and Implementation |
| * |
| *****************************************************************************/ |
| package org.eclipse.papyrus.developer.migration.elementtypereference.creationmenumodel; |
| |
| import java.io.File; |
| import java.util.List; |
| |
| import javax.xml.parsers.DocumentBuilder; |
| import javax.xml.parsers.DocumentBuilderFactory; |
| |
| import org.apache.commons.io.FileUtils; |
| import org.eclipse.papyrus.developer.migration.elementtypereference.common.AbstractElementTypeMigrationModel; |
| import org.w3c.dom.Document; |
| import org.w3c.dom.Element; |
| import org.w3c.dom.Node; |
| import org.w3c.dom.NodeList; |
| |
| |
| /** |
| * |
| * Dedicated to migrate |
| * |
| */ |
| public class ElementTypeMigrationCreationMenuModel extends AbstractElementTypeMigrationModel { |
| |
| |
| |
| static String CREATIONMENUMODEL = new String("creationmenumodel"); |
| |
| public ElementTypeMigrationCreationMenuModel(String folderRootGit4ElementtypeData) { |
| super(folderRootGit4ElementtypeData); |
| } |
| |
| public void migrateModelDocuments(String rootFolder, String outputRootFolder) { |
| Document doc = null; |
| try { |
| String[] extensions = new String[] { CREATIONMENUMODEL }; |
| |
| File folder = new File(rootFolder); |
| |
| List<File> files = (List<File>) FileUtils.listFiles(folder, extensions, true); |
| boolean migrated; |
| for (File file : files) { |
| System.err.println("Dealing with creationmenumodel: " + file.getAbsolutePath()); |
| migrated = false; |
| if (file.isFile()) { |
| DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); |
| DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); |
| doc = dBuilder.parse(file); |
| |
| // optional, but recommended |
| // read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work |
| doc.getDocumentElement().normalize(); |
| |
| Element root = doc.getDocumentElement(); |
| if (root.getAttribute("xmlns:elementtypesconfigurations").length() == 0) { |
| root.setAttribute("xmlns:elementtypesconfigurations", "http://www.eclipse.org/papyrus/infra/elementtypesconfigurations/1.2"); |
| } |
| |
| NodeList nList = doc.getElementsByTagName("menu"); |
| |
| for (int temp = 0; temp < nList.getLength(); temp++) { |
| |
| Node nNode = nList.item(temp); |
| |
| Element eElement = (Element) nNode; |
| if (eElement.getAttribute("elementTypeIdRef") != null && eElement.getAttribute("identifier") != null) { |
| if (identifier2Id.get(eElement.getAttribute("elementTypeIdRef")) != null) { |
| Element newChild = doc.createElement("elementType"); |
| newChild.setAttribute("xsi:type", "elementtypesconfigurations:MetamodelTypeConfiguration"); |
| |
| newChild.setAttribute("href", "platform:/plugin/" + identifier2Id.get(eElement.getAttribute("elementTypeIdRef")).get(1) + "#" + identifier2Id.get(eElement.getAttribute("elementTypeIdRef")).get(0)); |
| |
| eElement.appendChild(newChild); |
| eElement.removeAttribute("elementTypeIdRef"); |
| migrated = true; |
| } else { |
| System.err.println(eElement.getAttribute("elementTypeIdRef") + "\t@" + identifier2Id.get(eElement.getAttribute("elementTypeIdRef"))); |
| } |
| } |
| } |
| if (migrated) { |
| exportDocument2File(doc, file, outputRootFolder); |
| } |
| } |
| } |
| } catch (Exception e) { |
| e.printStackTrace(); |
| } |
| } |
| |
| } |