use of org.dom4j.io.XMLWriter in project atlas by alibaba.
the class ManifestFileUtils method removeProvider.
public static void removeProvider(File androidManifestFile) throws IOException, DocumentException {
File backupFile = new File(androidManifestFile.getParentFile(), "AndroidManifest-backup.xml");
FileUtils.deleteQuietly(backupFile);
FileUtils.moveFile(androidManifestFile, backupFile);
// 声明写XML的对象
XMLWriter writer = null;
SAXReader reader = new SAXReader();
OutputFormat format = OutputFormat.createPrettyPrint();
// 设置XML文件的编码格式
format.setEncoding("UTF-8");
FileOutputStream fos = new FileOutputStream(androidManifestFile);
if (androidManifestFile.exists()) {
try {
// 读取XML文件
Document document = reader.read(backupFile);
// 得到根节点
Element root = document.getRootElement();
List<? extends Node> nodes = root.selectNodes("//provider");
for (Node node : nodes) {
Element element = (Element) node;
String name = element.attributeValue("name");
logger.info("[Remove Provider]" + name);
element.getParent().remove(element);
}
writer = new XMLWriter(fos, format);
writer.write(document);
} finally {
if (null != writer) {
writer.close();
}
IOUtils.closeQuietly(fos);
}
}
}
use of org.dom4j.io.XMLWriter in project atlas by alibaba.
the class ManifestFileUtils method postProcessManifests.
/**
* 对manifest做后续处理
*
* @param mainManifest
* @param libManifestMap
* @param baseBunfleInfoFile
* @param manifestOptions
*/
public static void postProcessManifests(File mainManifest, Map<String, File> libManifestMap, Multimap<String, File> libDependenciesMaps, File baseBunfleInfoFile, ManifestOptions manifestOptions, boolean addMultiDex, Set<String> remoteBundles) throws IOException, DocumentException {
File backupFile = new File(mainManifest.getParentFile(), "AndroidManifest-backup.xml");
FileUtils.deleteQuietly(backupFile);
FileUtils.moveFile(mainManifest, backupFile);
// 声明写XML的对象
XMLWriter writer = null;
SAXReader reader = new SAXReader();
OutputFormat format = OutputFormat.createPrettyPrint();
// 设置XML文件的编码格式
format.setEncoding("UTF-8");
FileOutputStream fos = new FileOutputStream(mainManifest);
if (mainManifest.exists()) {
try {
// 读取XML文件
Document document = reader.read(backupFile);
if (null != baseBunfleInfoFile && baseBunfleInfoFile.exists()) {
addApplicationMetaData(document, libManifestMap, baseBunfleInfoFile, manifestOptions, remoteBundles);
}
if (null != manifestOptions && manifestOptions.isAddBundleLocation()) {
addBundleLocationToDestManifest(document, libManifestMap, libDependenciesMaps, manifestOptions);
}
if (null != manifestOptions && manifestOptions.isReplaceApplication()) {
replaceManifestApplicationName(document);
}
if ((null != manifestOptions && manifestOptions.isAddMultiDexMetaData()) || addMultiDex) {
addMultiDexMetaData(document);
}
if (null != manifestOptions && manifestOptions.isRemoveProvider()) {
removeProvider(document);
}
removeCustomLaunches(document, manifestOptions);
updatePermission(document, manifestOptions);
removeComments(document);
writer = new XMLWriter(fos, format);
writer.write(document);
} finally {
if (null != writer) {
writer.close();
}
IOUtils.closeQuietly(fos);
}
}
}
use of org.dom4j.io.XMLWriter in project Openfire by igniterealtime.
the class Xep227ExporterTest method testExportUsers.
/**
* Test method for {@link org.jivesoftware.openfire.plugin.OpenfireExporter#exportUsers(org.jivesoftware.openfire.user.UserManager)}.
* @throws UserAlreadyExistsException
* @throws IOException
*/
@Test
public void testExportUsers() throws UserAlreadyExistsException, IOException {
InExporter testobject = new Xep227Exporter("serverName", offlineMessagesStore, vCardManager, privateStorage, userManager, null);
for (int i = 0; i < 10; i++) {
userManager.createUser("username" + i, "pw", "name" + i, "email" + i);
}
Document result = testobject.exportUsers();
assertNotNull(result);
assertEquals(1, result.nodeCount());
assertNotNull(result.node(0));
Element elem = ((Element) result.node(0));
assertEquals(1, elem.nodeCount());
assertNotNull(elem.node(0));
elem = ((Element) elem.node(0));
assertEquals(10, elem.nodeCount());
assertNotNull(elem.node(0));
elem = ((Element) elem.node(0));
assertEquals(3, elem.nodeCount());
assertEquals(2, elem.attributeCount());
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint());
writer.write(result);
logger.fine(out.toString());
assertTrue("Invalid input", testobject.validate(new ByteArrayInputStream(out.toByteArray())));
}
use of org.dom4j.io.XMLWriter in project Openfire by igniterealtime.
the class ImportExportPlugin method exportUsersToByteArray.
/**
* Converts the user data that is to be exported to a byte[]. If a read-only
* user store is being used a user's password will be the same as their username.
*
* @return a byte[] of the user data.
* @throws IOException if there's a problem writing to the XMLWriter.
*/
public byte[] exportUsersToByteArray(boolean xep227Support) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint());
writer.write(exportUsers(xep227Support));
return out.toByteArray();
}
use of org.dom4j.io.XMLWriter in project hibernate-orm by hibernate.
the class AdditionalJaxbMappingProducerImpl method produceAdditionalMappings.
@Override
public Collection<MappingDocument> produceAdditionalMappings(final MetadataImplementor metadata, IndexView jandexIndex, final MappingBinder mappingBinder, final MetadataBuildingContext buildingContext) {
final ServiceRegistry serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry();
final EnversService enversService = serviceRegistry.getService(EnversService.class);
if (!enversService.isEnabled()) {
// short-circuit if envers integration has been disabled.
return Collections.emptyList();
}
final ArrayList<MappingDocument> additionalMappingDocuments = new ArrayList<>();
// atm we do not have distinct origin info for envers
final Origin origin = new Origin(SourceType.OTHER, "envers");
// final DOMWriter writer = new DOMWriter();
final MappingCollector mappingCollector = new MappingCollector() {
@Override
public void addDocument(Document document) throws DocumentException {
dump(document);
// while the commented-out code here is more efficient (well, understanding that
// this whole process is un-efficient) it leads to un-decipherable messages when
// we get mapping mapping errors from envers output.
// final DOMSource domSource = new DOMSource( writer.write( document ) );
// domSource.setSystemId( "envers" );
// final Binding jaxbBinding = mappingBinder.bind( domSource, origin );
// this form at least allows us to get better error messages
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
final Writer w = new BufferedWriter(new OutputStreamWriter(baos, "UTF-8"));
final XMLWriter xw = new XMLWriter(w, new OutputFormat(" ", true));
xw.write(document);
w.flush();
} catch (IOException e) {
throw new HibernateException("Unable to bind Envers-generated XML", e);
}
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
BufferedInputStream bis = new BufferedInputStream(bais);
final Binding jaxbBinding = mappingBinder.bind(bis, origin);
final JaxbHbmHibernateMapping jaxbRoot = (JaxbHbmHibernateMapping) jaxbBinding.getRoot();
additionalMappingDocuments.add(new MappingDocument(jaxbRoot, origin, buildingContext));
}
};
enversService.initialize(metadata, mappingCollector);
return additionalMappingDocuments;
}
Aggregations