Пример #1
0
 /**
  * Set up images separately - one image is created in both virtual wikis, the second image is set
  * up in only the shared virtual wiki.
  */
 private void setupImage(VirtualWiki virtualWiki, Topic topic)
     throws DataAccessException, IOException, WikiException {
   if (!topic.getName().toLowerCase().startsWith("image:")) {
     throw new IllegalArgumentException(
         "Cannot call JAMWikiUtilTest.setupImage for non-image topics");
   }
   TopicVersion topicVersion =
       new TopicVersion(
           null, "127.0.0.1", null, topic.getTopicContent(), topic.getTopicContent().length());
   topic.setTopicType(TopicType.IMAGE);
   topicVersion.setEditType(TopicVersion.EDIT_UPLOAD);
   // hard code image details - Image:Test Image.jpg will be created for both the "en"
   // and "test" virtual wikis, while Image:Test Image2.jpg will be created only for
   // the "test" virtual wiki.
   WikiFileVersion wikiFileVersion = new WikiFileVersion();
   if (topic.getName().equals("Image:Test Image.jpg") && virtualWiki.getName().equals("en")) {
     WikiBase.getDataHandler().writeTopic(topic, topicVersion, null, null);
     ImageUtil.writeWikiFile(
         topic,
         wikiFileVersion,
         null,
         "127.0.0.1",
         "test_image.jpg",
         "/test_image.jpg",
         "image/jpeg",
         61136,
         null);
   } else if (topic.getName().equals("Image:Test Image.jpg")
       && virtualWiki.getName().equals("test")) {
     WikiBase.getDataHandler().writeTopic(topic, topicVersion, null, null);
     ImageUtil.writeWikiFile(
         topic,
         wikiFileVersion,
         null,
         "127.0.0.1",
         "test_image_shared.jpg",
         "/test_image_shared.jpg",
         "image/jpeg",
         61136,
         null);
   } else if (topic.getName().equals("Image:Test Image2.jpg")
       && virtualWiki.getName().equals("test")) {
     WikiBase.getDataHandler().writeTopic(topic, topicVersion, null, null);
     ImageUtil.writeWikiFile(
         topic,
         wikiFileVersion,
         null,
         "127.0.0.1",
         "test_image2_shared.jpg",
         "/test_image2_shared.jpg",
         "image/jpeg",
         61136,
         null);
   }
 }
Пример #2
0
 /**
  * Refresh the current search index by re-visiting all topic pages.
  *
  * @throws Exception Thrown if any error occurs while re-indexing the Wiki.
  */
 public void refreshIndex() throws Exception {
   List<VirtualWiki> allWikis = WikiBase.getDataHandler().getVirtualWikiList();
   Topic topic;
   for (VirtualWiki virtualWiki : allWikis) {
     long start = System.currentTimeMillis();
     int count = 0;
     IndexWriter writer = null;
     try {
       writer = this.retrieveIndexWriter(virtualWiki.getName(), true);
       List<String> topicNames =
           WikiBase.getDataHandler().getAllTopicNames(virtualWiki.getName(), false);
       // FIXME - parsing all documents will be intolerably slow with even a
       // moderately large Wiki
       for (String topicName : topicNames) {
         topic = WikiBase.getDataHandler().lookupTopic(virtualWiki.getName(), topicName, false);
         if (topic == null) {
           logger.info("Unable to rebuild search index for topic: " + topicName);
           continue;
         }
         // note: no delete is necessary since a new index is being created
         this.addToIndex(writer, topic);
         count++;
       }
     } catch (Exception ex) {
       logger.error("Failure while refreshing search index", ex);
     } finally {
       try {
         if (writer != null) {
           writer.optimize();
         }
       } catch (Exception e) {
         logger.error("Exception during optimize", e);
       }
       try {
         if (writer != null) {
           writer.close();
         }
       } catch (Exception e) {
         logger.error("Exception during close", e);
       }
     }
     if (logger.isInfoEnabled()) {
       logger.info(
           "Rebuilt search index for "
               + virtualWiki.getName()
               + " ("
               + count
               + " documents) in "
               + ((System.currentTimeMillis() - start) / 1000.000)
               + " seconds");
     }
   }
 }
Пример #3
0
 private static void setupSpecialPages(Locale locale, WikiUser user, Connection conn)
     throws Exception {
   Collection all = WikiBase.getDataHandler().getVirtualWikiList(conn);
   for (Iterator iterator = all.iterator(); iterator.hasNext(); ) {
     VirtualWiki virtualWiki = (VirtualWiki) iterator.next();
     // create the default topics
     setupSpecialPage(
         locale, virtualWiki.getName(), WikiBase.SPECIAL_PAGE_STARTING_POINTS, user, false, conn);
     setupSpecialPage(
         locale, virtualWiki.getName(), WikiBase.SPECIAL_PAGE_LEFT_MENU, user, true, conn);
     setupSpecialPage(
         locale, virtualWiki.getName(), WikiBase.SPECIAL_PAGE_BOTTOM_AREA, user, true, conn);
     setupSpecialPage(
         locale, virtualWiki.getName(), WikiBase.SPECIAL_PAGE_STYLESHEET, user, true, conn);
   }
 }
