BrightSide Workbench Full Report + Source Code
DefaultSitemap.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.sitemap;
20 
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Set;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.turro.annotation.ElephantSitemap;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.impl.repository.Repository;
30 import org.turro.elephant.impl.repository.RepositoryFile;
31 import org.turro.elephant.web.ElContext;
32 import org.turro.elephant.web.ElContextMap;
33 import org.turro.util.ImageUtil;
34 
40 public class DefaultSitemap implements IElephantSitemap {
41 
42  @Override
43  public Collection<Sitemaps.SitemapLink> getLinks() {
44  ArrayList<Sitemaps.SitemapLink> list = new ArrayList<>();
45  doRoot(list, ElContextMap.getContext("/"));
46  return list;
47  }
48 
49  private void doRoot(ArrayList<Sitemaps.SitemapLink> list, ElContext context) {
50  if(!context.hasRestrictions() && context.isIndexable()) {
51  Sitemaps.SitemapLink sml = new Sitemaps.SitemapLink(context.getWebPath());
52  Repository repository = context.getRepository();
53  for(RepositoryFile rf : repository.getRepositoryFiles("*.jpg,*.png")) {
54  try {
55  if(ImageUtil.biggerThan(rf.getFile(), 599, 599)) {
56  sml.addImage(rf.getWebPath());
57  }
58  } catch (IOException ex) {
59  Logger.getLogger(DefaultSitemap.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
60  }
61  }
62  list.add(sml);
63  }
64  doChildren(list, context.getChildren(), 0);
65  }
66 
67  private void doChildren(ArrayList<Sitemaps.SitemapLink> list, Set<ElContext> context, int level) {
68  if(level < 2 && context != null) {
69  for(ElContext cni : context) {
70  if(!cni.hasRestrictions() && cni.isIndexable()) {
71  Sitemaps.SitemapLink sml = new Sitemaps.SitemapLink(cni.getWebPath());
72  Repository repository = cni.getRepository();
73  for(RepositoryFile rf : repository.getRepositoryFiles("*.jpg,*.png")) {
74  try {
75  if(ImageUtil.biggerThan(rf.getFile(), 599, 599)) {
76  sml.addImage(rf.getWebPath());
77  }
78  } catch (IOException ex) {
79  Logger.getLogger(DefaultSitemap.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
80  }
81  }
82  list.add(sml);
83  }
84  doChildren(list, cni.getChildren(), level + 1);
85  }
86  }
87  }
88 
89 }
Collection< Sitemaps.SitemapLink > getLinks()
static ElContext getContext(IConstructor constructor)
TreeSet< ElContext > getChildren()
Definition: ElContext.java:196