@Test public void testGetDocumentViewXmlRootPathFromContentXmlBelowDotDir() throws IOException { Path filePath = Paths.get("test", "parent.dir", ".content.xml"); Assert.assertEquals(Paths.get("test", "parent"), DocumentViewParserValidator.getDocumentViewXmlRootPath(null, filePath)); }
static Path getDocumentViewXmlRootPath(BufferedInputStream input, Path path) throws IOException { Path name = path.getFileName(); Path rootPath = null; int nameCount = path.getNameCount(); if (name.equals(Paths.get(Constants.DOT_CONTENT_XML))) { if (nameCount > 1) { rootPath = path.subpath(0, nameCount - 1); if (rootPath.toString().endsWith(EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX)) { rootPath = Paths.get(rootPath.toString().substring(0, rootPath.toString().length() - EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX.length())); } } else { rootPath = Paths.get(""); } } else if (name.toString().endsWith(".xml")) { input.mark(1024); try { SerializationType type = XmlAnalyzer.analyze(new InputSource(new CloseShieldInputStream(input))); if (type == SerializationType.XML_DOCVIEW) { String fileName = path.getFileName().toString(); fileName = fileName.substring(0, fileName.length() - ".xml".length()); if (nameCount > 1) { rootPath = path.subpath(0, nameCount - 1).resolve(fileName); } else { rootPath = Paths.get(fileName); } } } finally { input.reset(); } } return rootPath; }
DocumentViewParserValidator implements GenericJcrDataValidator { static Path getDocumentViewXmlRootPath(BufferedInputStream input, Path path) throws IOException { Path name = path.getFileName(); Path rootPath = null; int nameCount = path.getNameCount(); if (name.equals(Paths.get(Constants.DOT_CONTENT_XML))) { if (nameCount > 1) { rootPath = path.subpath(0, nameCount - 1); if (rootPath.toString().endsWith(EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX)) { rootPath = Paths.get(rootPath.toString().substring(0, rootPath.toString().length() - EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX.length())); } } else { rootPath = Paths.get(""); } } else if (name.toString().endsWith(".xml")) { input.mark(1024); try { SerializationType type = XmlAnalyzer.analyze(new InputSource(new CloseShieldInputStream(input))); if (type == SerializationType.XML_DOCVIEW) { String fileName = path.getFileName().toString(); fileName = fileName.substring(0, fileName.length() - ".xml".length()); if (nameCount > 1) { rootPath = path.subpath(0, nameCount - 1).resolve(fileName); } else { rootPath = Paths.get(fileName); } } } finally { input.reset(); } } return rootPath; } }
DocumentViewParserValidator implements GenericJcrDataValidator { static Path getDocumentViewXmlRootPath(BufferedInputStream input, Path path) throws IOException { Path name = path.getFileName(); Path rootPath = null; int nameCount = path.getNameCount(); if (name.equals(Paths.get(Constants.DOT_CONTENT_XML))) { if (nameCount > 1) { rootPath = path.subpath(0, nameCount - 1); if (rootPath.toString().endsWith(EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX)) { rootPath = Paths.get(rootPath.toString().substring(0, rootPath.toString().length() - EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX.length())); } } else { rootPath = Paths.get(""); } } else if (name.toString().endsWith(".xml")) { input.mark(1024); try { SerializationType type = XmlAnalyzer.analyze(new InputSource(new CloseShieldInputStream(input))); if (type == SerializationType.XML_DOCVIEW) { String fileName = path.getFileName().toString(); fileName = fileName.substring(0, fileName.length() - ".xml".length()); if (nameCount > 1) { rootPath = path.subpath(0, nameCount - 1).resolve(fileName); } else { rootPath = Paths.get(fileName); } } } finally { input.reset(); } } return rootPath; } DocumentViewParserValidator(SAXParser saxParser, @NotNull ValidationMessageSeverity severity); }
DocumentViewParserValidator implements GenericJcrDataValidator { static Path getDocumentViewXmlRootPath(BufferedInputStream input, Path path) throws IOException { Path name = path.getFileName(); Path rootPath = null; int nameCount = path.getNameCount(); if (name.equals(Paths.get(Constants.DOT_CONTENT_XML))) { if (nameCount > 1) { rootPath = path.subpath(0, nameCount - 1); if (rootPath.toString().endsWith(EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX)) { rootPath = Paths.get(rootPath.toString().substring(0, rootPath.toString().length() - EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX.length())); } } else { rootPath = Paths.get(""); } } else if (name.toString().endsWith(".xml")) { input.mark(1024); try { SerializationType type = XmlAnalyzer.analyze(new InputSource(new CloseShieldInputStream(input))); if (type == SerializationType.XML_DOCVIEW) { String fileName = path.getFileName().toString(); fileName = fileName.substring(0, fileName.length() - ".xml".length()); if (nameCount > 1) { rootPath = path.subpath(0, nameCount - 1).resolve(fileName); } else { rootPath = Paths.get(fileName); } } } finally { input.reset(); } } return rootPath; } DocumentViewParserValidator(SAXParser saxParser, @NotNull ValidationMessageSeverity severity); void setDocumentViewXmlValidators(Map<String, DocumentViewXmlValidator> documentViewXmlValidators); @Override Collection<ValidationMessage> done(); @Override boolean shouldValidateJcrData(@NotNull Path filePath, @NotNull Path basePath); @Override Collection<ValidationMessage> validateJcrData(@NotNull InputStream input, @NotNull Path filePath, @NotNull Path basePath, @NotNull Map<String, Integer> nodePathsAndLineNumbers); }
DocumentViewParserValidator implements GenericJcrDataValidator { static Path getDocumentViewXmlRootPath(BufferedInputStream input, Path path) throws IOException { Path name = path.getFileName(); Path rootPath = null; int nameCount = path.getNameCount(); if (name.equals(Paths.get(Constants.DOT_CONTENT_XML))) { if (nameCount > 1) { rootPath = path.subpath(0, nameCount - 1); if (rootPath.toString().endsWith(EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX)) { rootPath = Paths.get(rootPath.toString().substring(0, rootPath.toString().length() - EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX.length())); } } else { rootPath = Paths.get(""); } } else if (name.toString().endsWith(".xml")) { input.mark(1024); try { SerializationType type = XmlAnalyzer.analyze(new InputSource(new CloseShieldInputStream(input))); if (type == SerializationType.XML_DOCVIEW) { String fileName = path.getFileName().toString(); fileName = fileName.substring(0, fileName.length() - ".xml".length()); if (nameCount > 1) { rootPath = path.subpath(0, nameCount - 1).resolve(fileName); } else { rootPath = Paths.get(fileName); } } } finally { input.reset(); } } return rootPath; } DocumentViewParserValidator(SAXParser saxParser, @NotNull ValidationMessageSeverity severity); void setDocumentViewXmlValidators(Map<String, DocumentViewXmlValidator> documentViewXmlValidators); @Override Collection<ValidationMessage> done(); @Override boolean shouldValidateJcrData(@NotNull Path filePath, @NotNull Path basePath); @Override Collection<ValidationMessage> validateJcrData(@NotNull InputStream input, @NotNull Path filePath, @NotNull Path basePath, @NotNull Map<String, Integer> nodePathsAndLineNumbers); static final String EXTENDED_FILE_AGGREGATE_FOLDER_SUFFIX; }