Пример #4
0
 /**
  * Return the URL of the index page for the wiki.
  *
  * @throws DataAccessException Thrown if any error occurs while retrieving data.
  */
 public static String getBaseUrl() throws DataAccessException {
   VirtualWiki virtualWiki = VirtualWiki.defaultVirtualWiki();
   String url = Environment.getValue(Environment.PROP_SERVER_URL);
   url +=
       LinkUtil.buildTopicUrl(
           WEBAPP_CONTEXT_PATH, virtualWiki.getName(), virtualWiki.getRootTopicName(), true);
   return url;
 }
Пример #5
0
 /**
  * Return the URL of the index page for the wiki.
  *
  * @throws DataAccessException Thrown if any error occurs while retrieving data.
  */
 private String retrieveBaseUrl() throws DataAccessException {
   VirtualWiki virtualWiki = VirtualWiki.defaultVirtualWiki();
   String url = Environment.getValue(Environment.PROP_SERVER_URL);
   WikiLink wikiLink =
       LinkUtil.parseWikiLink(
           WikiUtil.WEBAPP_CONTEXT_PATH, virtualWiki.getName(), virtualWiki.getRootTopicName());
   url += LinkUtil.buildTopicUrl(wikiLink);
   return url;
 }
Пример #6
0
 /**
  * Determine the URL for the default virtual wiki topic, not including the application server
  * context.
  */
 public static String findDefaultVirtualWikiUrl(String virtualWikiName) {
   VirtualWiki virtualWiki = VirtualWiki.defaultVirtualWiki();
   if (!StringUtils.isBlank(virtualWikiName)) {
     try {
       virtualWiki = WikiBase.getDataHandler().lookupVirtualWiki(virtualWikiName);
     } catch (DataAccessException e) {
       logger.warn("Unable to retrieve default topic for virtual wiki", e);
     }
   }
   return "/" + virtualWiki.getName() + "/" + virtualWiki.getRootTopicName();
 }
Пример #7
0
 /**
  * This method ensures that the left menu, logo, and other required values have been loaded into
  * the session object.
  *
  * @param request The servlet request object.
  * @param next A ModelAndView object corresponding to the page being constructed.
  */
 private static void buildLayout(HttpServletRequest request, ModelAndView next) {
   String virtualWikiName = WikiUtil.getVirtualWikiFromURI(request);
   if (virtualWikiName == null) {
     logger.severe("No virtual wiki available for page request " + request.getRequestURI());
     virtualWikiName = WikiBase.DEFAULT_VWIKI;
   }
   VirtualWiki virtualWiki = retrieveVirtualWiki(virtualWikiName);
   // build the layout contents
   String leftMenu =
       ServletUtil.cachedContent(
           request.getContextPath(),
           request.getLocale(),
           virtualWikiName,
           WikiBase.SPECIAL_PAGE_LEFT_MENU,
           true);
   next.addObject("leftMenu", leftMenu);
   next.addObject("defaultTopic", virtualWiki.getDefaultTopicName());
   next.addObject("virtualWiki", virtualWiki.getName());
   next.addObject("logo", Environment.getValue(Environment.PROP_BASE_LOGO_IMAGE));
   String bottomArea =
       ServletUtil.cachedContent(
           request.getContextPath(),
           request.getLocale(),
           virtualWiki.getName(),
           WikiBase.SPECIAL_PAGE_BOTTOM_AREA,
           true);
   next.addObject("bottomArea", bottomArea);
   next.addObject(ServletUtil.PARAMETER_VIRTUAL_WIKI, virtualWiki.getName());
   Integer cssRevision = new Integer(0);
   try {
     cssRevision =
         WikiBase.getDataHandler()
             .lookupTopic(virtualWiki.getName(), WikiBase.SPECIAL_PAGE_STYLESHEET, false, null)
             .getCurrentVersionId();
   } catch (Exception e) {
   }
   next.addObject("cssRevision", cssRevision);
 }
Пример #8
0
 /** Crate a test topic. */
 protected Topic setupTopic(VirtualWiki virtualWiki, String topicName, String contents)
     throws DataAccessException, IOException, WikiException {
   if (virtualWiki == null) {
     virtualWiki = WikiBase.getDataHandler().lookupVirtualWiki("en");
   }
   Topic topic = new Topic(virtualWiki.getName(), topicName);
   topic.setTopicContent(contents);
   if (topicName.toLowerCase().startsWith("image:")) {
     this.setupImage(virtualWiki, topic);
     return topic;
   }
   this.setupTopic(topic);
   return topic;
 }