use of org.jdom2.JDOMException in project dq-easy-cloud by dq-open-cloud.
the class DqXMLUtils method getMapFromInputStream.
/**
* <p>
* 将xml流中的信息放入map中
* </p>
*
* @param inputStream
* : InputStream : xml输入流
* @param paramsMap
* : Map<String, Object> : xml结果容器
* @return Map<String, Object>
* @throws IOException
* @author daiqi 创建时间 2018年2月23日 下午12:49:06
*/
public static Map<String, Object> getMapFromInputStream(InputStream inputStream, Map<String, Object> paramsMap) throws IOException {
if (null == paramsMap) {
paramsMap = new HashMap<>();
}
SAXBuilder builder = new SAXBuilder();
try {
Document doc = builder.build(inputStream);
Element root = doc.getRootElement();
List<Element> list = root.getChildren();
Iterator<Element> it = list.iterator();
while (it.hasNext()) {
Element e = (Element) it.next();
String k = e.getName();
Object v = DqStringUtils.EMPTY;
List<Element> children = e.getChildren();
if (children.isEmpty()) {
v = e.getTextNormalize();
} else {
v = getChildren(children);
}
paramsMap.put(k, v);
}
} catch (JDOMException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return paramsMap;
}
use of org.jdom2.JDOMException in project archi by archimatetool.
the class JDOMUtils method readXMLFile.
/**
* Reads and returns a JDOM Document from file with Schema validation
* @param xmlFile The XML File
* @param schemaFile One or more Schema files
* @return The JDOM Document or null if not found
* @throws JDOMException
* @throws IOException
*/
public static Document readXMLFile(File xmlFile, File... schemaFiles) throws IOException, JDOMException {
XMLReaderJDOMFactory factory = new XMLReaderXSDFactory(schemaFiles);
SAXBuilder builder = new SAXBuilder(factory);
// This allows UNC mapped locations to load
return builder.build(new FileInputStream(xmlFile));
}
use of org.jdom2.JDOMException in project archi by archimatetool.
the class ArchimateTemplateManager method isValidTemplateFile.
@Override
protected boolean isValidTemplateFile(File file) throws IOException {
if (file == null || !file.exists()) {
return false;
}
// Ensure the template is of the right kind
String xmlString = ZipUtils.extractZipEntry(file, ZIP_ENTRY_MANIFEST);
if (xmlString == null) {
return false;
}
// If the attribute doesn't exist it was from an older version (before 2.1)
try {
Document doc = JDOMUtils.readXMLString(xmlString);
Element root = doc.getRootElement();
Attribute attType = root.getAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE);
if (attType != null) {
return ArchimateModelTemplate.XML_TEMPLATE_ATTRIBUTE_TYPE_MODEL.equals(attType.getValue());
}
} catch (JDOMException ex) {
return false;
}
return true;
}
use of org.jdom2.JDOMException 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.jdom2.JDOMException in project JMRI by JMRI.
the class JmriJTablePersistenceManager method savePreferences.
@Override
public synchronized void savePreferences(Profile profile) {
log.debug("Saving preferences (dirty={})...", this.dirty);
Element element = new Element(TABLES_ELEMENT, TABLES_NAMESPACE);
if (!this.columns.isEmpty()) {
this.columns.entrySet().stream().map((entry) -> {
Element table = new Element("table").setAttribute("name", entry.getKey());
Element columnsElement = new Element("columns");
entry.getValue().entrySet().stream().map((column) -> {
Element columnElement = new Element("column").setAttribute("name", column.getKey());
if (column.getValue().getOrder() != -1) {
columnElement.setAttribute("order", Integer.toString(column.getValue().getOrder()));
}
if (column.getValue().getWidth() != -1) {
columnElement.setAttribute("width", Integer.toString(column.getValue().getWidth()));
}
columnElement.setAttribute("hidden", Boolean.toString(column.getValue().getHidden()));
return columnElement;
}).forEach((columnElement) -> {
columnsElement.addContent(columnElement);
});
table.addContent(columnsElement);
List<SortKey> keys = this.sortKeys.get(entry.getKey());
if (keys != null) {
Element sorter = new Element(SORT_ORDER);
keys.stream().forEach((key) -> {
sorter.addContent(new Element("sortKey").setAttribute("column", Integer.toString(key.getColumn())).setAttribute(SORT_ORDER, key.getSortOrder().name()));
});
table.addContent(sorter);
}
return table;
}).forEach((table) -> {
element.addContent(table);
});
}
try {
ProfileUtils.getUserInterfaceConfiguration(ProfileManager.getDefault().getActiveProfile()).putConfigurationFragment(JDOMUtil.toW3CElement(element), false);
} catch (JDOMException ex) {
log.error("Unable to save user preferences", ex);
}
this.dirty = false;
}
Aggregations