use of org.jdom2.input.SAXBuilder in project dq-easy-cloud by dq-open-cloud.
the class EcGenerateXmlMybatisBO method updateMybatisXmlData.
/**
* 更新mybatis的xml数据
*
* @throws IOException
* @throws JDOMException
*/
protected void updateMybatisXmlData(File generateFile) throws Exception {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(generateFile);
// 获取根元素
Element rootElement = doc.getRootElement();
// 操作更新的数据
doUpdateMybatisXmlData(rootElement);
doXmlOutputter(doc, generateFile);
}
use of org.jdom2.input.SAXBuilder in project dq-easy-cloud by dq-open-cloud.
the class XmlUtilsTest method main.
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
SAXBuilder builder = new SAXBuilder();
// Document doc = token.build(new File("src/test.xml"));
// Document doc = token.build(new FileInputStream("src/test.xml"));
// Document doc = token.build(new FileReader("src/test.xml"));
// Document doc = token.build(new URL("http://localhost:8080/jdomTest/test.xml"));
Document doc = builder.build(EcSourceCodeRelativePath.RESOURCES + "\\test.xml");
readXmlFile(doc);
// addXmlElement(doc);
// updateXmlElement(doc);
// deleteXmlElement(doc);
}
use of org.jdom2.input.SAXBuilder in project dq-easy-cloud by dq-open-cloud.
the class XmlUtilsTest method main.
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
SAXBuilder builder = new SAXBuilder();
// Document doc = token.build(new File("src/test.xml"));
// Document doc = token.build(new FileInputStream("src/test.xml"));
// Document doc = token.build(new FileReader("src/test.xml"));
// Document doc = token.build(new URL("http://localhost:8080/jdomTest/test.xml"));
Document doc = builder.build(EcSourceCodeRelativePath.RESOURCES + "\\test.xml");
readXmlFile(doc);
// addXmlElement(doc);
// updateXmlElement(doc);
// deleteXmlElement(doc);
}
use of org.jdom2.input.SAXBuilder in project archi by archimatetool.
the class RelationshipsMatrix method loadRelationships.
private void loadRelationships() {
// URL url = Platform.getBundle(BUNDLE_ID).getResource(RELATIONSHIPS_FILE);
URL url = Platform.getBundle(BUNDLE_ID).getEntry(RELATIONSHIPS_FILE);
// Load the JDOM Document from XML
Document doc = null;
try {
doc = new SAXBuilder().build(url);
} catch (Exception ex) {
ex.printStackTrace();
return;
}
// Iterate through all "source" concepts
for (Object object : doc.getRootElement().getChildren(XML_ELEMENT_SOURCE)) {
Element elementSource = (Element) object;
// Source concept name
String sourceName = elementSource.getAttributeValue(XML_ATTRIBUTE_CONCEPT);
if (sourceName == null) {
continue;
}
// Get EClass source from mapping
EClass source = null;
// Use "Relationship" as a generic super type
if (sourceName.equals("Relationship")) {
// $NON-NLS-1$
source = IArchimatePackage.eINSTANCE.getArchimateRelationship();
} else // Else use given class
{
source = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(sourceName);
}
if (source == null) {
// $NON-NLS-1$
System.err.println(getClass() + ": Couldn't find source " + sourceName);
continue;
}
// Create a new list of type TargetMatrix
List<TargetMatrix> matrixList = new ArrayList<TargetMatrix>();
// Put it in the main matrix map
matrixMap.put(source, matrixList);
// Iterate through all child "target" concepts
for (Object objectChild : elementSource.getChildren(XML_ELEMENT_TARGET)) {
Element elementTarget = (Element) objectChild;
// Target concept name
String targetName = elementTarget.getAttributeValue(XML_ATTRIBUTE_CONCEPT);
if (targetName == null) {
continue;
}
EClass target = null;
// Use "Relationship" as a generic super type
if (targetName.equals("Relationship")) {
// $NON-NLS-1$
target = IArchimatePackage.eINSTANCE.getArchimateRelationship();
} else // Else use given class
{
target = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(targetName);
}
if (target == null) {
// $NON-NLS-1$
System.err.println(getClass() + ": Couldn't find target " + targetName);
continue;
}
// Create a new TargetMatrix and add it to the list
TargetMatrix matrix = new TargetMatrix();
matrixList.add(matrix);
// Set target class
matrix.targetClass = target;
// Get relations string
String relations = elementTarget.getAttributeValue(XML_ATTRIBUTE_RELATIONS);
if (relations == null) {
continue;
}
// Take each character and add the relationship from the mapping
for (int i = 0; i < relations.length(); i++) {
char key = relations.charAt(i);
EClass relationship = relationsKeyMap.get(key);
if (relationship != null) {
matrix.getRelationships().add(relationship);
} else {
// $NON-NLS-1$
System.err.println(getClass() + ": Found unmapped key char: " + key);
}
}
}
}
}
use of org.jdom2.input.SAXBuilder in project archi by archimatetool.
the class RelationshipsMatrix method loadKeyLetters.
private void loadKeyLetters() {
// URL url = Platform.getBundle(BUNDLE_ID).getResource(RELATIONSHIPS_KEYS_FILE);
URL url = Platform.getBundle(BUNDLE_ID).getEntry(RELATIONSHIPS_KEYS_FILE);
// Load the JDOM Document from XML
Document doc = null;
try {
doc = new SAXBuilder().build(url);
} catch (Exception ex) {
ex.printStackTrace();
return;
}
for (Object object : doc.getRootElement().getChildren(XML_ELEMENT_KEY)) {
Element elementKey = (Element) object;
String keyLetter = elementKey.getAttributeValue(XML_ATTRIBUTE_CHAR);
if (keyLetter == null || keyLetter.length() != 1) {
// $NON-NLS-1$
System.err.println(getClass() + ": Key letter incorrect: " + keyLetter);
continue;
}
String relationName = elementKey.getAttributeValue(XML_ATTRIBUTE_RELATIONSHIP);
if (relationName == null) {
// $NON-NLS-1$
System.err.println(getClass() + ": Relationship name incorrect: " + relationName);
continue;
}
EClass relationship = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(relationName);
if (relationship == null) {
// $NON-NLS-1$
System.err.println(getClass() + ": Couldn't find relationship " + relationName);
continue;
}
relationsKeyMap.put(keyLetter.charAt(0), relationship);
relationsValueMap.put(relationship, keyLetter.charAt(0));
}
}
Aggregations