- if (path != null && Files.exists(path)) {
- InputSource inputSource = new InputSource(path.toAbsolutePath().toUri().toString());
- inputSource.setEncoding(StandardCharsets.UTF_8.name());
- // TODO public id as well?
- document = dBuilder.parse(inputSource);
- } else {
- document = dBuilder.newDocument();
-// Element root = document.createElementNS(CrName.ROOT.getNamespaceURI(),
-// CrName.ROOT.get().toPrefixedString());
- Element root = document.createElementNS(CrName.CR_NAMESPACE_URI, CrName.ROOT.get().toPrefixedString());
- // root.setAttribute("xmlns", "");
-// root.setAttribute("xmlns:" + CrName.CR_DEFAULT_PREFIX, CrName.CR_NAMESPACE_URI);
- document.appendChild(root);
-
- // write it
- if (path != null) {
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- Transformer transformer = transformerFactory.newTransformer();
- DOMSource source = new DOMSource(document);
- try (Writer writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
- StreamResult result = new StreamResult(writer);
- transformer.transform(source, result);
- }
+// if (path != null && Files.exists(path)) {
+// InputSource inputSource = new InputSource(path.toAbsolutePath().toUri().toString());
+// inputSource.setEncoding(StandardCharsets.UTF_8.name());
+// // TODO public id as well?
+// document = dBuilder.parse(inputSource);
+// } else {
+ document = dBuilder.newDocument();
+ Element root = document.createElementNS(CrName.CR_NAMESPACE_URI, CrName.ROOT.get().toPrefixedString());
+
+ for (String prefix : contentTypesManager.getPrefixes().keySet()) {
+ root.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix,
+ contentTypesManager.getPrefixes().get(prefix));
+ }
+
+ document.appendChild(root);
+
+ // write it
+ if (path != null) {
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ DOMSource source = new DOMSource(document);
+ try (Writer writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
+ StreamResult result = new StreamResult(writer);
+ transformer.transform(source, result);