From a4f020f2df42181bf54587acddb3b748ff5f698f Mon Sep 17 00:00:00 2001 From: adrianocrestani Date: Mon, 17 Aug 2009 06:23:38 +0000 Subject: committing domain-manager changes from patch tuscany_2552_phillipe_ramalho_08_16_2009.patch git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@804870 13f79535-47bb-0310-9956-ffa450edef68 --- .../manager/impl/ContributionCollectionImpl.java | 16 +- .../impl/DeployedCompositeCollectionImpl.java | 30 +++ .../tuscany/sca/domain/manager/impl/Searcher.java | 212 +++++++++++---------- .../src/main/resources/DomainManager.composite | 18 +- .../src/main/resources/home-gadget.html | 9 - .../domain-manager/src/main/resources/home.html | 3 - .../src/main/resources/search-gadget.html | 78 ++++---- .../domain-manager/src/main/resources/search.html | 87 +++++++-- .../src/main/resources/toolbar-gadget.html | 12 ++ .../domain-manager/src/main/resources/utils.js | 4 +- 10 files changed, 294 insertions(+), 175 deletions(-) diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java index 1bce1c135c..6531d43e4a 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java @@ -222,7 +222,12 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl // Write the workspace writeWorkspace(workspace); + // add it to the search index, contributionUpdated is called to guarantee + // only one contribution with the same URI in the index + this.domainSearch.contributionUpdated(contribution, contribution); + return key; + } public void put(String key, Item item) throws NotFoundException { @@ -256,11 +261,18 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl Workspace workspace = readWorkspace(); List contributions = workspace.getContributions(); for (int i = 0, n = contributions.size(); i < n; i++) { - if (contributions.get(i).getURI().equals(key)) { + + Contribution contribution = contributions.get(i); + + if (contribution.getURI().equals(key)) { contributions.remove(i); - + // Write the workspace writeWorkspace(workspace); + + // delete it from the search index + this.domainSearch.contributionRemoved(contribution); + return; } diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java index a8cc6efdd1..eaa5187578 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java @@ -50,6 +50,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; @@ -89,12 +90,18 @@ public class DeployedCompositeCollectionImpl implements ItemCollection, LocalIte @Reference public LocalItemCollection deployableCollection; + @Reference + public DomainSearch domainSearch; + @Reference(required=false) public LocalItemCollection processCollection; @Reference public DomainManagerConfiguration domainManagerConfiguration; + @Reference + public ContributionsReader contributionReader; + private ModelFactoryExtensionPoint modelFactories; private AssemblyFactory assemblyFactory; private StAXArtifactProcessor compositeProcessor; @@ -214,6 +221,8 @@ public class DeployedCompositeCollectionImpl implements ItemCollection, LocalIte // Write the composite collection writeCompositeCollection(compositeCollection); + updateDomainSearch(contributionURI); + return key; } @@ -238,6 +247,8 @@ public class DeployedCompositeCollectionImpl implements ItemCollection, LocalIte // Write the domain composite writeCompositeCollection(compositeCollection); + updateDomainSearch(contributionURI); + return; } } @@ -267,7 +278,10 @@ public class DeployedCompositeCollectionImpl implements ItemCollection, LocalIte // Write the domain composite writeCompositeCollection(compositeCollection); + updateDomainSearch(contributionURI); + break; + } } @@ -286,6 +300,22 @@ public class DeployedCompositeCollectionImpl implements ItemCollection, LocalIte } } + private void updateDomainSearch(String contributionURI) { + Contribution[] contributions = this.contributionReader.readContributions(); + + for (Contribution contribution : contributions) { + + if (contributionURI.equals(contribution.getURI())) { + this.domainSearch.contributionUpdated(contribution, contribution); + + break; + + } + + } + + } + public Entry[] query(String queryString) { throw new UnsupportedOperationException(); } diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java index 78b571df7e..6937a848c1 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java @@ -1,8 +1,11 @@ package org.apache.tuscany.sca.domain.manager.impl; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; import java.io.StringWriter; import java.io.Writer; +import java.net.URL; import java.util.Arrays; import java.util.Map; @@ -64,7 +67,9 @@ public class Searcher implements ItemCollection, LocalItemCollection { } public Item get(String key) throws NotFoundException { + try { + if (key.startsWith("highlight")) { int lastSemicolonIndex = key.lastIndexOf(";"); String artifact = key.substring(lastSemicolonIndex + 1); @@ -80,6 +85,7 @@ public class Searcher implements ItemCollection, LocalItemCollection { } else { throw new NotFoundException("Invalid operation!"); } + } catch (Exception t) { if (t instanceof NotFoundException) { throw (NotFoundException)t; @@ -91,61 +97,59 @@ public class Searcher implements ItemCollection, LocalItemCollection { private Item highlightArtifact(String contribution, String artifact, String query) throws NotFoundException { - // Item item = this.contributionCollection.get(contribution); - // - // if (item == null) { - // throw new NotFoundException("contribution not found: " + - // contribution); - // } - // - // String location = item.getAlternate(); - // - // if (location.endsWith(".jar") || location.endsWith(".zip")) { - // location = "jar:" + (location.startsWith("file:") ? "" : "file:") + - // location + '!' + (artifact.startsWith("/") ? "" : "/") + artifact; - // - // } else { - // location += (location.endsWith("/") ? "" : "/") + artifact; - // } - // - // try { - // Reader reader = new InputStreamReader(new - // URL(location).openStream()); - // StringBuilder sb = new StringBuilder(); - // int c; - // - // // TODO: load the chars into an array buffer instead of one - // // at a - // // time - // while ((c = reader.read()) != -1) { - // char character = (char) c; - // - // if (!Character.isIdentifierIgnorable(character)) { - // sb.append(character); - // } - // - // } - // - // String highlightedText = - // this.domainSearch.highlight(SearchFields.FILE_CONTENT_FIELD, - // sb.toString(), query); - // highlightedText = - // HighlightingUtil.replaceHighlightMarkupBy(highlightedText, - // HIGHLIGHT_START, HIGHLIGHT_END); - // - // item = new Item(); - // item.setTitle("Highlighted Artifact"); - // item.setContents(highlightedText); - // - // return item; - // - // } catch (Exception e) { - // throw new NotFoundException("Could not highlight artifact: " + - // e.getMessage(), e); - // } + Item item = this.contributionCollection.get(contribution); - return null; + if (item == null) { + throw new NotFoundException("contribution not found: " + contribution); + } + + String location = item.getAlternate(); + + if (location.endsWith(".jar") || location.endsWith(".zip")) { + location = + "jar:" + (location.startsWith("file:") ? "" : "file:") + + location + + '!' + + (artifact.startsWith("/") ? "" : "/") + + artifact; + + } else { + location += (location.endsWith("/") ? "" : "/") + artifact; + } + + try { + Reader reader = new InputStreamReader(new URL(location).openStream()); + StringBuilder sb = new StringBuilder(); + int c; + + // TODO: load the chars into an array buffer instead of one + // at a + // time + while ((c = reader.read()) != -1) { + char character = (char)c; + + if (!Character.isIdentifierIgnorable(character)) { + sb.append(character); + } + + } + + String highlightedText = this.domainSearch.highlight(SearchFields.FILE_CONTENT_FIELD, sb.toString(), query); + highlightedText = highlightedText.replaceAll("\n", "
"); + highlightedText = highlightedText.replaceAll(" ", " "); + highlightedText = + HighlightingUtil.replaceHighlightMarkupBy(highlightedText, HIGHLIGHT_START, HIGHLIGHT_END); + + item = new Item(); + item.setTitle(contribution + ";" + artifact); + item.setContents(highlightedText); + return item; + + } catch (Exception e) { + throw new NotFoundException("Could not highlight artifact: " + e.getMessage(), e); + } + } private Item executeQuery(String query) throws NotFoundException { @@ -184,7 +188,7 @@ public class Searcher implements ItemCollection, LocalItemCollection { String contents = HighlightingUtil.replaceHighlightMarkupBy(sw.getBuffer(), HIGHLIGHT_START, HIGHLIGHT_END); - item.setContents(replaceAll(contents, 40) + "end"); + item.setContents(replaceAll(contents, 40)); } else { item.setContents("No results match: " + query + ""); @@ -196,43 +200,6 @@ public class Searcher implements ItemCollection, LocalItemCollection { } - // - // private static String replaceAll(CharSequence c) { - // StringBuilder sb = new StringBuilder(); - // // HashSet set = new HashSet(); - // Arrays.sort(characters); - // // int start = 0, end = 4; - // // char[] chars = new char[end - start]; - // // System.arraycopy(characters, start, chars, 0, end - start); - // - // for (int i = 0 ; i < c.length() ; i++) { - // char actual = c.charAt(i); - // - // //if (Arrays.binarySearch(characters, actual) < 0) { - // - // if (!Character.isIdentifierIgnorable(actual)) { - // sb.append(actual); - // - // } else { - // //sb.append('0'); - // } - // - // } - // // - // // System.out.println("set-size: " + set.size()); - // // for (char character : set) { - // // System.out.print(","); - // // System.out.print((int) character); - // // System.out.print("/*" + character + "*/"); - // // - // // } - // // - // // System.out.println(); - // - // return sb.toString(); - // - // } - private static String replaceAll(CharSequence c, int less) { StringBuilder sb = new StringBuilder(); // HashSet set = new HashSet(); @@ -387,37 +354,44 @@ public class Searcher implements ItemCollection, LocalItemCollection { String content = result.getValue(); if (content != null && content.length() > 0 && DomainSearchFormatter.isHighlighted(content)) { - + String contributionPlusArtifact = + getContributionURI(result) + ";" + removeHighlighting(result.getContainer().getValue()); + writer.write(HTML_NEW_LINE); this.elementCounter++; writer.write("
"); + writer.write("em;background-color:#FFE175;max-width:100%;border-style:dashed;border-width:1px;padding:5px' id='"); + writer.write(contributionPlusArtifact); + writer.write("'>"); writer.write("

