use of org.dom4j.DocumentException in project Spark by igniterealtime.
the class LoginDialog method checkForOldSettings.
/**
* Checks for historic Spark settings and upgrades the user.
*
* @throws Exception thrown if an error occurs.
*/
private void checkForOldSettings() throws Exception {
// Check for old settings.xml
File settingsXML = new File(Spark.getSparkUserHome(), "/settings.xml");
if (settingsXML.exists()) {
SAXReader saxReader = new SAXReader();
Document pluginXML;
try {
pluginXML = saxReader.read(settingsXML);
} catch (DocumentException e) {
Log.error(e);
return;
}
List<?> plugins = pluginXML.selectNodes("/settings");
for (Object plugin1 : plugins) {
Element plugin = (Element) plugin1;
String username = plugin.selectSingleNode("username").getText();
localPref.setLastUsername(username);
String server = plugin.selectSingleNode("server").getText();
localPref.setServer(server);
String autoLogin = plugin.selectSingleNode("autoLogin").getText();
localPref.setAutoLogin(Boolean.parseBoolean(autoLogin));
String savePassword = plugin.selectSingleNode("savePassword").getText();
localPref.setSavePassword(Boolean.parseBoolean(savePassword));
String password = plugin.selectSingleNode("password").getText();
localPref.setPasswordForUser(username + "@" + server, password);
SettingsManager.saveSettings();
}
// Delete settings File
settingsXML.delete();
}
}
use of org.dom4j.DocumentException in project sagacity-sqltoy by chenrenfei.
the class TranslateManager method parseTranslate.
/**
* @todo 解析缓存翻译的配置文件
* @param configFile
* @throws Exception
*/
public void parseTranslate(String configFile) throws Exception {
if (StringUtil.isBlank(configFile))
return;
InputStream fileIS = null;
InputStreamReader ir = null;
try {
fileIS = CommonUtils.getFileInputStream(configFile);
if (fileIS != null) {
SAXReader saxReader = new SAXReader();
saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
ir = new InputStreamReader(fileIS);
Document doc = saxReader.read(ir);
Element root = doc.getRootElement();
List translates = root.elements("translate");
if (translates == null || translates.isEmpty())
return;
Element translate;
for (Iterator iter = translates.iterator(); iter.hasNext(); ) {
translate = (Element) iter.next();
TranslateCacheModel translateCacheModel = new TranslateCacheModel();
// 对应缓存
translateCacheModel.setCacheName(translate.attributeValue("cache"));
// key对应的数据列
if (translate.attribute("key-index") != null) {
translateCacheModel.setKeyIndex(Integer.parseInt(translate.attributeValue("key-index")));
}
// 查询数据的service
if (translate.attribute("service") != null) {
translateCacheModel.setService(translate.attributeValue("service"));
}
// 查询数据的service对应的方法
if (translate.attribute("method") != null) {
translateCacheModel.setServiceMethod(translate.attributeValue("method"));
}
// 设置缓存管理器
if (translate.attribute("cache-manager") != null) {
translateCacheModel.setTranslateCacheManager(translate.attributeValue("cache-manager"));
} else if (translate.attribute("manager") != null) {
translateCacheModel.setTranslateCacheManager(translate.attributeValue("manager"));
}
// 过期时长
CacheConfig cacheConfig = new CacheConfig();
cacheConfig.setExpireSeconds(SqlToyConstants.getCacheExpireSeconds());
if (translate.attribute("expire-seconds") != null) {
cacheConfig.setExpireSeconds(Long.parseLong(translate.attributeValue("expire-seconds")));
} else if (translate.attribute("keep-alive") != null) {
cacheConfig.setExpireSeconds(Long.parseLong(translate.attributeValue("keep-alive")));
}
// sql对应的dataSource
if (translate.attribute("datasource") != null)
translateCacheModel.setDataSource(translate.attributeValue("datasource"));
else if (translate.attribute("dataSource") != null)
translateCacheModel.setDataSource(translate.attributeValue("dataSource"));
// 基于简单的sql查询对应的sql
if (translate.attribute("sql") != null) {
translateCacheModel.setSql(translate.attributeValue("sql"));
} else if (StringUtil.isNotBlank(translate.getTextTrim())) {
translateCacheModel.setSql(translate.getText());
} else if (translate.element("sql") != null) {
translateCacheModel.setSql(translate.element("sql").getText());
}
translateMap.put(translateCacheModel.getCacheName(), translateCacheModel);
}
}
} catch (DocumentException de) {
de.printStackTrace();
logger.error("读取translate对应的xml文件失败,对应文件={}", configFile, de);
throw de;
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (ir != null)
ir.close();
if (fileIS != null)
fileIS.close();
}
}
use of org.dom4j.DocumentException in project sagacity-sqltoy by chenrenfei.
the class SqlXMLConfigParse method parseSingleFile.
/**
* @todo <b>解析单个sql对应的xml文件</b>
* @param xmlFile
* @param cache
* @param encoding
* @param dialect
* @throws Exception
*/
public static void parseSingleFile(Object xmlFile, ConcurrentHashMap<String, SqlToyConfig> cache, String encoding, String dialect) throws Exception {
InputStream fileIS = null;
InputStreamReader ir = null;
try {
if (xmlFile instanceof File) {
File file = (File) xmlFile;
filesLastModifyMap.put(file.getName(), new Long(file.lastModified()));
fileIS = new FileInputStream(file);
if (logger.isDebugEnabled())
logger.debug("正在解析sql文件,对应文件={}", file.getName());
} else {
fileIS = getResourceAsStream((String) xmlFile);
if (logger.isDebugEnabled())
logger.debug("正在解析sql文件,对应文件={}", (String) xmlFile);
}
if (fileIS != null) {
if (encoding != null)
ir = new InputStreamReader(fileIS, encoding);
else
ir = new InputStreamReader(fileIS);
SAXReader saxReader = new SAXReader();
saxReader.setFeature(SqlToyConstants.XML_FETURE, false);
if (StringUtil.isNotBlank(encoding))
saxReader.setEncoding(encoding);
Document doc = saxReader.read(ir);
List<Element> sqlElts = doc.getRootElement().elements();
if (sqlElts == null || sqlElts.isEmpty())
return;
// 解析单个sql
SqlToyConfig sqlToyConfig;
for (Iterator<Element> iter = sqlElts.iterator(); iter.hasNext(); ) {
sqlToyConfig = parseSingleSql(iter.next(), dialect);
if (sqlToyConfig != null) {
// 去除sql中的注释语句并放入缓存
if (cache.get(sqlToyConfig.getId()) != null)
logger.warn("发现重复的SQL语句,id={},将被覆盖!", sqlToyConfig.getId());
cache.put(sqlToyConfig.getId(), sqlToyConfig);
}
}
}
} catch (DocumentException de) {
de.printStackTrace();
logger.error("读取sql对应的xml文件失败,对应文件={}", xmlFile, de);
throw de;
} catch (Exception e) {
e.printStackTrace();
logger.error("解析xml中对应的sql失败,对应文件={},正确的配置为<sql|mql|eql id=\"\"><![CDATA[]]></sql|mql|eql>或<sql|mql|eql id=\"\"><desc></desc><value><![CDATA[]]></value></sql|mql|eql>", xmlFile, e);
throw e;
} finally {
if (ir != null)
ir.close();
if (fileIS != null)
fileIS.close();
}
}
use of org.dom4j.DocumentException in project tmdm-studio-se by Talend.
the class ResourcesUtil method parsXMLString.
private static Document parsXMLString(String responseBody) {
SAXReader saxReader = new SAXReader();
Document document = null;
try {
document = saxReader.read(new StringReader(responseBody));
} catch (DocumentException e) {
return null;
}
return document;
}
use of org.dom4j.DocumentException in project tmdm-studio-se by Talend.
the class ExtensibleXMLEditorPageContent method toXMLExpression.
public String toXMLExpression() {
Document xmlDoc = DOMDocumentFactory.getInstance().createDocument();
fillXMLDoc(xmlDoc);
try {
// $NON-NLS-1$
return XmlUtil.formatPretty(XmlUtil.toXml(xmlDoc), "UTF-8");
} catch (DocumentException e) {
// $NON-NLS-1$
return "";
}
}
Aggregations