use of org.dom4j.Attribute in project Openfire by igniterealtime.
the class DiscoIQRegisteredProcessor method process.
@Override
public void process(Packet packet, final String subdomain, String to, String from) throws PacketRejectedException {
Log.debug("Processing packet in DiscoIQRegisteredProcessor for " + subdomain);
// Check if the jabber:iq:register is enabled in admin panel
boolean isFeatureEnabled = JiveGlobals.getBooleanProperty("plugin.remoteroster.sparkDiscoInfo", false);
if (!isFeatureEnabled) {
Log.debug("Spark extension is deactivated. Won't change the disco#info");
return;
}
final InterceptorManager interceptorManager = InterceptorManager.getInstance();
final PacketInterceptor interceptor = new PacketInterceptor() {
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
if (!processed && incoming) {
if (packet instanceof IQ) {
IQ iqPacket = (IQ) packet;
Element packetElement = iqPacket.getChildElement();
if (packetElement == null)
return;
String ns = iqPacket.getChildElement().getNamespace().getURI();
if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("jabber:iq:register") && iqPacket.getFrom().toString().equals(subdomain)) {
// Check if we are already registered
setRegistered(iqPacket.toString().contains("<registered/>"));
throw new PacketRejectedException();
} else if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("http://jabber.org/protocol/disco#info") && iqPacket.getFrom().toString().equals(subdomain)) {
/*
* This is the answer of the disco#info from spark
* to our component. add the jabber:iq:register
* feature if we are registered
*/
if (isRegistered()) {
Log.debug("Modifying disco#info packge to send registered iq feature to Spark user " + iqPacket.getTo().toString());
Attribute attribut = new DefaultAttribute("var", "jabber:iq:registered");
iqPacket.getChildElement().addElement("feature").add(attribut);
}
}
}
}
}
};
Log.debug("Creating my own listener for jabber:iq:register result to external component " + subdomain);
interceptorManager.addInterceptor(interceptor);
IQ askComponent = new IQ();
askComponent.setTo(to);
askComponent.setFrom(from);
askComponent.setType(IQ.Type.get);
Element query = new DefaultElement(QName.get("query", "jabber:iq:register"));
askComponent.setChildElement(query);
// Remove the package intercepter in 1sec
TimerTask removeInterceptorTask = new TimerTask() {
@Override
public void run() {
Log.debug("Removing my created listener for jabber:iq:register. Component " + subdomain);
interceptorManager.removeInterceptor(interceptor);
}
};
Timer timer = new Timer();
timer.schedule(removeInterceptorTask, 1000);
// Send the register query to component
dispatchPacket(askComponent);
}
use of org.dom4j.Attribute 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.Attribute in project tdi-studio-se by Talend.
the class HTMLDocGenerator method parseXml2HtmlPdf.
private List<URL> parseXml2HtmlPdf(String tempFolderPath, String jobName, String xslFilePath) throws Exception {
// clear the cache, maybe need improve it latter.
HTMLHandler.clearExternalNodeFileCache();
String htmlFilePath = tempFolderPath + File.separatorChar + jobName + IHTMLDocConstants.HTML_FILE_SUFFIX;
String xmlFilePath = tempFolderPath + File.separatorChar + jobName + IHTMLDocConstants.XML_FILE_SUFFIX;
HTMLHandler.generateHTMLFile(tempFolderPath, xslFilePath, xmlFilePath, htmlFilePath, this.externalNodeHTMLMap);
// for pdf
File originalXmlFile = new File(xmlFilePath);
if (originalXmlFile.exists()) {
//$NON-NLS-1$
String pdfXmlPath = tempFolderPath + File.separatorChar + "pdf_" + jobName + IHTMLDocConstants.XML_FILE_SUFFIX;
File pdfXmlFile = new File(pdfXmlPath);
if (pdfXmlFile.exists()) {
pdfXmlFile.delete();
}
FilesUtils.copyFile(originalXmlFile, pdfXmlFile);
SAXReader saxReader = new SAXReader();
Document document = saxReader.read(pdfXmlPath);
//$NON-NLS-1$
Attribute attri = (Attribute) document.selectNodes("/project/job/preview/@picture").get(0);
//$NON-NLS-1$
attri.setValue(IHTMLDocConstants.PICTUREFOLDERPATH + "pdf_" + jobName + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX);
//$NON-NLS-1$
List attributeList = document.selectNodes("/project/job/externalNodeComponents/component/@preview");
for (int i = 0; i < attributeList.size(); i++) {
Attribute at = (Attribute) attributeList.get(i);
//$NON-NLS-1$
String externalValue = at.getValue().substring(at.getValue().indexOf("/") + 1);
//$NON-NLS-1$
String value = IHTMLDocConstants.PICTUREFOLDERPATH + "pdf_" + externalValue;
at.setValue(value);
}
XMLHandler.generateXMLFile(tempFolderPath, pdfXmlPath, document);
HTMLHandler.clearExternalNodeFileCache();
//$NON-NLS-1$
String htmlPdfPath = tempFolderPath + File.separatorChar + "pdf_" + jobName + IHTMLDocConstants.HTML_FILE_SUFFIX;
HTMLHandler.generateHTMLFile(tempFolderPath, xslFilePath, pdfXmlPath, htmlPdfPath, this.externalNodeHTMLMap);
}
return getParsedUrl(tempFolderPath);
}
use of org.dom4j.Attribute in project Openfire by igniterealtime.
the class Xep227Exporter method exportOfflineMessages.
/**
* Adding offline messages, if there are some.
*
* @param hostname
* host name
* @param userElement
* DOM element
* @param userName
* user name
*/
@SuppressWarnings("unchecked")
private void exportOfflineMessages(String hostname, Element userElement, String userName) {
Collection<OfflineMessage> offlineMessages = offlineMessagesStore.getMessages(userName, false);
if (!offlineMessages.isEmpty()) {
Element offlineElement = userElement.addElement(OFFLINE_MESSAGES_ELEMENT_NAME);
for (OfflineMessage offMessage : offlineMessages) {
Element messageElement = offlineElement.addElement(new QName(MESSAGE_ELEMENT_NAME, JABBER_MSG_NS));
for (Object att : offMessage.getElement().attributes()) {
Attribute attribute = (Attribute) att;
messageElement.addAttribute(attribute.getQName(), attribute.getValue());
}
for (Iterator<Element> iterator = offMessage.getElement().elementIterator(); iterator.hasNext(); ) {
Element element = iterator.next();
messageElement.add(element.createCopy(new QName(element.getName(), (element.getNamespace() == Namespace.NO_NAMESPACE ? JABBER_MSG_NS : element.getNamespace()))));
}
/**
* Adding delay element
*/
Element delayElement = messageElement.addElement("delay", "urn:xmpp:delay");
delayElement.addAttribute(FROM_NAME, hostname);
delayElement.addAttribute("stamp", XMPPDateTimeFormat.format(offMessage.getCreationDate()));
delayElement.addText("Offline Storage");
}
}
}
use of org.dom4j.Attribute in project Openfire by igniterealtime.
the class WorkgroupPropertiesProvider method executeGet.
public void executeGet(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
// Retrieve the sound settings.
String authRequired = workgroup.getProperties().getProperty("authRequired");
Element returnPacket = reply.setChildElement("workgroup-properties", "http://jivesoftware.com/protocol/workgroup");
if (ModelUtil.hasLength(authRequired)) {
returnPacket.addElement("authRequired").setText(authRequired);
} else {
returnPacket.addElement("authRequired").setText("false");
}
Element iq = packet.getChildElement();
Attribute attr = iq.attribute("jid");
if (attr != null && ModelUtil.hasLength(iq.attribute("jid").getText())) {
String jid = iq.attribute("jid").getText();
UserManager userManager = UserManager.getInstance();
try {
User user = userManager.getUser(new JID(jid).getNode());
String email = user.getEmail();
String fullName = user.getName();
returnPacket.addElement("email").setText(email);
returnPacket.addElement("name").setText(fullName);
} catch (UserNotFoundException e) {
Log.error(e.getMessage(), e);
}
}
workgroup.send(reply);
}
Aggregations