"); - //+ "view all  view all  "); - + writer.write("download

"); + writer.write("'>download

"); int i = 0; while (i < content.length()) { - StringEscapeUtils.escapeHtml(writer, content.substring(i, Math.min(i + MAX_CONTENT_LINE_WIDTH,content.length()))); + StringEscapeUtils.escapeHtml(writer, content.substring(i, Math.min(i + MAX_CONTENT_LINE_WIDTH, + content.length()))); writer.write(HTML_NEW_LINE); i += MAX_CONTENT_LINE_WIDTH; } - writer.write("

"); + writer.write("
"); writer.write("
"); } @@ -450,9 +424,41 @@ public class Searcher implements ItemCollection, LocalItemCollection { System.out.println("put"); } + @SuppressWarnings("unchecked") public Entry[] query(String queryString) { - System.out.println("query"); - return null; + + try { + + Item item; + String key; + + if (queryString.startsWith("highlight")) { + int lastSemicolonIndex = queryString.lastIndexOf(";"); + String artifact = queryString.substring(lastSemicolonIndex + 1); + int secondLastSemicolonIndex = queryString.lastIndexOf(";", lastSemicolonIndex - 1); + String contribution = queryString.substring(secondLastSemicolonIndex + 1, lastSemicolonIndex); + String query = queryString.substring("highlight".length(), secondLastSemicolonIndex); + + item = highlightArtifact(contribution, artifact, query); + key = queryString.substring("highlight".length()); + + } else if (queryString.startsWith("query")) { + key = queryString.substring("query".length()); + item = executeQuery(key); + + } else { + throw new NotFoundException("Invalid operation!"); + } + + Entry[] returnArray = new Entry[1]; + returnArray[0] = new Entry(key, item); + + return returnArray; + + } catch (Exception t) { + return new Entry[0]; + } + } } diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite index 3336d1eec6..8dc5d023dd 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite @@ -34,6 +34,11 @@ + + + + + @@ -216,6 +221,8 @@ + + @@ -257,17 +264,6 @@ - - - - - - - - - - - diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/home-gadget.html b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/home-gadget.html index 05e262e4df..e54626af0e 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/home-gadget.html +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/home-gadget.html @@ -29,17 +29,8 @@
-
- - - -
Search:
-
- diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/home.html b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/home.html index aad1856621..141a48a690 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/home.html +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/home.html @@ -36,9 +36,6 @@
-






