use of org.dom4j.Element in project Openfire by igniterealtime.
the class WorkgroupManager method sendWorkgroups.
private void sendWorkgroups(IQ request, Agent agent) {
IQ reply = IQ.createResultIQ(request);
Element workgroupsElement = reply.setChildElement("workgroups", "http://jabber.org/protocol/workgroup");
workgroupsElement.addAttribute("jid", agent.getAgentJID().toBareJID());
for (Workgroup workgroup : getWorkgroups()) {
if (workgroup.getAgents().contains(agent)) {
// Add the information of the workgroup
Element workgroupElement = workgroupsElement.addElement("workgroup");
workgroupElement.addAttribute("jid", workgroup.getJID().toBareJID());
}
}
send(reply);
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class OfflineSettingsProvider method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
OfflineSettingsManager offlineSettingsManager = new OfflineSettingsManager();
OfflineSettings settings;
try {
settings = offlineSettingsManager.getOfflineSettings(workgroup);
} catch (OfflineSettingsNotFound offlineSettingsNotFound) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
return;
}
Element offline = reply.setChildElement("offline-settings", "http://jivesoftware.com/protocol/workgroup");
if (ModelUtil.hasLength(settings.getRedirectURL())) {
offline.addElement("redirectPage").setText(settings.getRedirectURL());
} else {
offline.addElement("emailAddress").setText(settings.getEmailAddress());
offline.addElement("offlineText").setText(settings.getOfflineText());
offline.addElement("subject").setText(settings.getSubject());
}
workgroup.send(reply);
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class AgentHistory method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
try {
if (workgroup.getAgentManager().getAgentSession(packet.getFrom()) == null) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_authorized));
workgroup.send(reply);
return;
}
} catch (AgentNotFoundException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.not_authorized));
workgroup.send(reply);
return;
}
// Create session list
List<AgentHistoryModel> sessionList = new ArrayList<AgentHistoryModel>();
Element chatSessions = reply.setChildElement("chat-sessions", "http://jivesoftware.com/protocol/workgroup");
Element iq = packet.getChildElement();
String agentJID = iq.attributeValue("agentJID");
String ms = iq.attributeValue("maxSessions");
String date = iq.attributeValue("startDate");
long startTime = 0;
if (date != null) {
startTime = Long.parseLong(date);
}
int maxSessions = Integer.parseInt(ms);
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_AGENT_SESSIONS);
pstmt.setString(1, agentJID);
ResultSet result = pstmt.executeQuery();
while (result.next()) {
String sessionID = result.getString(1);
String joinTime = result.getString(2);
String leftTime = result.getString(3);
AgentHistoryModel model = new AgentHistoryModel();
if (ModelUtil.hasLength(joinTime) && ModelUtil.hasLength(leftTime)) {
try {
long start = Long.valueOf(joinTime);
long end = Long.valueOf(leftTime);
long totalTime = end - start;
model.setSessionID(sessionID);
model.setJoinTime(joinTime);
model.setDuration(Long.toString(totalTime));
if (start >= startTime) {
sessionList.add(model);
}
} catch (NumberFormatException e) {
Log.error(e.getMessage(), e);
}
}
}
result.close();
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
} finally {
DbConnectionManager.closeConnection(pstmt, con);
}
buildAndSend(sessionList, chatSessions, reply, workgroup, maxSessions);
}
use of org.dom4j.Element in project atlas by alibaba.
the class ManifestFileUtils method updatePreProcessManifestFile.
/**
* 更新libManifest文件
*
* @param libManifestFile
* @param mainManifestFileObject param updateSdkVersion
*/
public static void updatePreProcessManifestFile(File libManifestFile, ManifestFileObject mainManifestFileObject, boolean updateSdkVersion) throws IOException, DocumentException {
if (!libManifestFile.exists()) {
return;
}
File orgManifestFile = new File(libManifestFile.getParentFile(), "AndroidManifest-org.xml");
if (orgManifestFile.exists()) {
return;
}
libManifestFile.renameTo(orgManifestFile);
SAXReader reader = new SAXReader();
OutputFormat format = OutputFormat.createPrettyPrint();
// 设置XML文件的编码格式
format.setEncoding("UTF-8");
// 读取XML文件
Document document = reader.read(orgManifestFile);
// 得到根节点
Element root = document.getRootElement();
if (updateSdkVersion) {
Element useSdkElement = root.element("uses-sdk");
if (null == useSdkElement) {
useSdkElement = root.addElement("uses-sdk");
}
if (null != useSdkElement) {
updateElement(useSdkElement, mainManifestFileObject.getUseSdkProperties());
}
}
// 先人工处理一下tools:remove和tools:replace规则,发现有些通过ManifestMerge不一定可以
Element applicationElement = root.element("application");
Map<String, String> replaceAttrs = mainManifestFileObject.getReplaceApplicationAttribute();
List<String> removeAttrs = mainManifestFileObject.getRemoveApplicationAttribute();
if (null != applicationElement) {
// 去除lib项目里的tools属性
List<Attribute> toRomoved = new ArrayList<Attribute>();
for (Attribute attribute : applicationElement.attributes()) {
if (attribute.getName().equals("replace") || attribute.getName().equals("remove")) {
// applicationElement.remove(attribute);
// applicationElement.attributes().remove(attribute);
toRomoved.add(attribute);
}
}
if (toRomoved.size() > 0) {
for (Attribute attribute : toRomoved) {
applicationElement.remove(attribute);
}
}
updateApplicationElement(applicationElement, replaceAttrs, removeAttrs);
}
//处理packageName TODO
String packageName = root.attributeValue("package");
if (StringUtils.isEmpty(packageName)) {
packageName = ManifestFileUtils.getPackage(orgManifestFile);
}
List<? extends Node> applicatNodes = root.selectNodes("//application");
for (Node node : applicatNodes) {
Element element = (Element) node;
Attribute attribute = element.attribute("name");
if (attribute != null) {
if (!attribute.getValue().startsWith(packageName)) {
attribute.setValue(packageName + attribute.getValue());
}
}
}
fillFullClazzName(root, packageName, "activity");
fillFullClazzName(root, packageName, "provider");
fillFullClazzName(root, packageName, "receiver");
fillFullClazzName(root, packageName, "service");
saveFile(document, format, libManifestFile);
}
use of org.dom4j.Element in project tdi-studio-se by Talend.
the class RowGeneratorComponentDocumentation method generateParameters.
private void generateParameters(Element parametersElement, List elementParameterList) {
List<IElementParameter> copyElementParameterList = new ArrayList(elementParameterList);
if (elementParameterList != null && elementParameterList.size() != 0) {
for (int j = 0; j < elementParameterList.size(); j++) {
IElementParameter elemparameter = (IElementParameter) elementParameterList.get(j);
if ((!elemparameter.isShow(copyElementParameterList) && (!elemparameter.getName().equals(EParameterFieldType.SCHEMA_TYPE.getName()))) || elemparameter.getCategory().equals(EComponentCategory.VIEW) || //$NON-NLS-1$
"ACTIVATE".equals(elemparameter.getName()) || //$NON-NLS-1$
"MAP".equals(elemparameter.getName()) || "SCHEMA".equals(elemparameter.getName())) {
//$NON-NLS-1$
continue;
}
//$NON-NLS-1$
Element columnElement = parametersElement.addElement("column");
//$NON-NLS-1$
columnElement.addAttribute("name", HTMLDocUtils.checkString(elemparameter.getDisplayName()));
Object eleObj = elemparameter.getValue();
//$NON-NLS-1$
String value = "";
if (eleObj != null) {
value = eleObj.toString();
if (elemparameter.getName().equals("COMMENT")) {
//$NON-NLS-1$
columnElement.addCDATA(value);
} else {
columnElement.setText(value);
}
}
}
}
}
Aggregations