--- xwiki/core/src/test/java/com/xpn/xwiki/content/parsers/LinkParserTest.java Wed Mar 28 19:27:26 CEST 2007 +++ xwiki/core/src/test/java/com/xpn/xwiki/content/parsers/LinkParserTest.java Wed Mar 28 19:27:26 CEST 2007 @@ -29,7 +29,7 @@ */ public class LinkParserTest extends TestCase { - public void testParseAliasWhenOnlyReferenceIsSpecified() + public void testParseAliasWhenOnlyReferenceIsSpecified() throws Exception { LinkParser parser = new LinkParser(); Link link = new Link(); @@ -41,7 +41,7 @@ assertEquals("reference", sb.toString()); } - public void testParseAliasWhenValidAliasSpecified() + public void testParseAliasWhenValidAliasSpecified() throws Exception { LinkParser parser = new LinkParser(); Link link = new Link(); @@ -61,7 +61,7 @@ assertFalse(link.isUsingPipeDelimiter()); } - public void testParseAliasWhenTargetSpecified() + public void testParseAliasWhenTargetSpecified() throws Exception { LinkParser parser = new LinkParser(); Link link = new Link(); @@ -184,6 +184,19 @@ assertEquals("WebHome", sb.toString()); } + public void testParseWhenSeparatorWithoutContentAfter() throws Exception + { + LinkParser parser = new LinkParser(); + try { + parser.parse("|"); + fail("Should have thrown an exception here"); + } catch (ContentParserException expected) { + assertEquals("Error number 22002 in 17: Invalid link syntax. You need to specify a " + + "link reference or a target after the link separator, got [|]", + expected.getMessage()); + } + } + public void testParse() throws Exception { LinkParser parser = new LinkParser(); --- xwiki/core/src/main/resources/log4j.properties Tue Feb 27 14:40:31 CET 2007 +++ xwiki/core/src/main/resources/log4j.properties Tue Feb 27 14:40:31 CET 2007 @@ -24,6 +24,7 @@ ### XWiki logging configuration log4j.logger.com.xpn.xwiki=warn log4j.logger.com.xpn.xwiki.render.XWikiRadeoxRenderEngine=warn +log4j.logger.com.xpn.xwiki.content=debug ### Deactive Radeox warnings log4j.logger.org.radeox.macro.BaseLocaleMacro=error --- xwiki/core/src/main/java/com/xpn/xwiki/content/Link.java Wed Mar 28 19:27:26 CEST 2007 +++ xwiki/core/src/main/java/com/xpn/xwiki/content/Link.java Wed Mar 28 19:27:26 CEST 2007 @@ -306,17 +306,8 @@ buffer.append(':'); } - if (getSpace() != null) { - buffer.append(getSpace()); - buffer.append('.'); - } + buffer.append(getCanonicalLinkName()); - if (getPage() != null) { - buffer.append(getPage()); - } else if (getURI() != null) { - buffer.append(getURI().toString()); - } - if (getAnchor() != null) { buffer.append('#'); buffer.append(getAnchor()); @@ -335,6 +326,24 @@ return buffer.toString(); } + public String getCanonicalLinkName() + { + StringBuffer buffer = new StringBuffer(); + + if (getSpace() != null) { + buffer.append(getSpace()); + buffer.append('.'); + } + + if (getPage() != null) { + buffer.append(getPage()); + } else if (getURI() != null) { + buffer.append(getURI().toString()); + } + + return buffer.toString(); + } + /** * Append a delimiter symbol. See {@link #isUsingPipeDelimiter()} * @param buffer the buffer to append to --- xwiki/core/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java Mon Apr 09 04:57:32 CEST 2007 +++ xwiki/core/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java Mon Apr 09 04:57:32 CEST 2007 @@ -29,6 +29,9 @@ import com.xpn.xwiki.XWiki; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.content.parsers.DocumentParser; +import com.xpn.xwiki.content.parsers.ParsingResultCollection; +import com.xpn.xwiki.content.Link; import com.xpn.xwiki.doc.XWikiAttachment; import com.xpn.xwiki.doc.XWikiDocument; import com.xpn.xwiki.doc.XWikiLink; @@ -1451,27 +1454,29 @@ // need to delete existing links before saving the page's one deleteLinks(doc.getId(), context, bTransaction); - // necessary to blank links from doc - context.remove("links"); + // Parse the links from the current page and save them in the backlinks table + ParsingResultCollection results = new DocumentParser().parseLinks(doc.getContent()); - // call to RenderEngine and converting the list of links into a list of backlinks - try { - XWikiRenderer renderer = context.getWiki().getRenderingEngine().getRenderer("wiki"); - renderer.render(doc.getContent(), doc, doc, context); - } catch (Exception e) { - // If the rendering fails lets forget backlinks without errors - } + // Only keep unique links as we want to save each unique link once in the database. + // It'll fail if we save it twice as the id would be the same. In addition it would + // take longer and is thus unnecessary. + Set alreadySavedLinks = new HashSet(); + for (Iterator links = results.getValidElements().iterator(); links.hasNext();) { + Link link = (Link) links.next(); + if (!link.isExternal() + && !alreadySavedLinks.contains(link.getCanonicalLinkName())) + { + alreadySavedLinks.add(link.getCanonicalLinkName()); - List links = (List)context.get("links"); - - if (links != null){ - for (int i=0;i