-
This page is under construction, searching the domain is not implemented yet.
- diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search-gadget.html b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search-gadget.html index 49737a0ae5..24a7013cf7 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search-gadget.html +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search-gadget.html @@ -27,41 +27,13 @@ - - - -
- -
- -

-   -

- -
-
-
-
- -
- - + + + + +
+ + + diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search.html b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search.html index 9bd80a6349..376e44726f 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search.html +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search.html @@ -21,46 +21,107 @@ SCA Domain - Search + + + + - +

- SCA Domain

- Domain Search  + Results
-

+
+ - diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/toolbar-gadget.html b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/toolbar-gadget.html index c9389affc3..d145fde1c4 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/toolbar-gadget.html +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/toolbar-gadget.html @@ -42,6 +42,18 @@ var toolbarDiv = elementByID(gadget, 'toolbar'); toolbarDiv.innerHTML = toolbar(home, tools); + + + function gup( name ) { + name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); + var regexS = "[\\?&]"+name+"=([^&#]*)"; + var regex = new RegExp( regexS ); + var results = regex.exec( window.location.href ); + if( results == null ) + return ""; + else + return results[1]; + } diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/utils.js b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/utils.js index 77ed807e85..d41435b084 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/utils.js +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/utils.js @@ -157,7 +157,9 @@ function toolbar(home, tools) { for (var i = 0; i < tools.length; i++) { toolbar = toolbar + '' +tools[i].print() + '' } - + + toolbar = toolbar + ' ' + toolbar = toolbar + '' + '' + '
' + home.print() + '
' + -- cgit v1.2.3