public TreeResource(Resource resource) { this.name = resource.getName(); this.parentName = resource.getParentName(); this.uri = resource.getURI(); }
private void collectBreadcrumbs(List<String> breadcrumbs, Resource resource, Map<String, Resource> index) { if (resource.hasParent()) { String parentName = resource.getParentName(); breadcrumbs.add(0, parentName); Resource parent = index.get(parentName); if (parent != null) { collectBreadcrumbs(breadcrumbs, parent, index); } } }
public static File asFile(Resource resource, String parentPath, String ext) { String childPath = ( resource.hasBreadcrumbs() ? StringUtils.join(resource.getBreadcrumbs(), "/") : "" ) + "/" + resource.getName() + ext; return new File(parentPath, childPath); }
protected String entity(Resource resource, Type type) { Page page = new Page(); page.syntax = ( resource.hasSyntax() ? resource.getSyntax() : "xwiki/2.0"); page.title = resource.getName(); page.content = resource.getContent(); page.parent = resource.getParentName(); switch (type) { case JSON: Gson gson = new Gson(); String json = gson.toJson(page); return json; case XML: page.xmlns = "http://www.xwiki.org"; XStream xstream = new XStream(); xstream.alias("page", Page.class); xstream.useAttributeFor(Page.class, "xmlns"); xstream.aliasField("xmlns", Page.class, "xmlns"); xstream.ignoreUnknownElements(); String xml = xstream.toXML(page); return xml; default: return resource.getContent(); } }
protected Map<String, Resource> createIndexFromEntity(String rootURI, String entity) { Collection<Page> pages = parse(entity); Map<String, Resource> index = new HashMap<>(); for (Page page : pages) { String parentName = (page.parent != null ? resolveName(page.parent.title) : null); String uri = format(PAGE_URI, rootURI, page.title); Resource resource = new Resource(uri, resolveName(page.title), parentName); index.put(resource.getName(), resource); } return index; }
private void addPath(String rootURI, String rootPath, String path, String syntax, Map<String, Resource> index) { File file = new File(path); String name = resolveName(fileNameWithoutExt(file)); String parentName = parentName(file, rootPath); String uri = fullPath(rootURI, name); Resource resource = new Resource(uri, name, parentName); resource.setContent(contentOf(file)); if ( isNotBlank(syntax) ){ resource.setSyntax(syntax); } index.put(name, resource); if (parentName != null) { addPath(rootURI, rootPath, file.getParent(), syntax, index); } }
private void loadResources(Map<String, Resource> index) { for (String name : index.keySet()) { Resource resource = index.get(name); String text = loader.loadResourceAsText(resource.getURI()); resource.setContent(text); } }
protected String entity(Resource resource, Type type) { Page page = new Page(); page.title = resource.getName(); page.text = resource.getContent(); Entity entity = new Entity(); entity.wiki_page = page; switch (type) { case JSON: Gson gson = new Gson(); return gson.toJson(entity); case XML: default: return resource.getContent(); } }
private void addPage(Map<String, Resource> result, String href, String pattern) { Page page = confluence.loadPage(href, true); Resource resource = new Resource(page.getSelfReference(), page.getTitle()); resource.setContent(page.getBody()); if (pattern == null || (pattern != null && Pattern.matches(pattern, page.getTitle()))) { result.put(page.getTitle(), resource); } if (page.hasChildren()) { for (Page child : page.getChildren()) { addPage(result, child.getSelfReference(), pattern); } } }
private void writeResource(Resource resource, File file) { try { file.getParentFile().mkdirs(); if (resource.hasContent()) { FileWriter writer = new FileWriter(file); writer.write(resource.getContent()); writer.close(); } } catch (IOException e) { throw new RuntimeException("Failed to write resource " + resource + " to file " + file, e); } }
private void indexResources() { try { String uri = configurer.getURI(); Map<String, Resource> index = indexer.indexResources(uri); wikiContext.setTreeRoots(treeRoots(treeResources(index))); } catch (Exception e) { List<TreeResource> roots = new ArrayList<TreeResource>(); roots.add(new TreeResource(new Resource("http://wiki", "Wiki"))); wikiContext.setTreeRoots(roots); // Allow for failures in indexing resources } }
protected String entity(Resource resource, Type type) { return resource.getContent(); }
protected Map<String, Resource> createIndexFromEntity(String rootURI, String entity) { Collection<Page> pages = parse(entity); Map<String, Resource> index = new HashMap<>(); for (Page page : pages) { String parentName = (page.parent != null ? resolveName(page.parent) : null); String uri = format(PAGE_URI, rootURI, page.name); Resource resource = new Resource(uri, resolveName(page.name), parentName); index.put(resource.getName(), resource); } return index; }
private void collectAncestors(List<Resource> ancestors, Resource resource, Map<String, Resource> index) { if (resource.hasParent()) { String parentName = resource.getParentName(); Resource parent = index.get(parentName); if (parent != null) { ancestors.add(0, parent); collectAncestors(ancestors, parent, index); } } }