diff options
author | adrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-05 07:04:56 +0000 |
---|---|---|
committer | adrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-05 07:04:56 +0000 |
commit | 7d544d6b11dc6494170c293e6897ed6d72612d06 (patch) | |
tree | 18f24b6d896fcf0c8cfa5a6a041df082dd7672f3 /branches/sca-java-1.x/modules/domain-manager/src | |
parent | b4f758f88e8c97be870ba86080d7f0adb6dafb65 (diff) |
applying patch tuscany_2552_phillipe_ramalho_07_04_2009.patch.txt from TUSCANY-2552
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@791203 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/domain-manager/src')
9 files changed, 500 insertions, 5 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 0b304a0854..6d13e38937 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 @@ -97,8 +97,8 @@ import org.w3c.dom.Document; * @version $Rev$ $Date$ */ @Scope("COMPOSITE") -@Service(interfaces={ItemCollection.class, LocalItemCollection.class}) -public class ContributionCollectionImpl implements ItemCollection, LocalItemCollection { +@Service(interfaces={ItemCollection.class, LocalItemCollection.class, WorkspaceReader.class}) +public class ContributionCollectionImpl implements ItemCollection, LocalItemCollection, WorkspaceReader { private static final Logger logger = Logger.getLogger(ContributionCollectionImpl.class.getName()); @@ -486,7 +486,7 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl * * @return */ - private Workspace readWorkspace() { + Workspace readWorkspace() { String rootDirectory = domainManagerConfiguration.getRootDirectory(); Workspace workspace; @@ -652,5 +652,9 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl } return contributions; } + + public Workspace getWorkspace() { + return readContributions(readWorkspace()); + } } 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 e95a0cc585..a8cc6efdd1 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 @@ -59,6 +59,7 @@ import org.apache.tuscany.sca.data.collection.Item; import org.apache.tuscany.sca.data.collection.ItemCollection; import org.apache.tuscany.sca.data.collection.LocalItemCollection; import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.apache.tuscany.sca.domain.search.DomainSearch; import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.XMLSerializer; import org.osoa.sca.ServiceRuntimeException; @@ -115,7 +116,7 @@ public class DeployedCompositeCollectionImpl implements ItemCollection, LocalIte */ @Init public void initialize() throws ParserConfigurationException { - + // Create factories ExtensionPointRegistry extensionPoints = domainManagerConfiguration.getExtensionPoints(); modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); @@ -133,7 +134,7 @@ public class DeployedCompositeCollectionImpl implements ItemCollection, LocalIte public Entry<String, Item>[] getAll() { logger.fine("getAll"); - + // Return all the composites in the domain composite List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>(); Composite compositeCollection = readCompositeCollection(); diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java index d68cfa3786..04c807cba8 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java @@ -39,6 +39,7 @@ import org.apache.tuscany.sca.data.collection.Item; import org.apache.tuscany.sca.data.collection.ItemCollection; import org.apache.tuscany.sca.data.collection.LocalItemCollection; import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.apache.tuscany.sca.domain.search.DomainSearch; import org.osoa.sca.ServiceRuntimeException; import org.osoa.sca.annotations.Init; import org.osoa.sca.annotations.Reference; 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 new file mode 100644 index 0000000000..5a2873b35f --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java @@ -0,0 +1,297 @@ +package org.apache.tuscany.sca.domain.manager.impl; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.Collection; + +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.data.collection.ItemCollection; +import org.apache.tuscany.sca.data.collection.LocalItemCollection; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.apache.tuscany.sca.domain.search.DomainSearch; +import org.apache.tuscany.sca.domain.search.Result; +import org.apache.tuscany.sca.domain.search.impl.ArtifactResult; +import org.apache.tuscany.sca.domain.search.impl.FileContentResult; +import org.apache.tuscany.sca.domain.search.impl.HighlightingUtil; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Scope("COMPOSITE") +@Service(interfaces = { ItemCollection.class, LocalItemCollection.class }) +public class Searcher implements ItemCollection, LocalItemCollection { + + static char[] characters = { '\u0001'/* */, '\u0003'/* */, + '\u0004'/* */, + + }; + + final private static String HTML_NEW_LINE = "<BR/>"; + + final private static String PATH_SEPARATOR = "/"; + + @Reference + public WorkspaceReader contributionCollection; + + @Reference + public DomainSearch domainSearch; + + public void delete(String key) throws NotFoundException { + System.out.println("delete"); + } + + private static void startIndentation(int size, StringWriter writer) { + writer + .write("<p style='margin-top:0em;margin-bottom:0em;padding:0em;margin-left:"); + writer.write(Integer.toString(size)); + writer.write("em'>"); + + } + + private static void endIndentation(StringWriter writer) { + writer.write("</p>"); + } + + public Item get(String key) throws NotFoundException { + System.out.println("get"); + this.domainSearch.contributionAdded(null, this.contributionCollection + .getWorkspace()); + Result[] results = this.domainSearch.parseAndSearch(key, false); + + Item item = new Item(); + item.setTitle("Results"); + + StringWriter sw = new StringWriter(); + + for (Result result : results) { + + try { + writeToHTML(0, result, sw); + + } catch (IOException e) { + // ignore result + } + + sw.write(HTML_NEW_LINE); + + } + + String contents = HighlightingUtil.replaceHighlightMarkupBy(sw + .getBuffer(), "<font color='#FF0000'>", "</font>"); + + item.setContents(replaceAll(contents, 40) + "end"); + + System.out.println(item.getContents().indexOf("@Referencevar")); + + System.out.println(item.getContents()); + + return item; + + } + + // + // private static String replaceAll(CharSequence c) { + // StringBuilder sb = new StringBuilder(); + // // HashSet<Character> set = new HashSet<Character>(); + // 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<Character> set = new HashSet<Character>(); + 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 (actual != '\u000b' && actual != '\u0020' && + // actual != '\u000c' && actual != '\u0009' && + // actual != ')' && actual != '(') { + + if (actual > less || actual == '&' || actual == '#' + || actual == '\'' || actual == ' ' || actual == '%' + || 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 Result writeFileContentResultToHTML(int indentation, + Result result, StringWriter writer) throws IOException { + + String content = ((FileContentResult) result).getContent(); + writer.write("file:"); + + if (content != null && content.length() > 0) { + + StringEscapeUtils.escapeHtml(writer, result.getName()); + writer.write(HTML_NEW_LINE); + + startIndentation(indentation, writer); + writer.write("<span style='max-width:100%'>"); + StringEscapeUtils.escapeHtml(writer, content); + writer.write("</span>"); + endIndentation(writer); + writer.write(HTML_NEW_LINE); + + } else { + + writer.write(result.getName()); + Collection<Result> contents = result.getContents().values(); + + while (contents.size() == 1) { + result = contents.iterator().next(); + + if (result instanceof FileContentResult) { + writer.write(PATH_SEPARATOR); + writer.write(result.getName()); + + contents = result.getContents().values(); + + } else { + break; + } + + } + + if (result instanceof FileContentResult) { + FileContentResult fileResult = (FileContentResult) result; + content = fileResult.getContent(); + + if (content != null && content.length() > 0) { + + writer.write(HTML_NEW_LINE); + + startIndentation(indentation, writer); + writer.write("<span style='max-width:100%'>"); + StringEscapeUtils.escapeHtml(writer, content); + writer.write("</span>"); + endIndentation(writer); + writer.write(HTML_NEW_LINE); + + } + + } + + } + + return result; + + } + + private static void writeToHTML(int indentation, Result result, + StringWriter writer) throws IOException { + + startIndentation(indentation++, writer); + + if (result instanceof FileContentResult) { + result = writeFileContentResultToHTML(indentation, result, writer); + + } else { + + StringEscapeUtils.escapeHtml(writer, result.getClass() + .getSimpleName().substring(0, + result.getClass().getSimpleName().length() - 6)); + writer.write(':'); + StringEscapeUtils.escapeHtml(writer, result.getName()); + writer.write(HTML_NEW_LINE); + + if (result instanceof ArtifactResult) { + String location = ((ArtifactResult) result).getLocation(); + + if (location != null) { + startIndentation(indentation, writer); + writer.write("location: "); + StringEscapeUtils.escapeHtml(writer, location); + endIndentation(writer); + writer.write(HTML_NEW_LINE); + + } + + } + + } + + endIndentation(writer); + + for (Result actualResult : result.getContents().values()) { + writeToHTML(indentation, actualResult, writer); + } + + } + + public Entry<String, Item>[] getAll() { + System.out.println("getAll"); + return null; + } + + public String post(String key, Item item) { + System.out.println("post"); + return null; + } + + public void put(String key, Item item) throws NotFoundException { + System.out.println("put"); + } + + public Entry<String, Item>[] query(String queryString) { + System.out.println("query"); + return null; + } + +} diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/WorkspaceReader.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/WorkspaceReader.java new file mode 100644 index 0000000000..d4cb1d21af --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/WorkspaceReader.java @@ -0,0 +1,9 @@ +package org.apache.tuscany.sca.domain.manager.impl; + +import org.apache.tuscany.sca.workspace.Workspace; + +public interface WorkspaceReader { + + Workspace getWorkspace(); + +} 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 ba57ea45d1..d9b0939517 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 @@ -29,6 +29,13 @@ </service> </component> + <component name="SearchPage"> + <t:implementation.widget location="search.html"/> + <service name="Widget"> + <t:binding.http uri="http://localhost:9990/ui/search"/> + </service> + </component> + <component name="HomeGadget"> <t:implementation.widget location="home-gadget.html"/> <service name="Widget"> @@ -247,6 +254,29 @@ <reference name="cloudCollection" target="CloudCollectionComponent/LocalItemCollection"/> <reference name="processCollection" target="NodeProcessCollectionComponent/LocalItemCollection"/> </component> + + <component name="SearchGadget"> + <t:implementation.widget location="search-gadget.html"/> + <service name="Widget"> + <t:binding.http uri="http://localhost:9990/ui/search-gadget"/> + </service> + <reference name="searcher" target="SearcherCollectionComponent/ItemCollection"> + <t:binding.atom/> + </reference> + + </component> + + <component name="SearcherCollectionComponent"> + <implementation.java class="org.apache.tuscany.sca.domain.manager.impl.Searcher"/> + + <service name="ItemCollection"> + <t:binding.atom uri="http://localhost:9990/search" title="Search"/> + </service> + + <reference name="domainSearch" target="DomainSearchComponent"/> + <reference name="contributionCollection" target="ContributionCollectionComponent/WorkspaceReader"/> + + </component> <component name="NodeProcessCollectionFacadeComponent"> <implementation.java class="org.apache.tuscany.sca.domain.manager.impl.NodeProcessCollectionFacadeImpl"/> @@ -258,6 +288,7 @@ <reference name="processCollection" target="NodeProcessCollectionComponent/ItemCollection"> <t:binding.atom/> </reference> + </component> <component name="NodeProcessCollectionComponent"> @@ -277,5 +308,9 @@ <component name="DomainManagerConfigurationComponent"> <implementation.java class="org.apache.tuscany.sca.domain.manager.impl.DomainManagerConfigurationImpl"/> </component> + + <component name="DomainSearchComponent"> + <implementation.java class="org.apache.tuscany.sca.domain.search.impl.DomainSearchImpl"/> + </component> </composite> diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/composite-gadget.html b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/composite-gadget.html index ce1039d9e5..3af9c3f725 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/composite-gadget.html +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/composite-gadget.html @@ -65,6 +65,7 @@ var gadget = gadget(window, document); if (gadget.showContributions == null) { gadget.showContributions = true; + } var domainCompositeForm = elementByID(gadget, 'domainCompositeForm'); 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 new file mode 100644 index 0000000000..df68d9751d --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search-gadget.html @@ -0,0 +1,81 @@ +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<html> + +<head> + +<title>SCA Domain - Domain Composite</title> + +<script type="text/javascript" src="../search-gadget/search-gadget.js"></script> +<script type="text/javascript" src="utils.js"></script> + + + +<link rel="stylesheet" type="text/css" href="manager.css"> + + + +</head> + +<body> + + + <div id="domainSearch"> + + <form id="domainSearchForm"> + + <p style="margin-top:1em;margin-bottom:1em;margin-left:1em;margin-right:1em"> + <input id="searchField" type="text" value="" /> <input id="searchButton" type="button" value="Search" onclick="search()" /> + </p> + + <br> + <br> + <div id="results"></div> + </form> + + </div> +</body> + +<script type="text/javascript"> + + //@Reference + var searcher = new tuscany.sca.Reference("searcher"); + + var gadget = gadget(window, document); + + function search() { + searcher.get(elementByID(gadget, 'searchField').value, searchResponse); + } + + function searchResponse(feed) { + var entries = feed.getElementsByTagName("entry"); + var content = entries[0].getElementsByTagName("content"); + + // alert(content[0].firstChild.data); + + var results = elementByID(gadget, "results"); + results.innerHTML = content[0].firstChild.data; + + } + + elementByID(gadget, 'searchButton').onclick = search + +</script> + +</html> 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 new file mode 100644 index 0000000000..52309f3256 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search.html @@ -0,0 +1,66 @@ +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<html> +<head> +<title>SCA Domain - Search</title> + +<script type="text/javascript" src="utils.js"></script> + +<link rel="stylesheet" type="text/css" href="manager.css"> +</head> + +<body> + <div id="toolbarGadgetDiv"></div> + <br> + + <span class=hd1> + SCA Domain<br><br> + Domain Search <a href="/search/"><img src="icons/feed-icon.png" border="0"></a> + </span> + <br> + + <p> + <div id="searchGadgetDiv"></div> + </p> + + <iframe id="toolbarGadget" src="toolbar-gadget.html"></iframe> + <iframe id="searchGadget" src="search-gadget.html"marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe> +</body> + +<script type="text/javascript"> + var toolbarGadgetDiv = elementByID(document, 'toolbarGadgetDiv'); + var searchGadgetDiv = elementByID(document, 'searchGadgetDiv'); + + var toolbarGadget = elementByID(document, 'toolbarGadget'); + var searchGadget = elementByID(document, 'searchGadget'); + + function ongadget(win, doc) { + if (doc == content(toolbarGadget)) { + toolbarGadgetDiv.innerHTML = doc.body.innerHTML; + return toolbarGadgetDiv; + } else if (doc == content(searchGadget)) { + searchGadgetDiv.innerHTML = doc.body.innerHTML; + searchGadgetDiv.showContributions = true; + searchGadgetDiv.showComponents = true; + return searchGadgetDiv; + } + return document; + } +</script> +</html> |