use of org.omegat.filters3.Element in project archi by archimatetool.
the class ViewpointManager method loadDefaultViewpointsFile.
/**
* Load viewpoints from XML file
*/
void loadDefaultViewpointsFile() throws IOException, JDOMException {
URL url = Platform.getBundle(BUNDLE_ID).getEntry(VIEWPOINTS_FILE);
Document doc = new SAXBuilder().build(url);
Element rootElement = doc.getRootElement();
for (Element xmlViewpoint : rootElement.getChildren("viewpoint")) {
// $NON-NLS-1$
// $NON-NLS-1$
String id = xmlViewpoint.getAttributeValue("id");
if (id == null || "".equals(id)) {
// $NON-NLS-1$
// $NON-NLS-1$
System.err.println("Blank id for viewpoint");
continue;
}
// $NON-NLS-1$
Element xmlName = xmlViewpoint.getChild("name");
if (xmlName == null) {
// $NON-NLS-1$
System.err.println("No name element for viewpoint");
continue;
}
String name = xmlName.getText();
if (name == null || "".equals(name)) {
// $NON-NLS-1$
// $NON-NLS-1$
System.err.println("Blank name for viewpoint");
continue;
}
Viewpoint vp = new Viewpoint(id, name);
for (Element xmlConcept : xmlViewpoint.getChildren("concept")) {
// $NON-NLS-1$
String conceptName = xmlConcept.getText();
if (conceptName == null || "".equals(conceptName)) {
// $NON-NLS-1$
// $NON-NLS-1$
System.err.println("Blank concept name for viewpoint");
continue;
}
if (ELEMENTS_MAP.containsKey(conceptName)) {
addCollection(vp, conceptName);
} else {
EClass eClass = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(conceptName);
if (eClass != null) {
addConcept(vp, eClass);
} else {
// $NON-NLS-1$
System.err.println("Couldn't get eClass: " + conceptName);
}
}
}
VIEWPOINTS.put(id, vp);
}
}
use of org.omegat.filters3.Element in project coprhd-controller by CoprHD.
the class ServiceCatalogBuilder method build.
/**
* Parses xml file to ServiceCatalog with Jdom
*
* @param xmlFile
* The instance of xml file
* @return instance of ServiceCatalog
*/
public static ServiceCatalog build(final File xmlFile) {
String fileName = xmlFile.getName().trim().toLowerCase();
// remove suffix
if (fileName.endsWith(Constants.XML_FILE_SUFFIX)) {
fileName = fileName.substring(0, fileName.length() - Constants.XML_FILE_SUFFIX.length() - 1);
} else {
throw new IllegalArgumentException("API file is not xml format: " + fileName);
}
// filter name
int separatorIndex = fileName.indexOf(Constants.NAME_STRING_SEPARATOR);
if (separatorIndex == -1) {
throw new IllegalArgumentException("API file name should split with " + Constants.NAME_STRING_SEPARATOR + " actually: " + fileName);
}
String serviceName = fileName.substring(0, separatorIndex);
String version = fileName.substring(separatorIndex + 1, fileName.length());
Document document;
try {
document = new SAXBuilder().build(xmlFile);
} catch (Exception ex) {
throw new IllegalArgumentException("Invalid XML file:\n " + xmlFile.getAbsolutePath(), ex);
}
if (document == null) {
return null;
}
// Navigates to resource tag, it's a little tricky here, depends on structure of xml file completely.
List<Element> resourceList = document.getRootElement().getChild(Constants.REST_NODE).getChild(Constants.RESOURCES_NODE).getChildren();
// Navigates to element tag, it's a little tricky here, depends on structure of xml file completely.
List<Element> elementList = document.getRootElement().getChild(Constants.DATA_NODE).getChild(Constants.DATA_SCHEMA_NODE).getChild(Constants.ELEMENTS_NODE).getChildren();
return new ServiceCatalog(parseResource(resourceList), parseElement(elementList), serviceName, version);
}
use of org.omegat.filters3.Element in project coprhd-controller by CoprHD.
the class XmlDiff method compareXml.
/**
* Compares two documents and outputs different part info.
* <p>
* 1. ignore sequence 2. ignore element text value 3. ignore xml comment element
* </p>
*
* @param oldDocument
* The old xml document
* @param newDocument
* The new xml document
* @return
* The instance of diff
*/
public static Pair<String, String> compareXml(Document oldDocument, Document newDocument) {
Element oldRootElement = oldDocument.getRootElement();
Element newRootElement = newDocument.getRootElement();
if (compareElement(oldRootElement, newRootElement)) {
return null;
}
XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
return new Pair<String, String>(xmlOutputter.outputString(oldRootElement), xmlOutputter.outputString(newRootElement));
}
use of org.omegat.filters3.Element in project coprhd-controller by CoprHD.
the class XmlDiffTest method testElementAdd.
@Test
public void testElementAdd() {
Element oldElement = oldDocument.getRootElement().getChild("add").clone();
Element newElement = newDocument.getRootElement().getChild("add").clone();
boolean ret = XmlDiff.compareElement(oldElement, newElement);
Assert.assertFalse(ret);
Assert.assertEquals(oldElement.getChildren().size() + 1, newElement.getChildren().size());
}
use of org.omegat.filters3.Element in project coprhd-controller by CoprHD.
the class XmlDiffTest method testSameElement.
@Test
public void testSameElement() {
Element oldElement = oldDocument.getRootElement().getChild("same").clone();
Element newElement = newDocument.getRootElement().getChild("same").clone();
boolean ret = XmlDiff.compareElement(oldElement, newElement);
Assert.assertTrue(ret);
}
Aggregations