private String findThumbnailLocation(AbstractElementInfo<?> element) { final List<YContentFile> contentFiles = findAllThumbnailLocations(element); for (YContentFile contentFile : contentFiles) { if (contentFile.getLocations().isEmpty()) { continue; } return contentFile.getLocations().get(0); } return null; }
@SuppressWarnings("rawtypes") private String prepareVideoId(List<YContentEntry> contents){ for (YContentEntry<?> yContentEntry : contents) { if(yContentEntry instanceof YContentFile){ YContentFile file = (YContentFile) yContentEntry; if(VideoConstants.VIDEO_URL_FILE_TYPE.equals(file.getType())){ return file.getLocations().get(0); } } } return null; }
@Override public void doWithFile(YContentFile yfile) { if (contentId.equals(yfile.getId())) { List<String> locations = yfile.getLocations(); if (locations.size() > 0) { location = locations.iterator().next(); } } } };
protected String findLocationOfContentLink(List<YContentEntry> contents, String expectedType) { for (YContentEntry content : contents) { if (content instanceof YContentFile) { YContentFile contentFile = (YContentFile) content; if (expectedType.equals(contentFile.getType())) { List<String> locations = contentFile.getLocations(); if (locations != null && locations.size() > 0) { return locations.get(0).trim(); } } } } return null; }
private Page resolveFile(YContentFile file) { Page result = new Page(); if (!file.getLocations().isEmpty()) { String location = file.getLocations().get(0).replace("yar://", ""); if (file.getType().equals(YConstants.FT_PLAIN_TEXT)) { result.setText(location); } else { result.setScan(location); } } return result; }
protected YContentFile getContentFile(Link link) { String name = link.getHref(); name = StringUtils.removeStart(name, WileyComponentConstants.CONENT_LINK_PREFIX); name = StringUtils.stripStart(name, "/\\"); YContentFile contentFile = new YContentFile(name, FileTypes.FT_FULL_TEXT, "application/pdf", null); contentFile.getLocations().add(name); return contentFile; } }
@Override public void doWithFile(YContentFile file) { String type = file.getType(); if (FileTypes.FT_PLAIN_TEXT.equals(type)) { String location = file.getLocations().get(0); // System.out.println("adding..."+location); if (location != null) { Attachment<?> part = document.getAttachments().get(location); String text = ""; if (part instanceof BinaryAttachment) { byte[] content = ((BinaryAttachment) part).getContent(); text = new String(content); } textBuilder.append(text); } } }
public void convertContentLocations(YContentEntry<?> entry) { if (entry instanceof YContentDirectory) { YContentDirectory dir = (YContentDirectory) entry; for (YContentEntry<?> e : dir.getEntries()) { convertContentLocations(e); } return; } YContentFile file = (YContentFile) entry; List<String> newLocations = new ArrayList<String>(); for (String location : file.getLocations()) { newLocations.add(location.replaceAll("^" + YConstants.MISC_PACK_RELATIVE_CONTENT_PREFIX + "archive/", YConstants.MISC_LOCAL_CONTENT_ADDRESS_PREFIX)); } file.setLocations(newLocations); }
protected String resolveCoverUrl(YElement element) { for (YContentEntry e : element.getContents()) { if (e.isFile()) { YContentFile cFile = (YContentFile) e; String location = cFile.getLocations().get(0); if (location != null && ((cFile.getType() != null && cFile.getType().equals("cover") || anyContentAsCover))) { return "download/" + location.replace("yar://", ""); } } } return null; }
public String locateFile(final String[] idSplit) { String fileLocation = null; final ModelAndView content = elementContentHandler.handleContentRequest(idSplit[0], idSplit[1]); if (content != null) { final ContentFileInfo info = (ContentFileInfo) content.getModel().get(YaddaWebUtils.ATTR_CONTENT_FILE_INFO); if (info != null) { final YContentFile file = info.getContentFile(); if (file != null) { final List<String> locations = file.getLocations(); if (CollectionUtils.isNotEmpty(locations)) { fileLocation = locations.get(0); } } } } return fileLocation; }
public void convertContentLocations(YContentEntry<?> entry) { if (entry instanceof YContentDirectory) { YContentDirectory dir = (YContentDirectory) entry; for (YContentEntry<?> e : dir.getEntries()) { convertContentLocations(e); } return; } YContentFile file = (YContentFile) entry; List<String> newLocations = new ArrayList<String>(); for (String location : file.getLocations()) { if (location.startsWith(BasicPackConstants.NEW_CONTENT_DIRECTORY) ||location.startsWith(BasicPackConstants.OLD_CONTENT_DIRECTORY) || location.startsWith(BasicPackConstants.OLD_FULLTEXTS_DIRECTORY) ){ try { newLocations.add(bpi.contentPathToArchiveUri(location)); } catch (Exception ex) { log.error(ex.getLocalizedMessage(), ex); newLocations.add(location); } } else { newLocations.add(location); } } file.setLocations(newLocations); }
@Override public List<String> extractContentLocation(@SuppressWarnings("rawtypes") List<YContentEntry> contentList, String mainLevel) { List<String> result = new ArrayList<String>(); for (YContentEntry<?> content : contentList) { if (content instanceof YContentFile) { YContentFile file = (YContentFile) content; if (yModelPropertyExtractor.isFileAccepted(file, mainLevel)) { result.add(yModelPropertyExtractor.prepareLocation(file.getLocations())); } } else if (content instanceof YContentDirectory) { YContentDirectory dir = (YContentDirectory) content; result.addAll(extractContentLocation(dir.getEntries(), mainLevel)); } } return result; }
protected void fillUrls(HtmlMetaHeaders metadata, ElementMetadata elementMetadata) { YElement yElement = (YElement) elementMetadata.getContent(); Map<String, YContentFile> fulltextFiles = scanForFulltextFiles(yElement, "application/pdf", "application/octet-stream", "text/html"); if (shouldUrlBeVisible(elementMetadata)) { for (Entry<String, YContentFile> entry : fulltextFiles.entrySet()) { switch (entry.getKey()) { case "application/pdf": metadata.addMetadataName(WP_PDF_URL, constructContentPath(yElement, entry.getValue().getLocations().iterator().next())); break; default: metadata.addMetadataName(WP_FULLTEXT_HTML_URL, constructContentPath(yElement, entry.getValue().getLocations().iterator().next())); break; } } } metadata.addMetadataName(WP_ABSTRACT_URL, constructResourceUrl(yElement)); }
private boolean isLicensedContent(ElementMetadata elementMetadata, String contentPath) { YElement yElement = (YElement) elementMetadata.getContent(); for (YContentEntry<?> entry : yElement.getContents()) { if (entry.isFile()) { YContentFile contentFile = (YContentFile) entry; if (contentFile.getLocations().contains(contentPath) && notLicensedContentTypes != null && notLicensedContentTypes.contains(contentFile.getType())) { return false; } } } return true; }
private Page resolveMultiFile(YContentDirectory dir) { Page result = new Page(); if (dir.getType().equals(YConstants.CONTENT_MULTI_TYPE)) { for (YContentEntry e : dir.getEntries()) { if (e.isFile()) { YContentFile file = (YContentFile) e; if (!file.getLocations().isEmpty()) { String location = file.getLocations().get(0) .replace("yar://", ""); if (file.getType().equals(YConstants.FT_PLAIN_TEXT)) { result.setText(location); } else { result.setScan(location); } } } } } return result; }
@Override public DataResponse apply(YElement input) { ZipFile zipFile = processorState.getZipFile(); ZipEntry lastEntry = processorState.getLastZipEntry(); YAttribute attribute = new YAttribute(CommonExtractorContstants.SOURCE_ATTRIBUTE, zipFile.getName() + "/" + lastEntry.getName()); input.getAttributes().add(attribute); DataResponse dataResponse = new DataResponse(input, dataResponseQualityComparator); for (YContentFile file : createIterable(input.getContents())) { String id = file.getId(); String fileName = file.getLocations().get(0); ZipEntry entry = zipFile.getEntry(fileName); if (entry != null) { dataResponse.addContent(id, new ZipEntryResource(zipFile.getName(), entry)); } } if(insertSource){ dataResponse.addContent(CommonExtractorContstants.SOURCE_ATTRIBUTE, new ZipEntryResource(zipFile.getName(), lastEntry)); } return dataResponse; }
private String extractTextFromYElement(final YElement yElement) throws IOException { final String sep = " "; final YLanguage lang = YLanguage.Polish; StringBuilder builder = new StringBuilder(); for (YName data : yElement.getNames()) { if(lang.equals(data.getLanguage())){ builder.append(data.getText()); builder.append(sep); } } for (YDescription data : yElement.getDescriptions()) { if(lang.equals(data.getLanguage())){ builder.append(data.getText()); builder.append(sep); } } for(FilteredContentEntry<?> plainTextFile:ResourceDisplayUtilsImpl.fetchPlainTextContentEntries(yElement)){ if(plainTextFile.getSource() instanceof YContentFile){ YContentFile file = (YContentFile)plainTextFile.getSource(); ElementContent elementContent = repositoryFacade.fetchContent(yElement.getId(), file.getLocations().get(0)); builder.append(IOUtils.toString(elementContent.getStream())); builder.append(sep); } } return builder.toString().trim(); }
private List<ContentFileData> findChapterPages(List<YContentEntry> chapterEntries, Locale locale, String mainLevel) { List<ContentFileData> result = new ArrayList<ContentFileData>(); for (YContentEntry<?> content : chapterEntries) { if (content instanceof YContentFile) { YContentFile file = (YContentFile) content; if (yModelPropertyExtractor.isFileAccepted(file, mainLevel)) { result.add(new ContentFileData(file.getId(), YModelUtils.getDefaultName(file), fetchName(file.getFormat(), locale), yModelPropertyExtractor.prepareLocation(file.getLocations()))); } } else if (content instanceof YContentDirectory) { YContentDirectory dir = (YContentDirectory) content; if (ContentTypes.CONTENT_MULTI_TYPE.equals(dir.getType())) { result.addAll(findChapterPages(dir.getEntries(), locale, mainLevel)); } } } return result; }
private List<ContentInfo> getContentInfo(YContentFile file){ Collection<String> names = convertNames(file.getNames()); ContentInfo contentInfo = new ContentInfo.Builder(file.getFormat(), file.getId()) .locations(file.getLocations()) .names(names) .type(file.getType()) .build(); return Arrays.asList(contentInfo); }
private List<ContentEntryData> translateContent(List<YContentEntry> contentList, Locale locale, String mainLevel) { List<ContentEntryData> result = new ArrayList<ContentEntryData>(); for (YContentEntry<?> content : contentList) { if (content instanceof YContentFile) { YContentFile file = (YContentFile) content; if (yModelPropertyExtractor.isFileAccepted(file, mainLevel)) { result.add(new ContentFileData(file.getId(), YModelUtils.getDefaultName(file), fetchName(file.getFormat(), locale), yModelPropertyExtractor.prepareLocation(file.getLocations()))); } } else if (content instanceof YContentDirectory) { YContentDirectory dir = (YContentDirectory) content; if (ContentTypes.CONTENT_PAGED.equals(dir.getType()) && findIfContentExists(dir.getEntries(), mainLevel)) { result.add(new ContentDirectoryData(dir.getId(), getDirectoryName(dir), dir.getType(), fetchName(dir.getType(), locale))); } else if(findIfContentExists(dir.getEntries(), mainLevel)) { result.add(new ContentDirectoryData(dir.getId(), getDirectoryName(dir), dir.getType(), fetchName(dir.getType(), locale), translateContent(dir.getEntries(), locale, mainLevel))); } } } return result; }