summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoradrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68>2009-08-10 01:40:02 +0000
committeradrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68>2009-08-10 01:40:02 +0000
commit8e7db232ee169c8d8513c8e8a84921d905e4af2d (patch)
tree0cc43203723c019a13f23a1b46b466639ed37da0
parent1dff5319f17ee5bec9588675d43a84e836627a5d (diff)
applying tuscany_2552_domain_search_phillipe_ramalho_08_08_2009.patch and tuscany_2552_domain_manager_phillipe_ramalho_08_08_2009.patch submitted to TUSCANY-2552
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@802637 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java14
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionsReader.java9
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeCollectionImpl.java723
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/FileServiceImpl.java253
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java375
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/WorkspaceReader.java9
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite8
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/artifact.pngbin0 -> 228 bytes
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/component.pngbin0 -> 226 bytes
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/composite.pngbin0 -> 202 bytes
-rw-r--r--branches/sca-java-1.x/modules/domain-manager/src/main/resources/search-gadget.html50
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java15
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java8
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java6
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java3
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java85
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResult.java25
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResultProcessor.java55
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResult.java11
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResultFactory.java36
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentDocumentProcessor.java60
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResult.java16
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResultFactory.java35
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeDocumentProcessor.java53
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResult.java15
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResultFactory.java36
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeDocumentProcessor.java8
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResult.java15
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResultFactory.java35
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java40
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResult.java15
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResultFactory.java36
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileContent.java35
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java7
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DirectoryDocumentProcessor.java49
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/Document.java2
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzer.java16
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java5
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java17
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java410
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java16
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java1
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResult.java25
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java120
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java49
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java69
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java2
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java36
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyResult.java20
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ReferenceResult.java27
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultFactoryList.java55
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java40
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java171
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java10
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ServiceResult.java27
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java22
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java91
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java11
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java264
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java5
60 files changed, 2012 insertions, 1639 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 6d13e38937..5dcd09770b 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
@@ -74,6 +74,7 @@ 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.manager.impl.ContributionCollectionImpl.Cache.ContributionCache;
+import org.apache.tuscany.sca.domain.search.DomainSearch;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
@@ -97,8 +98,8 @@ import org.w3c.dom.Document;
* @version $Rev$ $Date$
*/
@Scope("COMPOSITE")
-@Service(interfaces={ItemCollection.class, LocalItemCollection.class, WorkspaceReader.class})
-public class ContributionCollectionImpl implements ItemCollection, LocalItemCollection, WorkspaceReader {
+@Service(interfaces={ItemCollection.class, LocalItemCollection.class})
+public class ContributionCollectionImpl implements ItemCollection, LocalItemCollection {
private static final Logger logger = Logger.getLogger(ContributionCollectionImpl.class.getName());
@@ -111,6 +112,9 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl
@Reference
public DomainManagerConfiguration domainManagerConfiguration;
+ @Reference
+ public DomainSearch domainSearch;
+
private Monitor monitor;
private ContributionFactory contributionFactory;
private WorkspaceFactory workspaceFactory;
@@ -256,6 +260,7 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl
// Write the workspace
writeWorkspace(workspace);
return;
+
}
}
throw new NotFoundException(key);
@@ -479,7 +484,6 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl
private static String title(String contributionURI) {
return contributionURI;
}
-
/**
* Read the workspace.
@@ -652,9 +656,5 @@ 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/ContributionsReader.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionsReader.java
new file mode 100644
index 0000000000..b679f594e6
--- /dev/null
+++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionsReader.java
@@ -0,0 +1,9 @@
+package org.apache.tuscany.sca.domain.manager.impl;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+
+public interface ContributionsReader {
+
+ Contribution[] readContributions();
+
+}
diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeCollectionImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeCollectionImpl.java
index 3dac9b535e..63af213fbb 100644
--- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeCollectionImpl.java
+++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeCollectionImpl.java
@@ -33,6 +33,7 @@ import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
@@ -54,10 +55,8 @@ import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
import org.apache.tuscany.sca.contribution.service.ContributionReadException;
-import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.data.collection.Entry;
@@ -78,331 +77,405 @@ import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;
/**
- * Implementation of a deployable composite collection service.
- *
+ * Implementation of a deployable composite collection service.
+ *
* @version $Rev$ $Date$
*/
@Scope("COMPOSITE")
-@Service(interfaces={ItemCollection.class, LocalItemCollection.class})
-public class DeployableCompositeCollectionImpl implements ItemCollection, LocalItemCollection {
-
- private static final Logger logger = Logger.getLogger(DeployableCompositeCollectionImpl.class.getName());
-
- @Reference
- public LocalItemCollection contributionCollection;
-
- @Reference
- public DomainManagerConfiguration domainManagerConfiguration;
-
- private ModelFactoryExtensionPoint modelFactories;
- private ModelResolverExtensionPoint modelResolvers;
- private URLArtifactProcessor<Contribution> contributionProcessor;
- private XMLOutputFactory outputFactory;
- private ContributionDependencyBuilder contributionDependencyBuilder;
- private Monitor monitor;
-
- /**
- * Cache contribution models.
- */
- static class Cache {
- static class ContributionCache {
- private Contribution contribution;
- private long contributionLastModified;
- }
- private Map<URL, ContributionCache> contributions = new HashMap<URL, ContributionCache>();
- }
-
- private Cache cache = new Cache();
-
- /**
- * Initialize the component.
- */
- @Init
- public void initialize() throws ParserConfigurationException {
-
- ExtensionPointRegistry extensionPoints = domainManagerConfiguration.getExtensionPoints();
-
- // Create a monitor
- UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
- monitor = monitorFactory.createMonitor();
-
- // Get model factories
- modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
- XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
- outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
- outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
-
- // Get and initialize artifact processors
- StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- StAXArtifactProcessor<Object> staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor);
-
- URLArtifactProcessorExtensionPoint urlProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
- URLArtifactProcessor<Object> urlProcessor = new ExtensibleURLArtifactProcessor(urlProcessors, monitor);
-
- // Create contribution processor
- modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
- contributionProcessor = new ContributionContentProcessor(extensionPoints, monitor);
-
- // Create contribution and composite builders
- contributionDependencyBuilder = new ContributionDependencyBuilderImpl(monitor);
- }
-
- public Entry<String, Item>[] getAll() {
- logger.fine("getAll");
-
- // Return all the deployable composites in the contributions
- List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>();
-
- // Get the list of contributions in the workspace
- Entry<String, Item>[] contributionEntries = contributionCollection.getAll();
-
- // Read contribution metadata
- for (Entry<String, Item> contributionEntry: contributionEntries) {
- Item contributionItem = contributionEntry.getData();
- Contribution contribution;
- try {
- contribution = contribution(contributionEntry.getKey(), contributionItem.getAlternate());
- } catch (ContributionReadException e) {
- continue;
- }
-
- // Create entries for the deployable composites
- for (Composite deployable: contribution.getDeployables()) {
- entries.add(entry(contribution, deployable));
- }
-
- }
- return entries.toArray(new Entry[entries.size()]);
- }
-
- public Item get(String key) throws NotFoundException {
- logger.fine("get " + key);
-
- // Get the specified contribution info
- String contributionURI = contributionURI(key);
- Item contributionItem = contributionCollection.get(contributionURI);
-
- // Read the contribution
- Contribution contribution;
- try {
- contribution = contribution(contributionURI, contributionItem.getAlternate());
- } catch (ContributionReadException e) {
- throw new NotFoundException(key);
- }
-
- // Find the specified deployable composite
- QName qname = compositeQName(key);
- for (Composite deployable: contribution.getDeployables()) {
- if (qname.equals(deployable.getName())) {
- // find the deployable composite
- deployable = contribution.getModelResolver().resolveModel(Composite.class, deployable);
-
- if (deployable.isUnresolved()) {
- throw new NotFoundException(key);
- }
-
- // Return an item describing the deployable composite
- return item(contribution, deployable);
- }
- }
-
- throw new NotFoundException(key);
- }
-
- public String post(String key, Item item) {
- throw new UnsupportedOperationException();
- }
-
- public void put(String key, Item item) throws NotFoundException {
- throw new UnsupportedOperationException();
- }
-
- public void delete(String key) throws NotFoundException {
- throw new UnsupportedOperationException();
- }
-
- public Entry<String, Item>[] query(String queryString) {
- logger.fine("query " + queryString);
-
- if (queryString.startsWith("contribution=")) {
-
- // Return all the deployable composites in the specified
- // contribution
- List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>();
-
- // Get the specified contribution info
- String contributionURI = queryString.substring(queryString.indexOf('=') + 1);
- Item contributionItem;
- try {
- contributionItem = contributionCollection.get(contributionURI);
- } catch (NotFoundException e) {
- return entries.toArray(new Entry[entries.size()]);
- }
-
- // Read the contribution
- Contribution contribution;
- try {
- contribution = contribution(contributionURI, contributionItem.getAlternate());
- } catch (ContributionReadException e) {
- return entries.toArray(new Entry[entries.size()]);
- }
-
- // Create entries for the deployable composites
- for (Composite deployable: contribution.getDeployables()) {
- entries.add(entry(contribution, deployable));
- }
-
- return entries.toArray(new Entry[entries.size()]);
-
- } else {
- throw new UnsupportedOperationException();
- }
- }
-
- /**
- * Returns the contribution with the given URI.
- *
- * @param contributionURI
- * @param contributionLocation
- * @return
- * @throws NotFoundException
- */
- private Contribution contribution(String contributionURI, String contributionLocation) throws ContributionReadException {
- try {
- URI uri = URI.create(contributionURI);
- URL location = locationURL(contributionLocation);
-
- // Get contribution from cache
- ContributionCache contributionCache = cache.contributions.get(location);
- long lastModified = lastModified(location);
- if (contributionCache != null) {
- if (contributionCache.contributionLastModified == lastModified) {
- return contributionCache.contribution;
- }
-
- // Reset contribution cache
- cache.contributions.remove(location);
- }
-
- Contribution contribution = (Contribution)contributionProcessor.read(null, uri, location);
-
- // TODO - analyse dependencies here?
-
- //contributionProcessor.resolve(contribution, new DefaultModelResolver());
-
- // Cache contribution
- contributionCache = new ContributionCache();
- contributionCache.contribution = contribution;
- contributionCache.contributionLastModified = lastModified;
- cache.contributions.put(location, contributionCache);
-
- return contribution;
-
- } catch (ContributionReadException e) {
- throw e;
- } catch (MalformedURLException e) {
- throw new ContributionReadException(e);
- // } catch (ContributionResolveException e) {
- // throw new ContributionReadException(e);
- } catch (Throwable e) {
- throw new ContributionReadException(e);
- }
- }
-
- /**
- * Returns the entry contents describing a composite.
- *
- * @param composite
- * @return
- */
- private static String content(Composite composite) {
- StringBuffer sb = new StringBuffer();
- List<Component> components = composite.getComponents();
- for (int i = 0, n = components.size(); i < n; i++) {
- Component component = components.get(i);
- if (component.getImplementation() instanceof NodeImplementation) {
- List<ComponentService> services = component.getServices();
- if (!services.isEmpty()) {
- List<Binding> bindings = services.get(0).getBindings();
- if (!bindings.isEmpty()) {
-
- // List node URIs
- sb.append("Node URI: <span id=\"nodeURI\">");
- sb.append(component.getServices().get(0).getBindings().get(0).getURI());
- break;
- }
- }
- } else {
-
- // List component names
- if (sb.length() == 0) {
- sb.append("Components: <span id=\"components\">");
- } else {
- sb.append(" ");
- }
- sb.append(component.getName());
- }
- }
- if (sb.length() != 0) {
- sb.append("</span>");
- }
- return sb.toString();
- }
-
- /**
- * Returns the link to the resource related to a composite.
- *
- * @param composite
- * @return
- */
- private static String relatedLink(Composite composite) {
- for (Component component: composite.getComponents()) {
- if (component.getImplementation() instanceof NodeImplementation) {
- NodeImplementation nodeImplementation = (NodeImplementation)component.getImplementation();
- Composite deployable = nodeImplementation.getComposite();
- String contributionURI = deployable.getURI();
- QName qname = deployable.getName();
- String key = compositeKey(contributionURI, qname);
- return "/composite-source/" + key;
- }
- }
- return null;
- }
-
- /**
- * Returns an entry describing the given deployable.
- *
- * @param contribution
- * @param deployable
- * @return
- */
- private static Entry<String, Item> entry(Contribution contribution, Composite deployable) {
- Entry<String, Item> entry = new Entry<String, Item>();
- entry.setKey(DomainManagerUtil.compositeKey(contribution.getURI(), deployable.getName()));
- entry.setData(item(contribution, deployable));
- return entry;
- }
-
- /**
- * Returns an item describing the given deployable.
- *
- * @param contribution
- * @param deployable
- * @return
- */
- private static Item item(Contribution contribution, Composite deployable) {
- String contributionURI = contribution.getURI();
- String contributionLocation = contribution.getLocation();
- QName qname = deployable.getName();
- String deployableURI = deployable.getURI();
- Item item = new Item();
- item.setTitle(compositeTitle(contributionURI, qname));
- item.setContents(content(deployable));
- item.setLink(compositeSourceLink(contributionURI, qname));
- item.setAlternate(compositeAlternateLink(contributionLocation, deployableURI));
- item.setRelated(relatedLink(deployable));
- return item;
- }
+@Service(interfaces = { ItemCollection.class, LocalItemCollection.class, ContributionsReader.class })
+public class DeployableCompositeCollectionImpl implements ItemCollection,
+ LocalItemCollection, ContributionsReader {
+
+ private static final Logger logger = Logger
+ .getLogger(DeployableCompositeCollectionImpl.class.getName());
+
+ @Reference
+ public LocalItemCollection contributionCollection;
+
+ @Reference
+ public DomainManagerConfiguration domainManagerConfiguration;
+
+ private ModelFactoryExtensionPoint modelFactories;
+ private ModelResolverExtensionPoint modelResolvers;
+ private URLArtifactProcessor<Contribution> contributionProcessor;
+ private XMLOutputFactory outputFactory;
+ private ContributionDependencyBuilder contributionDependencyBuilder;
+ private Monitor monitor;
+
+ /**
+ * Cache contribution models.
+ */
+ static class Cache {
+ static class ContributionCache {
+ private Contribution contribution;
+ private long contributionLastModified;
+ }
+
+ private Map<URL, ContributionCache> contributions = new HashMap<URL, ContributionCache>();
+ }
+
+ private Cache cache = new Cache();
+
+ /**
+ * Initialize the component.
+ */
+ @Init
+ public void initialize() throws ParserConfigurationException {
+
+ ExtensionPointRegistry extensionPoints = domainManagerConfiguration
+ .getExtensionPoints();
+
+ // Create a monitor
+ UtilityExtensionPoint utilities = extensionPoints
+ .getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities
+ .getUtility(MonitorFactory.class);
+ monitor = monitorFactory.createMonitor();
+
+ // Get model factories
+ modelFactories = extensionPoints
+ .getExtensionPoint(ModelFactoryExtensionPoint.class);
+ XMLInputFactory inputFactory = modelFactories
+ .getFactory(XMLInputFactory.class);
+ outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+ outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
+ true);
+
+ // Get and initialize artifact processors
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints
+ .getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ StAXArtifactProcessor<Object> staxProcessor = new ExtensibleStAXArtifactProcessor(
+ staxProcessors, inputFactory, outputFactory, monitor);
+
+ URLArtifactProcessorExtensionPoint urlProcessors = extensionPoints
+ .getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ URLArtifactProcessor<Object> urlProcessor = new ExtensibleURLArtifactProcessor(
+ urlProcessors, monitor);
+
+ // Create contribution processor
+ modelResolvers = extensionPoints
+ .getExtensionPoint(ModelResolverExtensionPoint.class);
+ contributionProcessor = new ContributionContentProcessor(
+ extensionPoints, monitor);
+
+ // Create contribution and composite builders
+ contributionDependencyBuilder = new ContributionDependencyBuilderImpl(
+ monitor);
+ }
+
+ public Entry<String, Item>[] getAll() {
+ logger.fine("getAll");
+
+ // Return all the deployable composites in the contributions
+ List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>();
+
+ // Get the list of contributions in the workspace
+ Entry<String, Item>[] contributionEntries = contributionCollection
+ .getAll();
+
+ // Read contribution metadata
+ for (Entry<String, Item> contributionEntry : contributionEntries) {
+ Item contributionItem = contributionEntry.getData();
+ Contribution contribution;
+ try {
+ contribution = contribution(contributionEntry.getKey(),
+ contributionItem.getAlternate());
+ } catch (ContributionReadException e) {
+ continue;
+ }
+
+ // Create entries for the deployable composites
+ for (Composite deployable : contribution.getDeployables()) {
+ entries.add(entry(contribution, deployable));
+ }
+
+ }
+ return entries.toArray(new Entry[entries.size()]);
+ }
+
+ public Contribution[] readContributions() {
+
+ // Get the list of contributions in the workspace
+ Entry<String, Item>[] contributionEntries = contributionCollection
+ .getAll();
+
+ LinkedList<Contribution> contributions = new LinkedList<Contribution>();
+
+ // Read contribution metadata
+ for (Entry<String, Item> contributionEntry : contributionEntries) {
+ Item contributionItem = contributionEntry.getData();
+ Contribution contribution;
+ try {
+ contribution = contribution(contributionEntry.getKey(),
+ contributionItem.getAlternate());
+
+ } catch (ContributionReadException e) {
+ continue;
+ }
+
+ LinkedList<Composite> resolvedComposites = new LinkedList<Composite>();
+
+ for (Composite composite : contribution.getDeployables()) {
+
+ // find the deployable composite
+ composite = contribution.getModelResolver().resolveModel(
+ Composite.class, composite);
+
+ resolvedComposites.add(composite);
+
+ }
+
+ contribution.getDeployables().clear();
+ contribution.getDeployables().addAll(resolvedComposites);
+
+ contributions.add(contribution);
+
+ }
+
+ return contributions.toArray(new Contribution[0]);
+
+ }
+
+ public Item get(String key) throws NotFoundException {
+ logger.fine("get " + key);
+
+ // Get the specified contribution info
+ String contributionURI = contributionURI(key);
+ Item contributionItem = contributionCollection.get(contributionURI);
+
+ // Read the contribution
+ Contribution contribution;
+ try {
+ contribution = contribution(contributionURI, contributionItem
+ .getAlternate());
+ } catch (ContributionReadException e) {
+ throw new NotFoundException(key);
+ }
+
+ // Find the specified deployable composite
+ QName qname = compositeQName(key);
+ for (Composite deployable : contribution.getDeployables()) {
+ if (qname.equals(deployable.getName())) {
+ // find the deployable composite
+ deployable = contribution.getModelResolver().resolveModel(
+ Composite.class, deployable);
+
+ if (deployable.isUnresolved()) {
+ throw new NotFoundException(key);
+ }
+
+ // Return an item describing the deployable composite
+ return item(contribution, deployable);
+ }
+ }
+
+ throw new NotFoundException(key);
+ }
+
+ public String post(String key, Item item) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void put(String key, Item item) throws NotFoundException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void delete(String key) throws NotFoundException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Entry<String, Item>[] query(String queryString) {
+ logger.fine("query " + queryString);
+
+ if (queryString.startsWith("contribution=")) {
+
+ // Return all the deployable composites in the specified
+ // contribution
+ List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>();
+
+ // Get the specified contribution info
+ String contributionURI = queryString.substring(queryString
+ .indexOf('=') + 1);
+ Item contributionItem;
+ try {
+ contributionItem = contributionCollection.get(contributionURI);
+ } catch (NotFoundException e) {
+ return entries.toArray(new Entry[entries.size()]);
+ }
+
+ // Read the contribution
+ Contribution contribution;
+ try {
+ contribution = contribution(contributionURI, contributionItem
+ .getAlternate());
+ } catch (ContributionReadException e) {
+ return entries.toArray(new Entry[entries.size()]);
+ }
+
+ // Create entries for the deployable composites
+ for (Composite deployable : contribution.getDeployables()) {
+ entries.add(entry(contribution, deployable));
+ }
+
+ return entries.toArray(new Entry[entries.size()]);
+
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ /**
+ * Returns the contribution with the given URI.
+ *
+ * @param contributionURI
+ * @param contributionLocation
+ * @return
+ * @throws NotFoundException
+ */
+ private Contribution contribution(String contributionURI,
+ String contributionLocation) throws ContributionReadException {
+ try {
+ URI uri = URI.create(contributionURI);
+ URL location = locationURL(contributionLocation);
+
+ // Get contribution from cache
+ ContributionCache contributionCache = cache.contributions
+ .get(location);
+ long lastModified = lastModified(location);
+ if (contributionCache != null) {
+ if (contributionCache.contributionLastModified == lastModified) {
+ return contributionCache.contribution;
+ }
+
+ // Reset contribution cache
+ cache.contributions.remove(location);
+ }
+
+ Contribution contribution = (Contribution) contributionProcessor
+ .read(null, uri, location);
+
+ // TODO - analyse dependencies here?
+
+ // contributionProcessor.resolve(contribution, new
+ // DefaultModelResolver());
+
+ // Cache contribution
+ contributionCache = new ContributionCache();
+ contributionCache.contribution = contribution;
+ contributionCache.contributionLastModified = lastModified;
+ cache.contributions.put(location, contributionCache);
+
+ return contribution;
+
+ } catch (ContributionReadException e) {
+ throw e;
+ } catch (MalformedURLException e) {
+ throw new ContributionReadException(e);
+ // } catch (ContributionResolveException e) {
+ // throw new ContributionReadException(e);
+ } catch (Throwable e) {
+ throw new ContributionReadException(e);
+ }
+ }
+
+ /**
+ * Returns the entry contents describing a composite.
+ *
+ * @param composite
+ * @return
+ */
+ private static String content(Composite composite) {
+ StringBuffer sb = new StringBuffer();
+ List<Component> components = composite.getComponents();
+ for (int i = 0, n = components.size(); i < n; i++) {
+ Component component = components.get(i);
+ if (component.getImplementation() instanceof NodeImplementation) {
+ List<ComponentService> services = component.getServices();
+ if (!services.isEmpty()) {
+ List<Binding> bindings = services.get(0).getBindings();
+ if (!bindings.isEmpty()) {
+
+ // List node URIs
+ sb.append("Node URI: <span id=\"nodeURI\">");
+ sb.append(component.getServices().get(0).getBindings()
+ .get(0).getURI());
+ break;
+ }
+ }
+ } else {
+
+ // List component names
+ if (sb.length() == 0) {
+ sb.append("Components: <span id=\"components\">");
+ } else {
+ sb.append(" ");
+ }
+ sb.append(component.getName());
+ }
+ }
+ if (sb.length() != 0) {
+ sb.append("</span>");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns the link to the resource related to a composite.
+ *
+ * @param composite
+ * @return
+ */
+ private static String relatedLink(Composite composite) {
+ for (Component component : composite.getComponents()) {
+ if (component.getImplementation() instanceof NodeImplementation) {
+ NodeImplementation nodeImplementation = (NodeImplementation) component
+ .getImplementation();
+ Composite deployable = nodeImplementation.getComposite();
+ String contributionURI = deployable.getURI();
+ QName qname = deployable.getName();
+ String key = compositeKey(contributionURI, qname);
+ return "/composite-source/" + key;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns an entry describing the given deployable.
+ *
+ * @param contribution
+ * @param deployable
+ * @return
+ */
+ private static Entry<String, Item> entry(Contribution contribution,
+ Composite deployable) {
+ Entry<String, Item> entry = new Entry<String, Item>();
+ entry.setKey(DomainManagerUtil.compositeKey(contribution.getURI(),
+ deployable.getName()));
+ entry.setData(item(contribution, deployable));
+ return entry;
+ }
+
+ /**
+ * Returns an item describing the given deployable.
+ *
+ * @param contribution
+ * @param deployable
+ * @return
+ */
+ private static Item item(Contribution contribution, Composite deployable) {
+ String contributionURI = contribution.getURI();
+ String contributionLocation = contribution.getLocation();
+ QName qname = deployable.getName();
+ String deployableURI = deployable.getURI();
+ Item item = new Item();
+ item.setTitle(compositeTitle(contributionURI, qname));
+ item.setContents(content(deployable));
+ item.setLink(compositeSourceLink(contributionURI, qname));
+ item.setAlternate(compositeAlternateLink(contributionLocation,
+ deployableURI));
+ item.setRelated(relatedLink(deployable));
+ return item;
+ }
}
diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/FileServiceImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/FileServiceImpl.java
index 2adb623876..1493b73248 100644
--- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/FileServiceImpl.java
+++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/FileServiceImpl.java
@@ -39,6 +39,9 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.tuscany.sca.data.collection.Item;
+import org.apache.tuscany.sca.data.collection.LocalItemCollection;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Reference;
@@ -47,107 +50,161 @@ import org.osoa.sca.annotations.Service;
/**
* Implementation of a servlet component supporting file upload/download.
- *
+ *
* @version $Rev$ $Date$
*/
@Scope("COMPOSITE")
@Service(Servlet.class)
public class FileServiceImpl extends HttpServlet {
- private static final long serialVersionUID = -4560385595481971616L;
-
- private static final Logger logger = Logger.getLogger(FileServiceImpl.class.getName());
-
- @Property
- public String directoryName;
-
- @Reference
- public DomainManagerConfiguration domainManagerConfiguration;
-
- private ServletFileUpload upload;
-
- /**
- * Initialize the component.
- */
- @Init
- public void initialize() throws IOException {
- upload = new ServletFileUpload(new DiskFileItemFactory());
- }
-
- @Override
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
-
- // Upload files
- String rootDirectory = domainManagerConfiguration.getRootDirectory();
- try {
- for (FileItem item: (List<FileItem>)upload.parseRequest(request)) {
- if (!item.isFormField()) {
- File directory = new File(rootDirectory + "/" + directoryName);
- if (!directory.exists()) {
- directory.mkdirs();
- }
- logger.fine("post " + item.getName());
- item.write(new File(directory, item.getName()));
- }
- }
-
- // Redirect to the admin page
- response.sendRedirect("/ui/files");
- }
- catch (Exception e) {
- throw new IOException(e.toString());
- }
- }
-
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-
- // Download a file
- String requestURI = URLDecoder.decode(request.getRequestURI(), "UTF-8");
- String path = requestURI.substring(request.getServletPath().length());
- if (path.startsWith("/")) {
- path = path.substring(1);
- }
- logger.fine("get " + path);
-
- try {
-
- // Analyze the given path
- URI uri = URI.create(path);
- String scheme = uri.getScheme();
- if (scheme == null) {
-
- // If no scheme is specified then the path identifies file
- // inside our directory
- String rootDirectory = domainManagerConfiguration.getRootDirectory();
- uri = new File(rootDirectory + "/" + directoryName, path).toURI();
-
- } else if (!scheme.equals("file")) {
-
- // If the scheme does not identify a local file, just redirect to the server
- // hosting the file
- response.sendRedirect(path);
- }
-
- // Read the file and write to response
- URLConnection connection = uri.toURL().openConnection();
- connection.setUseCaches(false);
- connection.connect();
- InputStream is = connection.getInputStream();
- ServletOutputStream os = response.getOutputStream();
- byte[] buffer = new byte[4096];
- for (;;) {
- int n = is.read(buffer);
- if (n < 0) {
- break;
- }
- os.write(buffer, 0, n);
- }
- is.close();
- os.flush();
-
- } catch (FileNotFoundException e) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- }
- }
-
+ private static final long serialVersionUID = -4560385595481971616L;
+
+ private static final Logger logger = Logger.getLogger(FileServiceImpl.class
+ .getName());
+
+ @Property
+ public String directoryName;
+
+ @Reference
+ public DomainManagerConfiguration domainManagerConfiguration;
+
+ @Reference
+ public LocalItemCollection contributionCollection;
+
+ private ServletFileUpload upload;
+
+ /**
+ * Initialize the component.
+ */
+ @Init
+ public void initialize() throws IOException {
+ upload = new ServletFileUpload(new DiskFileItemFactory());
+ }
+
+ @Override
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+
+ // Upload files
+ String rootDirectory = domainManagerConfiguration.getRootDirectory();
+ try {
+ for (FileItem item : (List<FileItem>) upload.parseRequest(request)) {
+ if (!item.isFormField()) {
+ File directory = new File(rootDirectory + "/"
+ + directoryName);
+ if (!directory.exists()) {
+ directory.mkdirs();
+ }
+ logger.fine("post " + item.getName());
+ item.write(new File(directory, item.getName()));
+ }
+ }
+
+ // Redirect to the admin page
+ response.sendRedirect("/ui/files");
+ } catch (Exception e) {
+ throw new IOException(e.toString());
+ }
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
+
+ // Download a file
+ String requestURI = URLDecoder.decode(request.getRequestURI(), "UTF-8");
+ String path = requestURI.substring(request.getServletPath().length());
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+ logger.fine("get " + path);
+
+ try {
+
+ // Analyze the given path
+ String artifactURI;
+ if (path.startsWith("contribution=")) {
+ int semicolonIndex = path.indexOf(';');
+ String contributionName = path.substring("contribution="
+ .length(), semicolonIndex);
+ artifactURI = path.substring(semicolonIndex + 1);
+
+ try {
+ Item item = this.contributionCollection
+ .get(contributionName);
+
+ if (item == null) {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
+
+ return;
+
+ }
+
+ path = item.getAlternate();
+
+ } catch (NotFoundException e) {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
+
+ return;
+
+ }
+
+ if (path.endsWith(".jar") || path.endsWith(".zip")) {
+ path = "jar:" + (path.startsWith("file:") ? "" : "file:") + path + '!' + (artifactURI.startsWith("/") ? "" : "/") + artifactURI;
+
+ } else {
+ path += (path.endsWith("/") ? "" : "/") + artifactURI;
+ }
+
+ } else {
+ artifactURI = null;
+ }
+
+ URI uri = URI.create(path);
+ String scheme = uri.getScheme();
+ if (scheme == null) {
+
+ if (artifactURI != null) {
+ uri = URI.create("file:" + uri.toString());
+
+ } else {
+
+ // If no scheme is specified then the path identifies file
+ // inside our directory
+ String rootDirectory = domainManagerConfiguration
+ .getRootDirectory();
+ uri = new File(rootDirectory + "/" + directoryName, path)
+ .toURI();
+
+ }
+
+ } else if (!scheme.equals("file") && !scheme.equals("jar")) {
+
+ // If the scheme does not identify a local file, just redirect
+ // to the server
+ // hosting the file
+ response.sendRedirect(path);
+ }
+
+ // Read the file and write to response
+ URLConnection connection = uri.toURL().openConnection();
+ connection.setUseCaches(false);
+ connection.connect();
+ InputStream is = connection.getInputStream();
+ ServletOutputStream os = response.getOutputStream();
+ byte[] buffer = new byte[4096];
+ for (;;) {
+ int n = is.read(buffer);
+ if (n < 0) {
+ break;
+ }
+ os.write(buffer, 0, n);
+ }
+ is.close();
+ os.flush();
+
+ } catch (FileNotFoundException e) {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
+ }
+ }
+
}
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 5a2873b35f..0fb1812975 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
@@ -2,10 +2,12 @@ package org.apache.tuscany.sca.domain.manager.impl;
import java.io.IOException;
import java.io.StringWriter;
+import java.io.Writer;
import java.util.Arrays;
-import java.util.Collection;
+import java.util.Map;
import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.data.collection.Entry;
import org.apache.tuscany.sca.data.collection.Item;
import org.apache.tuscany.sca.data.collection.ItemCollection;
@@ -13,9 +15,9 @@ 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.DomainSearchFormatter;
import org.apache.tuscany.sca.domain.search.impl.HighlightingUtil;
+import org.apache.tuscany.sca.domain.search.impl.SearchFields;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;
@@ -25,20 +27,29 @@ import org.osoa.sca.annotations.Service;
public class Searcher implements ItemCollection, LocalItemCollection {
static char[] characters = { '\u0001'/*  */, '\u0003'/*  */,
- '\u0004'/*  */,
-
- };
+ '\u0004'/*  */, };
final private static String HTML_NEW_LINE = "<BR/>";
final private static String PATH_SEPARATOR = "/";
+ final private static int MAX_CONTENT_LINE_WIDTH = 300;
+
+ final private static String HIGHLIGHT_START = "<font color='#FF0000'>";
+
+ final private static String HIGHLIGHT_END = "</font>";
+
@Reference
- public WorkspaceReader contributionCollection;
+ public ContributionsReader contributionReader;
+
+ @Reference
+ public LocalItemCollection contributionCollection;
@Reference
public DomainSearch domainSearch;
+ private int elementCounter;
+
public void delete(String key) throws NotFoundException {
System.out.println("delete");
}
@@ -56,35 +67,159 @@ public class Searcher implements ItemCollection, LocalItemCollection {
}
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);
+
+ try {
+
+ if (key.startsWith("highlight")) {
+ int lastSemicolonIndex = key.lastIndexOf(";");
+ String artifact = key.substring(lastSemicolonIndex + 1);
+ int secondLastSemicolonIndex = key.lastIndexOf(";",
+ lastSemicolonIndex - 1);
+ String contribution = key.substring(
+ secondLastSemicolonIndex + 1, lastSemicolonIndex);
+ String query = key.substring("highlight".length(),
+ secondLastSemicolonIndex);
+
+ return highlightArtifact(contribution, artifact, query);
+
+ } else if (key.startsWith("query")) {
+ return executeQuery(key.substring("query".length()));
+
+ } else {
+ throw new NotFoundException("Invalid operation!");
+ }
+
+ } catch (Exception t) {
+
+ if (t instanceof NotFoundException) {
+ throw (NotFoundException) t;
+ }
+
+ throw new NotFoundException("Internal error!");
+
+ }
+
+ }
+
+ 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);
+ // }
+
+ return null;
+
+ }
+
+ private Item executeQuery(String query) throws NotFoundException {
+
+ if (!this.domainSearch.indexExists()) {
+
+ Contribution[] contributions = this.contributionReader
+ .readContributions();
+
+ for (Contribution contribution : contributions) {
+
+ if (!contribution.getURI().equals(
+ DomainManagerUtil.DEPLOYMENT_CONTRIBUTION_URI)) {
+
+ this.domainSearch.contributionUpdated(contribution,
+ contribution);
+
+ }
+
+ }
+
+ }
+
+ Result[] results;
+ try {
+ results = this.domainSearch.parseAndSearch(query, true);
+
+ } catch (Exception e1) {
+
+ throw new NotFoundException("Exception while searching: "
+ + e1.getMessage(), e1);
+
+ }
Item item = new Item();
item.setTitle("Results");
StringWriter sw = new StringWriter();
+ this.elementCounter = 0;
- for (Result result : results) {
+ if (results.length > 0) {
- try {
- writeToHTML(0, result, sw);
+ for (Result result : results) {
- } catch (IOException e) {
- // ignore result
- }
+ try {
+ writeToHTML(0, result, sw);
- sw.write(HTML_NEW_LINE);
+ } catch (IOException e) {
+ // ignore result
+ }
- }
+ }
+
+ String contents = HighlightingUtil.replaceHighlightMarkupBy(sw
+ .getBuffer(), HIGHLIGHT_START, HIGHLIGHT_END);
- String contents = HighlightingUtil.replaceHighlightMarkupBy(sw
- .getBuffer(), "<font color='#FF0000'>", "</font>");
+ item.setContents(replaceAll(contents, 40) + "end");
- item.setContents(replaceAll(contents, 40) + "end");
-
- System.out.println(item.getContents().indexOf("@Referencevar"));
+ } else {
+ item.setContents("No results match: <u>" + query + "</u>");
+ }
System.out.println(item.getContents());
@@ -148,7 +283,9 @@ public class Searcher implements ItemCollection, LocalItemCollection {
if (actual > less || actual == '&' || actual == '#'
|| actual == '\'' || actual == ' ' || actual == '%'
- || actual == ':') {
+ || actual == ':' || actual == '(' || actual == ')'
+ || actual == '"') {
+
sb.append(actual);
} else {
@@ -171,100 +308,168 @@ public class Searcher implements ItemCollection, LocalItemCollection {
}
- private static Result writeFileContentResultToHTML(int indentation,
- Result result, StringWriter writer) throws IOException {
+ private static String getIconLocationForResult(Result result) {
- String content = ((FileContentResult) result).getContent();
- writer.write("file:");
+ if (SearchFields.COMPONENT_FIELD.equals(result.getField())) {
+ return "icons/component.png' title='Component";
- if (content != null && content.length() > 0) {
+ } else if (SearchFields.COMPOSITE_FIELD.equals(result.getField())) {
+ return "icons/composite.png' title='Composite";
- StringEscapeUtils.escapeHtml(writer, result.getName());
- writer.write(HTML_NEW_LINE);
+ } else if (SearchFields.ARTIFACT_FIELD.equals(result.getField())) {
+ return "icons/artifact.png' title='Artifact";
+ }
- 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 "icons/feed-icon.png";
- } else {
+ }
- writer.write(result.getName());
- Collection<Result> contents = result.getContents().values();
+ private static void writeResultIcon(Writer writer, Result result)
+ throws IOException {
+ writer.write("<img src='");
+ writer.write(getIconLocationForResult(result));
+ writer.write("'/> ");
- while (contents.size() == 1) {
- result = contents.iterator().next();
+ }
- if (result instanceof FileContentResult) {
- writer.write(PATH_SEPARATOR);
- writer.write(result.getName());
+ private static Result writeFileContentResultToHTML(int indentation,
+ Result result, StringWriter writer) throws IOException {
- contents = result.getContents().values();
+ Map<String, Result> contents = result.getContents();
+ writeResultIcon(writer, result);
- } else {
- break;
- }
+ if (contents.size() == 1
+ && SearchFields.ARTIFACT_FIELD.equals(contents.values()
+ .iterator().next().getField())) {
- }
-
- if (result instanceof FileContentResult) {
- FileContentResult fileResult = (FileContentResult) result;
- content = fileResult.getContent();
+ writer.write(result.getValue());
+ contents = result.getContents();
- if (content != null && content.length() > 0) {
+ while (contents.size() == 1
+ && SearchFields.ARTIFACT_FIELD.equals(contents.values()
+ .iterator().next().getField())) {
- writer.write(HTML_NEW_LINE);
+ result = contents.values().iterator().next();
- startIndentation(indentation, writer);
- writer.write("<span style='max-width:100%'>");
- StringEscapeUtils.escapeHtml(writer, content);
- writer.write("</span>");
- endIndentation(writer);
- writer.write(HTML_NEW_LINE);
+ writer.write(PATH_SEPARATOR);
+ StringEscapeUtils.escapeHtml(writer, result.getValue());
- }
+ contents = result.getContents();
}
+ } else {
+ StringEscapeUtils.escapeHtml(writer, result.getValue());
}
-
+
return result;
}
- private static void writeToHTML(int indentation, Result result,
- StringWriter writer) throws IOException {
+ private static String removeHighlighting(String text) {
+ return HighlightingUtil.replaceHighlightMarkupBy(text, "", "");
+ }
- startIndentation(indentation++, writer);
+ private static void writeResultName(Result result, StringWriter writer)
+ throws IOException {
+
+ if (SearchFields.CONTRIBUTION_FIELD.equals(result.getField())) {
+ writer.write("<a href='/contribution/");
+ writer.write(removeHighlighting(result.getValue()));
+ writer.write("'>");
+ writer.write(StringEscapeUtils.escapeHtml(result.getValue()));
+ writer.write("</a>");
+
+ } else if (SearchFields.COMPOSITE_FIELD.equals(result.getField())) {
+ writer.write("<a href='/composite-source/composite:");
+ writer.write(getContributionURI(result));
+ writer.write(';');
+ writer.write(removeHighlighting(result.getValue()));
+ writer.write("'>");
+ writer.write(StringEscapeUtils.escapeHtml(result.getValue()));
+ writer.write("</a>");
- if (result instanceof FileContentResult) {
- result = writeFileContentResultToHTML(indentation, result, writer);
+ } else {
+ StringEscapeUtils.escapeHtml(writer, result.getValue());
+ }
+
+ }
+
+ private static String getContributionURI(Result result) {
+
+ if (result == null) {
+ return "";
+
+ } else if (SearchFields.CONTRIBUTION_FIELD.equals(result.getField())) {
+ return removeHighlighting(result.getValue());
} else {
+ return getContributionURI(result.getContainer());
+ }
+
+ }
+
+ private void writeToHTML(int indentation, Result result, StringWriter writer)
+ throws IOException {
- 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);
+ startIndentation(indentation++, writer);
+ String field = result.getField();
+
+ if (SearchFields.FILE_CONTENT_FIELD.equals(field)) {
+ String content = result.getValue();
+
+ if (content != null && content.length() > 0
+ && DomainSearchFormatter.isHighlighted(content)) {
+
+ writer.write(HTML_NEW_LINE);
+
+ this.elementCounter++;
+ writer.write("<div style='margin-top:0em;margin-left:");
+ writer.write(Integer.toString(indentation));
+ writer
+ .write("em;background-color:#FFE175;max-width:100%;border-style:dashed;border-width:1px;padding:5px'>"
+ + "<p style='margin:0px;padding:0px;font-size:70%'>"
+ + "<a style='margin:0px;padding:0px' href='#filecontent");
+
+ writer.write(Integer.toString(this.elementCounter));
+
+ String contributionPlusArtifact = getContributionURI(result)
+ + ";"
+ + removeHighlighting(result.getContainer().getValue());
+
+ // writer.write("' onclick='search");
+ // writer.write("'>view all</a>&nbsp;&nbsp;<a href='/files/contribution=");
+ writer.write("' onclick='getHighlighted(\"");
+ writer.write(contributionPlusArtifact);
+ writer
+ .write("\")'>view all</a>&nbsp;&nbsp;<a href='/files/contribution=");
+
+ writer.write(contributionPlusArtifact);
+ writer
+ .write("'>download</a></p><p style='margin:8px 0px 0px 0px;padding:0px'>");
+
+ int i = 0;
+ while (i < 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("</p></div>");
+
}
+ } else if (SearchFields.ARTIFACT_FIELD.equals(field)) {
+ result = writeFileContentResultToHTML(indentation, result, writer);
+
+ } else {
+
+ writeResultIcon(writer, result);
+ writeResultName(result, writer);
+
}
endIndentation(writer);
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
deleted file mode 100644
index d4cb1d21af..0000000000
--- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/WorkspaceReader.java
+++ /dev/null
@@ -1,9 +0,0 @@
-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 d9b0939517..3336d1eec6 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
@@ -128,6 +128,7 @@
<t:binding.atom uri="http://localhost:9990/workspace" title="Contributions"/>
</service>
<reference name="domainManagerConfiguration" target="DomainManagerConfigurationComponent"/>
+ <reference name="domainSearch" target="DomainSearchComponent"/>
</component>
<component name="ContributionServiceComponent">
@@ -154,6 +155,7 @@
<t:binding.http uri="http://localhost:9990/files"/>
</service>
<reference name="domainManagerConfiguration" target="DomainManagerConfigurationComponent"/>
+ <reference name="contributionCollection" target="ContributionCollectionComponent/LocalItemCollection"/>
</component>
<component name="DomainCompositeCollectionComponent">
@@ -274,7 +276,8 @@
</service>
<reference name="domainSearch" target="DomainSearchComponent"/>
- <reference name="contributionCollection" target="ContributionCollectionComponent/WorkspaceReader"/>
+ <reference name="contributionCollection" target="ContributionCollectionComponent/LocalItemCollection"/>
+ <reference name="contributionReader" target="DeployableCompositeCollectionComponent/ContributionsReader"/>
</component>
@@ -311,6 +314,7 @@
<component name="DomainSearchComponent">
<implementation.java class="org.apache.tuscany.sca.domain.search.impl.DomainSearchImpl"/>
+ <!--<property name="indexDirectoryPath">domainSearchIndex</property> -->
</component>
-
+
</composite>
diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/artifact.png b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/artifact.png
new file mode 100644
index 0000000000..dddbebd2bd
--- /dev/null
+++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/artifact.png
Binary files differ
diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/component.png b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/component.png
new file mode 100644
index 0000000000..7315475b3e
--- /dev/null
+++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/component.png
Binary files differ
diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/composite.png b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/composite.png
new file mode 100644
index 0000000000..3fa9d02549
--- /dev/null
+++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/icons/composite.png
Binary files differ
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 df68d9751d..f0c1ff4038 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
@@ -25,11 +25,39 @@
<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">
+<script type="text/javascript">
+ function search() {
+ lastQuery = elementByID(gadget, 'searchField').value;
+ searcher.get("query" + lastQuery, searchResponse);
+
+ }
+
+ function getHighlighted(artifact) {
+ searcher.get("highlight" + lastQuery + ";" + artifact, searchResponse);
+ }
+
+ function highlightResponse(feed) {
+ var entries = feed.getElementsByTagName("entry");
+ var content = entries[0].getElementsByTagName("content");
+
+ var results = elementByID(gadget, "results");
+ results.innerHTML = content[0].firstChild.data;
+
+ }
+
+ function searchResponse(feed) {
+ var entries = feed.getElementsByTagName("entry");
+ var content = entries[0].getElementsByTagName("content");
+
+ var results = elementByID(gadget, "results");
+ results.innerHTML = content[0].firstChild.data;
+
+ }
+
+</script>
</head>
@@ -53,28 +81,14 @@
</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;
-
- }
+ var lastQuery = "";
- elementByID(gadget, 'searchButton').onclick = search
+ elementByID(gadget, 'searchButton').onclick = search;
</script>
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java
index bc347d8cbe..e6329e5b71 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java
@@ -2,15 +2,18 @@ package org.apache.tuscany.sca.domain.search;
import org.apache.lucene.search.Query;
import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.service.ContributionRepository;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface DomainSearch {
- Result[] parseAndSearch(String searchQuery, boolean highlight);
+ boolean indexExists();
- Result[] search(Query searchQuery, boolean hightlight);
+ Result[] parseAndSearch(String searchQuery, boolean highlight) throws Exception;
+
+ Result[] search(Query searchQuery, boolean hightlight) throws Exception;
+
+ String highlight(String field, String text, String searchQuery) throws Exception;
/**
* Notifies the listener that a contribution has been added.
@@ -18,7 +21,7 @@ public interface DomainSearch {
* @param repository The contribution repository
* @param contribution The new contribution
*/
- void contributionAdded(ContributionRepository repository, Contribution contribution);
+ void contributionAdded(Contribution contribution);
/**
* Notifies the listener that a contribution has been removed.
@@ -26,7 +29,7 @@ public interface DomainSearch {
* @param repository The contribution repository
* @param contribution The removed contribution.
*/
- void contributionRemoved(ContributionRepository repository, Contribution contribution);
+ void contributionRemoved(Contribution contribution);
/**
* Notifies the listener that a contribution has been updated.
@@ -35,6 +38,6 @@ public interface DomainSearch {
* @param oldContribution The old contribution
* @param contribution The new contribution
*/
- void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution);
+ void contributionUpdated(Contribution oldContribution, Contribution contribution);
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java
index 9713b7e79d..ca5c7b86ae 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java
@@ -5,9 +5,9 @@ import java.util.Map;
public interface Result extends Serializable {
- String getName();
+ String getValue();
- void setName(String name);
+ void setValue(String value);
Result getContainer();
@@ -18,5 +18,9 @@ public interface Result extends Serializable {
void removeContent(Result artifactResult);
void setContainer(Result container);
+
+ String getField();
+
+ void setField(String field);
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java
index 073dda6c78..51409ab5ae 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java
@@ -4,11 +4,7 @@ import org.apache.lucene.document.Document;
public interface ResultFactory<T extends Result> {
- String getType();
-
- String getName(Document document);
-
- T createResult(String name);
+ T createResult(String field, String value);
T createResult(Document document);
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java
index 0a2935cde7..e557a45305 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java
@@ -1,10 +1,9 @@
package org.apache.tuscany.sca.domain.search;
import org.apache.lucene.document.Document;
-import org.apache.lucene.search.Query;
public interface ResultProcessor {
- Result process(Document document, Query query, Result result);
+ Result process(Document document, Result result);
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java
index ade97aaaeb..83dc2d10fd 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java
@@ -1,11 +1,11 @@
package org.apache.tuscany.sca.domain.search.impl;
-import java.io.File;
-import java.net.MalformedURLException;
+import java.io.IOException;
import java.net.URL;
import org.apache.lucene.document.Field;
import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.domain.search.DocumentMap;
import org.apache.tuscany.sca.domain.search.DocumentProcessor;
@@ -17,43 +17,68 @@ public class ArtifactDocumentProcessor implements DocumentProcessor {
if (object instanceof Artifact) {
Artifact artifact = (Artifact) object;
- String uri = artifact.getURI();
+ // String uri = artifact.getURI();
+
+ // if (uri != null && uri.length() == 0) {
+ // uri = null;
+ // }
+ //
+ // if (uri != null) {
+ //
+ // if (uri.endsWith(".composite")
+ // || uri.endsWith(".component")) {
+ //
+ // parent += DomainPathAnalyzer.PATH_SEPARATOR
+ // + SearchFields.ARTIFACT_FIELD
+ // + DomainPathAnalyzer.TYPE_SEPARATOR + uri;
+ //
+ // if (document == null) {
+ // document = documents.get(uri);
+ // }
+ //
+ // document.add(new Field(SearchFields.ARTIFACT_FIELD, uri,
+ // Field.Store.YES, Field.Index.ANALYZED));
+ //
+ // }
+ //
+ // }
+
+ if (!(object instanceof Contribution)) {
- if (uri != null && uri.length() == 0) {
- uri = null;
- }
+ String location = artifact.getLocation();
- if (uri != null) {
+ try {
- parent += DomainPathAnalyzer.PATH_SEPARATOR
- + SearchFields.ARTIFACT_FIELD
- + DomainPathAnalyzer.TYPE_SEPARATOR + uri;
+ if (document == null) {
+ document = documents.get(SearchFields.ARTIFACT_FIELD + location);
+ }
- if (document == null) {
- document = documents.get(uri);
- }
+ FileContent fileContent = new WrappedFileContent(new URL(
+ location));
- document.add(new Field(SearchFields.ARTIFACT_FIELD, uri,
- Field.Store.YES, Field.Index.ANALYZED));
+ document.add(new Field(SearchFields.ARTIFACT_FIELD,
+ fileContent.getName(), Field.Store.YES,
+ Field.Index.ANALYZED));
- }
+ parent += DomainPathAnalyzer.PATH_SEPARATOR
+ + SearchFields.ARTIFACT_FIELD
+ + DomainPathAnalyzer.TYPE_SEPARATOR
+ + location + DomainPathAnalyzer.URI_SEPARATOR
+ + fileContent.getName();
- if (document != null) {
+ // parent += DomainPathAnalyzer.PATH_SEPARATOR
+ // + SearchFields.FILE_FIELD
+ // + DomainPathAnalyzer.TYPE_SEPARATOR + location +
+ // DomainPathAnalyzer.URI_SEPARATOR + fileContent.getName();
- String location = artifact.getLocation();
-
- document.add(new Field(SearchFields.LOCATION_FIELD, location,
- Field.Store.YES, Field.Index.ANALYZED));
-
- try {
Document fileDoc = parentProcessor.process(parentProcessor,
- documents, new SystemFileContent(new File(new URL(location).getFile())), document, parent);
-
+ documents, fileContent, null, parent);
+
fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
Field.Store.YES, Field.Index.ANALYZED));
-
- } catch (MalformedURLException e) {
- // ignore file
+
+ } catch (IOException e) {
+ // ignore location
}
}
@@ -70,13 +95,13 @@ public class ArtifactDocumentProcessor implements DocumentProcessor {
if (obj instanceof Artifact) {
Artifact artifact = (Artifact) obj;
- String uri = artifact.getURI();
+ String uri = artifact.getLocation();
if (uri != null && uri.length() == 0) {
return null;
}
- return uri;
+ return SearchFields.ARTIFACT_FIELD + uri;
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResult.java
deleted file mode 100644
index ace9fde093..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResult.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-public class ArtifactResult extends ResultImpl {
-
- private static final long serialVersionUID = 7418036586148544103L;
-
- private String location;
-
- public ArtifactResult() {
- // empty constructor
- }
-
- public ArtifactResult(String name) {
- super(name);
- }
-
- public void setLocation(String location) {
- this.location = location;
- }
-
- public String getLocation() {
- return this.location;
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResultProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResultProcessor.java
deleted file mode 100644
index 700e823161..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResultProcessor.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-import org.apache.tuscany.sca.domain.search.Result;
-import org.apache.tuscany.sca.domain.search.ResultFactory;
-import org.apache.tuscany.sca.domain.search.ResultProcessor;
-
-import org.apache.lucene.document.Document;
-import org.apache.lucene.search.Query;
-
-public class ArtifactResultProcessor implements ResultProcessor {
-
- public Result process(Document document, Query query, Result result) {
-
- if (result instanceof ArtifactResult) {
- String location = document.get(SearchFields.LOCATION_FIELD);
- ((ArtifactResult) result).setLocation(location);
-
- }
-
- return result;
-
- }
-
- public static class ArtifactResultFactory implements ResultFactory<ArtifactResult> {
-
- public ArtifactResultFactory() {
- // empty constructor
- }
-
- public ArtifactResult createResult(String name) {
- return new ArtifactResult(name);
- }
-
- public String getName(Document document) {
- return document.get(SearchFields.ARTIFACT_FIELD);
- }
-
- public String getType() {
- return SearchFields.ARTIFACT_FIELD;
- }
-
- public ArtifactResult createResult(Document document) {
- String name = getName(document);
-
- if (name != null) {
- return createResult(name);
- }
-
- return null;
-
- }
-
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResult.java
deleted file mode 100644
index 7a2654f05b..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResult.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-public class BindingResult extends ResultImpl {
-
- private static final long serialVersionUID = 8393058630593239377L;
-
- public BindingResult(String name) {
- super(name);
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResultFactory.java
deleted file mode 100644
index f88548344f..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResultFactory.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-import org.apache.lucene.document.Document;
-import org.apache.tuscany.sca.domain.search.ResultFactory;
-
-public class BindingResultFactory implements ResultFactory<BindingResult> {
-
- public BindingResultFactory() {
- // empty constructor
- }
-
- public BindingResult createResult(String name) {
- return new BindingResult(name);
- }
-
- public String getType() {
- return SearchFields.BINDING_FIELD;
- }
-
- public String getName(Document document) {
- return document.get(getType());
- }
-
- public BindingResult createResult(Document document) {
- String name = getName(document);
-
- if (name != null) {
- return createResult(name);
- }
-
- return null;
-
-
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentDocumentProcessor.java
index ac7ffbe5b9..5057afeab4 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentDocumentProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentDocumentProcessor.java
@@ -5,6 +5,7 @@ import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.ComponentProperty;
import org.apache.tuscany.sca.assembly.ComponentReference;
import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.domain.search.DocumentMap;
import org.apache.tuscany.sca.domain.search.DocumentProcessor;
import org.apache.tuscany.sca.domain.search.Result;
@@ -32,12 +33,16 @@ public class ComponentDocumentProcessor implements DocumentProcessor {
if (doc == null) {
doc = documents.get(uri);
}
-
- parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPONENT_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri + DomainPathAnalyzer.URI_SEPARATOR + component.getName();
+
+ parent += DomainPathAnalyzer.PATH_SEPARATOR
+ + SearchFields.COMPONENT_FIELD
+ + DomainPathAnalyzer.TYPE_SEPARATOR + uri
+ + DomainPathAnalyzer.URI_SEPARATOR
+ + component.getName();
doc.add(new Field(SearchFields.COMPONENT_FIELD, uri,
Field.Store.YES, Field.Index.ANALYZED));
-
+
for (ComponentService service : component.getServices()) {
Document serviceDoc = documents.get(uri + ':'
+ service.getName());
@@ -84,8 +89,9 @@ public class ComponentDocumentProcessor implements DocumentProcessor {
Document referenceDoc = documents.get(uri + ':'
+ reference.getName());
- referenceDoc.add(new Field(SearchFields.REFERENCE_NAME_FIELD,
- reference.getName(), Field.Store.YES,
+ referenceDoc.add(new Field(
+ SearchFields.REFERENCE_NAME_FIELD, reference
+ .getName(), Field.Store.YES,
Field.Index.ANALYZED));
InterfaceContract interfaceContract = reference
@@ -117,31 +123,38 @@ public class ComponentDocumentProcessor implements DocumentProcessor {
}
- referenceDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
- Field.Store.YES, Field.Index.ANALYZED));
+ referenceDoc.add(new Field(SearchFields.PARENT_FIELD,
+ parent, Field.Store.YES, Field.Index.ANALYZED));
}
}
- Document implementationDoc = parentProcessor.process(parentProcessor,
- documents, component.getImplementation(), null, parent);
+ Document implementationDoc = parentProcessor.process(
+ parentProcessor, documents, component.getImplementation(),
+ null, parent);
if (uri != null && implementationDoc != null) {
- implementationDoc.add(new Field(SearchFields.PARENT_FIELD,
- uri, Field.Store.YES, Field.Index.ANALYZED));
-
+ implementationDoc.add(new Field(SearchFields.PARENT_FIELD, uri,
+ Field.Store.YES, Field.Index.ANALYZED));
+
}
for (ComponentProperty componentProperty : component
.getProperties()) {
- Document propertyDoc = parentProcessor.process(parentProcessor,
- documents, componentProperty.getProperty(), null, parent);
- if (uri != null) {
- propertyDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
- Field.Store.YES, Field.Index.ANALYZED));
+ Property property = componentProperty.getProperty();
+
+ if (property != null) {
+ Document propertyDoc = parentProcessor.process(
+ parentProcessor, documents, property, null, parent);
+
+ if (uri != null) {
+ propertyDoc.add(new Field(SearchFields.PARENT_FIELD,
+ parent, Field.Store.YES, Field.Index.ANALYZED));
+
+ }
}
@@ -176,17 +189,16 @@ public class ComponentDocumentProcessor implements DocumentProcessor {
}
- public Result processDocument(org.apache.lucene.document.Document document, Result result) {
+ public Result processDocument(org.apache.lucene.document.Document document,
+ Result result) {
String componentName = document.get(SearchFields.COMPONENT_FIELD);
-
+
if (componentName != null) {
-
-
-
+
}
-
+
return null;
-
+
}
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResult.java
deleted file mode 100644
index 012715a7ea..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResult.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-
-public class ComponentResult extends ResultImpl {
-
- private static final long serialVersionUID = -2171168107785499573L;
-
- public ComponentResult() {
- // empty constructor
- }
-
- public ComponentResult(String name) {
- super(name);
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResultFactory.java
deleted file mode 100644
index 61e734d725..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResultFactory.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-import org.apache.lucene.document.Document;
-import org.apache.tuscany.sca.domain.search.ResultFactory;
-
-public class ComponentResultFactory implements ResultFactory<ComponentResult> {
-
- public ComponentResultFactory() {
- // empty constructor
- }
-
- public ComponentResult createResult(String name) {
- return new ComponentResult(name);
- }
-
- public String getName(Document document) {
- return document.get(getType());
- }
-
- public String getType() {
- return SearchFields.COMPONENT_FIELD;
- }
-
- public ComponentResult createResult(Document document) {
- String name = getName(document);
-
- if (name != null) {
- return createResult(name);
- }
-
- return null;
-
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeDocumentProcessor.java
index 68453fcb0b..fdf4d935f2 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeDocumentProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeDocumentProcessor.java
@@ -7,6 +7,7 @@ import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.domain.search.DocumentMap;
import org.apache.tuscany.sca.domain.search.DocumentProcessor;
+import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
@@ -35,8 +36,10 @@ public class ComponentTypeDocumentProcessor implements DocumentProcessor {
}
if (uri != null) {
-
- parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPONENT_TYPE_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri;
+
+ parent += DomainPathAnalyzer.PATH_SEPARATOR
+ + SearchFields.COMPONENT_TYPE_FIELD
+ + DomainPathAnalyzer.TYPE_SEPARATOR + uri;
doc.add(new Field(SearchFields.COMPONENT_TYPE_FIELD, uri,
Field.Store.YES, Field.Index.ANALYZED));
@@ -54,25 +57,35 @@ public class ComponentTypeDocumentProcessor implements DocumentProcessor {
if (interfaceContract != null) {
- for (Operation operation : interfaceContract
- .getInterface().getOperations()) {
+ Interface interfac = interfaceContract.getInterface();
- serviceDoc.add(new Field(
- SearchFields.SERVICE_INTERFACE_FIELD,
- operation.getName(), Field.Store.YES,
- Field.Index.ANALYZED));
+ if (interfac != null) {
+
+ for (Operation operation : interfac.getOperations()) {
+
+ serviceDoc.add(new Field(
+ SearchFields.SERVICE_INTERFACE_FIELD,
+ operation.getName(), Field.Store.YES,
+ Field.Index.ANALYZED));
+
+ }
}
- for (Operation operation : interfaceContract
- .getCallbackInterface().getOperations()) {
+ interfac = interfaceContract.getCallbackInterface();
- serviceDoc
- .add(new Field(
- SearchFields.SERVICE_INTERFACE_CALLBACK_FIELD,
- operation.getName(),
- Field.Store.YES,
- Field.Index.ANALYZED));
+ if (interfac != null) {
+
+ for (Operation operation : interfac.getOperations()) {
+
+ serviceDoc
+ .add(new Field(
+ SearchFields.SERVICE_INTERFACE_CALLBACK_FIELD,
+ operation.getName(),
+ Field.Store.YES,
+ Field.Index.ANALYZED));
+
+ }
}
@@ -122,8 +135,8 @@ public class ComponentTypeDocumentProcessor implements DocumentProcessor {
}
- referenceDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
- Field.Store.YES, Field.Index.ANALYZED));
+ referenceDoc.add(new Field(SearchFields.PARENT_FIELD,
+ parent, Field.Store.YES, Field.Index.ANALYZED));
}
@@ -135,8 +148,8 @@ public class ComponentTypeDocumentProcessor implements DocumentProcessor {
if (uri != null) {
- propertyDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
- Field.Store.YES, Field.Index.ANALYZED));
+ propertyDoc.add(new Field(SearchFields.PARENT_FIELD,
+ parent, Field.Store.YES, Field.Index.ANALYZED));
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResult.java
deleted file mode 100644
index bc7112cf47..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResult.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-public class ComponentTypeResult extends ResultImpl {
-
- private static final long serialVersionUID = 3767144511814116732L;
-
- public ComponentTypeResult() {
- // empty constructor
- }
-
- public ComponentTypeResult(String name) {
- super(name);
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResultFactory.java
deleted file mode 100644
index d486870078..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResultFactory.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-import org.apache.lucene.document.Document;
-import org.apache.tuscany.sca.domain.search.ResultFactory;
-
-public class ComponentTypeResultFactory implements
- ResultFactory<ComponentTypeResult> {
-
- public ComponentTypeResultFactory() {
- // empty constructor
- }
-
- public String getName(Document document) {
- return document.get(getType());
- }
-
- public String getType() {
- return SearchFields.COMPONENT_TYPE_FIELD;
- }
-
- public ComponentTypeResult createResult(String name) {
- return new ComponentTypeResult(name);
- }
-
- public ComponentTypeResult createResult(Document document) {
- String name = getName(document);
-
- if (name != null) {
- return createResult(name);
- }
-
- return null;
-
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeDocumentProcessor.java
index f28d876d2e..79ac6e9958 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeDocumentProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeDocumentProcessor.java
@@ -15,11 +15,9 @@ public class CompositeDocumentProcessor implements DocumentProcessor {
if (object instanceof Composite) {
Composite composite = (Composite) object;
- String uri = composite.getURI();
QName name = composite.getName();
-
- uri = (uri == null ? "" : uri) + (name == null ? "" : name.toString());
-
+ String uri = (name == null ? "" : name.getNamespaceURI() + ';' + name.getLocalPart());
+
if (uri.length() == 0) {
uri = null;
@@ -28,7 +26,7 @@ public class CompositeDocumentProcessor implements DocumentProcessor {
}
if (uri != null) {
- parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPOSITE_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + composite.getURI() + DomainPathAnalyzer.URI_SEPARATOR + composite.getName();
+ parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPOSITE_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri;
}
for (Component component : composite.getComponents()) {
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResult.java
deleted file mode 100644
index 8dd96de288..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResult.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-public class CompositeResult extends ResultImpl {
-
- private static final long serialVersionUID = -4651241874173649592L;
-
- public CompositeResult() {
- // empty constructor
- }
-
- public CompositeResult(String name) {
- super(name);
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResultFactory.java
deleted file mode 100644
index 9b4acefc8c..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResultFactory.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-import org.apache.lucene.document.Document;
-import org.apache.tuscany.sca.domain.search.ResultFactory;
-
-public class CompositeResultFactory implements ResultFactory<CompositeResult> {
-
- public CompositeResultFactory() {
- // empty constructor
- }
-
- public CompositeResult createResult(String name) {
- return new CompositeResult(name);
- }
-
- public String getName(Document document) {
- return document.get(getType());
- }
-
- public String getType() {
- return SearchFields.COMPOSITE_FIELD;
- }
-
- public CompositeResult createResult(Document document) {
- String name = getName(document);
-
- if (name != null) {
- return createResult(name);
- }
-
- return null;
-
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java
index 615a84b6dc..706a026eaf 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java
@@ -7,7 +7,6 @@ import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.domain.search.DocumentMap;
import org.apache.tuscany.sca.domain.search.DocumentProcessor;
-import org.apache.tuscany.sca.domain.search.Result;
public class ContributionDocumentProcessor implements DocumentProcessor {
@@ -24,18 +23,21 @@ public class ContributionDocumentProcessor implements DocumentProcessor {
uri = null;
} else {
-
- parent += DomainPathAnalyzer.PATH_SEPARATOR
+
+ parent += Character.toString(DomainPathAnalyzer.PATH_START)
+ SearchFields.CONTRIBUTION_FIELD
+ DomainPathAnalyzer.TYPE_SEPARATOR + uri;
-
+
}
}
- if (uri != null && doc == null) {
- doc = documents.get(uri);
+ if (uri != null) {
+ if (doc == null) {
+ doc = documents.get(uri);
+ }
+
doc.add(new Field(SearchFields.CONTRIBUTION_FIELD, uri,
Field.Store.YES, Field.Index.ANALYZED));
@@ -85,8 +87,9 @@ public class ContributionDocumentProcessor implements DocumentProcessor {
if (!object.getClass().getSimpleName().contains("Workspace")) {
for (Composite composite : contribution.getDeployables()) {
- Document compositeDoc = parentProcessor.process(parentProcessor,
- documents, composite, null, parent);
+ Document compositeDoc = parentProcessor
+ .process(parentProcessor, documents, composite,
+ null, parent);
if (uri != null) {
@@ -125,25 +128,4 @@ public class ContributionDocumentProcessor implements DocumentProcessor {
}
- public Result processDocument(org.apache.lucene.document.Document document,
- Result result) {
- String contributionName = document.get(SearchFields.CONTRIBUTION_FIELD);
-
- if (contributionName != null) {
-
- if (result == null) {
- result = new ContributionResult(contributionName);
-
- } else if (!(result instanceof ContributionResult)) {
- throw new IllegalArgumentException();
- }
-
- result.setName(contributionName);
-
- }
-
- return result;
-
- }
-
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResult.java
deleted file mode 100644
index f4abc62319..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResult.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-public class ContributionResult extends ArtifactResult {
-
- private static final long serialVersionUID = 4508196828816188213L;
-
- public ContributionResult() {
- // empty constructor
- }
-
- public ContributionResult(String name) {
- super(name);
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResultFactory.java
deleted file mode 100644
index c2ac77ed43..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResultFactory.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-import org.apache.lucene.document.Document;
-import org.apache.tuscany.sca.domain.search.ResultFactory;
-
-public class ContributionResultFactory implements
- ResultFactory<ContributionResult> {
-
- public ContributionResultFactory() {
- // empty constructor
- }
-
- public ContributionResult createResult(String name) {
- return new ContributionResult(name);
- }
-
- public String getName(Document document) {
- return document.get(SearchFields.CONTRIBUTION_FIELD);
- }
-
- public String getType() {
- return SearchFields.CONTRIBUTION_FIELD;
- }
-
- public ContributionResult createResult(Document document) {
- String name = getName(document);
-
- if (name != null) {
- return createResult(name);
- }
-
- return null;
-
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileContent.java
new file mode 100644
index 0000000000..c1358327a9
--- /dev/null
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileContent.java
@@ -0,0 +1,35 @@
+package org.apache.tuscany.sca.domain.search.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public class DefaultFileContent implements FileContent {
+
+ final private URL url;
+
+ public DefaultFileContent(URL url) {
+ this.url = url;
+ }
+
+ public FileContent[] getChildren() {
+ return new FileContent[0];
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return this.url.openStream();
+ }
+
+ public String getName() {
+ return this.url.getFile();
+ }
+
+ public String getPath() {
+ return this.url.getPath();
+ }
+
+ public boolean isLeaf() {
+ return false;
+ }
+
+}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java
index d4a23693d4..ff58f2521f 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java
@@ -25,11 +25,12 @@ public class DefaultFileDocumentProcessor implements DocumentProcessor {
doc = documents.get(file.getPath());
}
- doc.add(new Field(SearchFields.FILE_FIELD, file.getName(), Field.Store.YES,
- Field.Index.ANALYZED));
-
doc.add(new Field(SearchFields.FILE_CONTENT_FIELD, reader));
+ doc.add(new Field(SearchFields.FILE_CONTENT_FIELD,
+ "", Field.Store.YES,
+ Field.Index.ANALYZED));
+
return doc;
} catch (IOException e) {
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DirectoryDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DirectoryDocumentProcessor.java
deleted file mode 100644
index b25e292322..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DirectoryDocumentProcessor.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-import java.io.File;
-
-import org.apache.lucene.document.Field;
-import org.apache.tuscany.sca.domain.search.DocumentMap;
-import org.apache.tuscany.sca.domain.search.DocumentProcessor;
-
-public class DirectoryDocumentProcessor implements DocumentProcessor {
-
- public Document process(DocumentProcessor parentProcessor,
- DocumentMap documents, Object object, Document doc, String parent) {
-
- if (object instanceof File) {
- File file = (File) object;
- doc = documents.get(file.getAbsoluteFile());
-
- if (file.isDirectory()) {
- doc.add(new Field(SearchFields.DIRECTORY_FIELD, file.getAbsolutePath(),
- Field.Store.YES, Field.Index.ANALYZED));
-
- parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.DIRECTORY_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + file.getName();
-
- File[] files = file.listFiles();
-
- for (File childFile : files) {
- Document fileDoc = parentProcessor.process(parentProcessor, documents, childFile, null, parent);
-
- fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
- Field.Store.YES, Field.Index.ANALYZED));
-
- }
-
- }
-
- return doc;
-
- }
-
- throw new IllegalArgumentException();
-
- }
-
- public Object getDocumentKey(Object object) {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/Document.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/Document.java
index 02cf097874..4178decfef 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/Document.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/Document.java
@@ -88,5 +88,5 @@ public class Document {
public boolean containsField(String field) {
return this.fieldablesTable.containsKey(field);
}
-
+
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzer.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzer.java
index b17d22d68a..0a033b488e 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzer.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzer.java
@@ -10,16 +10,20 @@ import org.apache.lucene.analysis.Tokenizer;
public class DomainPathAnalyzer extends Analyzer {
- final public static char PATH_SEPARATOR = '\u0001';
+ final public static char PATH_START = '\u0001';
+
+ final public static char PATH_SEPARATOR = '\u0002';
- final public static char TYPE_SEPARATOR = '\u0002';
+ final public static char TYPE_SEPARATOR = '\u0003';
- final public static char URI_SEPARATOR = '\u0003';
+ final public static char URI_SEPARATOR = '\u0004';
+
+ final public static char ARCHIVE_SEPARATOR = '!';
static class DomainPathTokenizer extends Tokenizer {
private int offset = 0, bufferIndex = 0, dataLen = 0;
- private static final int MAX_WORD_LEN = 255;
+ private static final int MAX_WORD_LEN = 1024;
private static final int IO_BUFFER_SIZE = 4096;
private final char[] ioBuffer = new char[IO_BUFFER_SIZE];
private boolean typeCharFound = false;
@@ -90,8 +94,8 @@ public class DomainPathAnalyzer extends Analyzer {
final char c = ioBuffer[bufferIndex++];
boolean breakChar = true;
boolean includeChar = false;
-
- if (c == PATH_SEPARATOR) {
+
+ if (c == PATH_START || c == PATH_SEPARATOR) {
if (length == 0) {
includeChar = true;
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java
index 4aeb431964..771ec9b224 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java
@@ -1,7 +1,5 @@
package org.apache.tuscany.sca.domain.search.impl;
-import java.io.File;
-
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.ComponentType;
@@ -23,7 +21,8 @@ public class DomainSearchDocumentProcessorsMap extends DocumentProcessorsMap {
addDocumentProcessor(Binding.class, new BindingDocumentProcessor());
addDocumentProcessor(Component.class, new ComponentDocumentProcessor());
addDocumentProcessor(Composite.class, new CompositeDocumentProcessor());
- addDocumentProcessor(File.class, new DomainSearchFileDocumentProcessor());
+ addDocumentProcessor(FileContent.class, new DomainSearchFileDocumentProcessor());
+ addDocumentProcessor(Property.class, new PropertyDocumentProcessor());
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java
index 2537066b92..7b61544778 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java
@@ -26,5 +26,22 @@ public class DomainSearchFormatter implements Formatter {
}
}
+
+ public static boolean isHighlighted(String text) {
+ int start = text.indexOf(HIGHLIGHT_START);
+ int end = text.indexOf(HIGHLIGHT_END);
+
+ if (start < end && start != -1) {
+ start = text.indexOf(HIGHLIGHT_START, start + 1);
+
+ if (start > end || start == -1) {
+ return true;
+ }
+
+ }
+
+ return false;
+
+ }
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java
index 332bd249e1..8ac7b4054d 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java
@@ -1,189 +1,357 @@
package org.apache.tuscany.sca.domain.search.impl;
+import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
-import java.util.List;
+import java.util.HashSet;
import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.document.Field;
import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.HitCollector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.SimpleFSLockFactory;
import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.service.ContributionRepository;
import org.apache.tuscany.sca.domain.search.DocumentMap;
import org.apache.tuscany.sca.domain.search.DomainSearch;
import org.apache.tuscany.sca.domain.search.Result;
import org.osoa.sca.annotations.AllowsPassByReference;
+import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Scope;
@Scope("COMPOSITE")
public class DomainSearchImpl implements DomainSearch {
- private Directory dir = new RAMDirectory();
+ @Property
+ public String indexDirectoryPath;
+
+ private Directory dir;
private Analyzer analyzer = new DomainSearchAnalyzer();
+ private MultiFieldQueryParser qp = new MultiFieldQueryParser(new String[] {
+ SearchFields.ARTIFACT_FIELD, SearchFields.BINDING_FIELD,
+ SearchFields.COMPONENT_FIELD, SearchFields.COMPOSITE_FIELD,
+ SearchFields.CONTRIBUTION_FIELD, SearchFields.EXPORTEDBY_FIELD,
+ SearchFields.FILE_CONTENT_FIELD, SearchFields.IMPLEMENTS_FIELD,
+ SearchFields.IMPORTEDBY_FIELD, SearchFields.INCLUDEDBY_FIELD,
+ SearchFields.PROPERTY_KEY_FIELD, SearchFields.REFERENCE_FIELD,
+ SearchFields.REFERENCE_INTERFACE_CALLBACK_FIELD,
+ SearchFields.REFERENCE_INTERFACE_FIELD,
+ SearchFields.REFERENCE_NAME_FIELD, SearchFields.SERVICE_FIELD,
+ SearchFields.SERVICE_INTERFACE_CALLBACK_FIELD,
+ SearchFields.SERVICE_INTERFACE_FIELD,
+ SearchFields.SERVICE_NAME_FIELD, SearchFields.TYPE_FIELD,
+ SearchFields.VALUE_FIELD }, this.analyzer);
+
public DomainSearchImpl() {
- // empty constructor
+ this.qp.setAllowLeadingWildcard(true);
+
+ }
+
+ private Directory getIndexDirectory() throws IOException {
+
+ if (this.dir == null) {
+
+ if (this.indexDirectoryPath == null
+ || this.indexDirectoryPath.length() == 0) {
+ this.dir = new RAMDirectory();
+
+ } else {
+
+ try {
+ this.dir = new FSDirectory(
+ new File(this.indexDirectoryPath),
+ new SimpleFSLockFactory(this.indexDirectoryPath));
+
+ } catch (IOException e) {
+ System.err.println("Could not open index at "
+ + this.indexDirectoryPath);
+
+ throw e;
+
+ }
+
+ }
+
+ }
+
+ return this.dir;
+
}
@AllowsPassByReference
- public void contributionAdded(ContributionRepository repository,
- Contribution contribution) {
- System.out.println("contributionAdded:");
- System.out.println(repository);
- System.out.println(contribution);
+ public void contributionAdded(Contribution contribution) {
+
+ IndexWriter indexWriter = null;
try {
- IndexWriter indexWriter = new IndexWriter(dir, analyzer,
+ indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer,
IndexWriter.MaxFieldLength.UNLIMITED);
- try {
- DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap();
- DocumentMap docs = new DocumentMap();
+ contributionAdded(contribution, indexWriter);
+
+ indexWriter.commit();
+
+ } catch (Exception e) {
+
+ if (indexWriter != null) {
+
+ try {
+ indexWriter.rollback();
+
+ } catch (Exception e1) {
+ // ignore exception
+ }
+
+ }
+
+ throw new RuntimeException("Problem while indexing!", e);
+
+ } finally {
+
+ if (indexWriter != null) {
try {
- docProcessors.process(docProcessors, docs, contribution, null, "");
+ indexWriter.close();
+
} catch (Exception e) {
- e.printStackTrace();
+ // ignore exception
}
- for (Document doc : docs.values()) {
- indexWriter.addDocument(doc.createLuceneDocument());
+ }
+
+ }
+
+ }
+
+ @AllowsPassByReference
+ public void contributionRemoved(Contribution contribution) {
+
+ IndexWriter indexWriter = null;
+
+ try {
+ indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer,
+ IndexWriter.MaxFieldLength.UNLIMITED);
+
+ contributionRemoved(contribution, indexWriter);
+
+ indexWriter.commit();
+
+ } catch (Exception e) {
+
+ if (indexWriter != null) {
+
+ try {
+ indexWriter.rollback();
+
+ } catch (Exception e1) {
+ // ignore exception
+ }
+
+ }
+
+ throw new RuntimeException("Problem while indexing!", e);
+
+ } finally {
+
+ if (indexWriter != null) {
+
+ try {
+ indexWriter.close();
+
+ } catch (Exception e) {
+ // ignore exception
}
- } finally {
- indexWriter.close();
}
- // BufferedReader consoleReader = new BufferedReader(
- // new InputStreamReader(System.in));
- //
- // while (true) {
- // System.out.print("query: ");
- // String queryString = consoleReader.readLine();
- //
- // if (queryString.equals("exit")) {
- // break;
- // }
- //
- // parseAndSearch(queryString, false);
- //
- // }
-
- } catch (CorruptIndexException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (LockObtainFailedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
}
- public void contributionRemoved(ContributionRepository repository,
- Contribution contribution) {
- System.out.println("contributionRemoved:");
- System.out.println(repository);
- System.out.println(contribution);
+ private void contributionRemoved(Contribution contribution,
+ IndexWriter indexWriter) throws CorruptIndexException, IOException {
+
+ String contributionURI = contribution.getURI();
+ StringBuilder sb = new StringBuilder(SearchFields.PARENT_FIELD);
+ sb.append(":\"");
+ sb.append(DomainPathAnalyzer.PATH_START);
+ sb.append(contributionURI);
+ sb.append("\" OR ");
+ sb.append(SearchFields.CONTRIBUTION_FIELD);
+ sb.append(":\"");
+ sb.append(contributionURI);
+ sb.append('"');
+
+ try {
+ Query query = this.qp.parse(sb.toString());
+ indexWriter.deleteDocuments(query);
+
+ } catch (ParseException e) {
+ throw new RuntimeException("Could not parse query: "
+ + sb.toString(), e);
+ }
}
- public void contributionUpdated(ContributionRepository repository,
- Contribution oldContribution, Contribution contribution) {
+ private void contributionAdded(Contribution contribution,
+ IndexWriter indexWriter) throws CorruptIndexException, IOException {
- System.out.println("contributionUpdated:");
- System.out.println(repository);
- System.out.println(oldContribution);
- System.out.println(contribution);
+ DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap();
+ DocumentMap docs = new DocumentMap();
+
+ try {
+ docProcessors.process(docProcessors, docs, contribution, null, "");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ FileWriter writer = new FileWriter("indexed.txt");
+ for (Document doc : docs.values()) {
+ org.apache.lucene.document.Document luceneDoc = doc
+ .createLuceneDocument();
+ writer.write(luceneDoc.toString());
+ writer.write('\n');
+ writer.write('\n');
+ indexWriter.addDocument(luceneDoc);
+
+ }
+
+ writer.close();
+
+ // BufferedReader consoleReader = new BufferedReader(
+ // new InputStreamReader(System.in));
+ //
+ // while (true) {
+ // System.out.print("query: ");
+ // String queryString = consoleReader.readLine();
+ //
+ // if (queryString.equals("exit")) {
+ // break;
+ // }
+ //
+ // parseAndSearch(queryString, false);
+ //
+ // }
}
- @SuppressWarnings("deprecation")
- public Result[] parseAndSearch(String searchQuery, boolean highlight) {
+ @AllowsPassByReference
+ public void contributionUpdated(Contribution oldContribution,
+ Contribution contribution) {
+
+ IndexWriter indexWriter = null;
try {
- final IndexSearcher searcher = new IndexSearcher(dir);
- final DomainSearchResultProcessor resultProcessor = new DomainSearchResultProcessor(
- new DomainSearchResultFactory());
+ indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer,
+ IndexWriter.MaxFieldLength.UNLIMITED);
- QueryParser qp = new QueryParser("", analyzer);
+ contributionRemoved(oldContribution, indexWriter);
+ contributionAdded(contribution, indexWriter);
- qp.setAllowLeadingWildcard(true);
+ indexWriter.commit();
- try {
- final Query query = qp.parse(searchQuery);
+ } catch (Exception e) {
- searcher.search(query, new HitCollector() {
+ if (indexWriter != null) {
- @Override
- public void collect(int doc, float score) {
- try {
- org.apache.lucene.document.Document document = searcher
- .doc(doc);
+ try {
+ indexWriter.rollback();
- resultProcessor.process(document, query, null);
+ } catch (Exception e1) {
+ // ignore exception
+ }
- List<?> fields = document.getFields();
- System.out.println("---------");
- System.out.println("doc = " + doc);
+ }
- for (Object obj : fields) {
- Field field = (Field) obj;
- String[] values = document.getValues(field
- .name());
- System.out.println(field);
+ throw new RuntimeException("Problem while indexing!", e);
- for (String value : values) {
- System.out.println("\t" + value);
- }
+ } finally {
- }
+ if (indexWriter != null) {
- } catch (CorruptIndexException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ try {
+ indexWriter.close();
- });
+ } catch (Exception e) {
+ // ignore exception
+ }
- } catch (ParseException e) {
- System.out.println(e.getMessage());
}
- Result[] results = resultProcessor.getResultRoots();
+ }
+
+ }
+
+ public Result[] parseAndSearch(String searchQuery, final boolean highlight)
+ throws Exception {
- // for (Result result : results) {
- // System.out.println(result);
- // }
+ final IndexSearcher searcher = new IndexSearcher(getIndexDirectory());
- System.out.println();
+ DomainSearchResultProcessor resultProcessor = new DomainSearchResultProcessor(
+ new DomainSearchResultFactory());
- return results;
+ final Query query = qp.parse(searchQuery);
+ System.out.println("query: " + searchQuery);
+
+ TopDocs topDocs = searcher.search(query, 1000);
+
+ int indexed = 0;
+ HashSet<String> set = new HashSet<String>();
+ for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
+ org.apache.lucene.document.Document luceneDocument = searcher
+ .doc(scoreDoc.doc);
+
+ resultProcessor.process(luceneDocument, null);
+
+ indexed++;
+ set.add(luceneDocument.toString());
+
+ System.out.println(luceneDocument);
- } catch (CorruptIndexException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
}
- return null;
+ /*
+ * searcher.search(query, new HitCollector() {
+ *
+ * @Override public void collect(int doc, float score) { try {
+ * org.apache.lucene.document.Document document = searcher .doc(doc);
+ *
+ * luceneDocuments.put(doc, document);
+ *
+ * System.out.println(doc);
+ *
+ * } catch (CorruptIndexException e) { // TODO Auto-generated catch
+ * block e.printStackTrace(); } catch (IOException e) { // TODO
+ * Auto-generated catch block e.printStackTrace(); } }
+ *
+ * });
+ */
+
+ System.out.println("indexed = " + indexed);
+ System.out.println("set.size() = " + set.size());
+
+ Result[] results = resultProcessor.createResultRoots();
+
+ if (highlight) {
+
+ for (Result result : results) {
+ HighlightingUtil.highlightResult(result, query);
+ }
+
+ }
+
+ return results;
}
@@ -192,4 +360,26 @@ public class DomainSearchImpl implements DomainSearch {
return null;
}
+ public String highlight(String field, String text, String searchQuery)
+ throws Exception {
+ final Query query = qp.parse(searchQuery);
+
+ return HighlightingUtil.highlight(field, query, text);
+
+ }
+
+ public boolean indexExists() {
+
+ if ((this.indexDirectoryPath == null || this.indexDirectoryPath
+ .length() == 0)
+ && this.dir == null) {
+
+ return false;
+
+ } else {
+ return this.dir != null || IndexReader.indexExists(new File(this.indexDirectoryPath));
+ }
+
+ }
+
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java
index f20d2bb586..e4ef73519f 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java
@@ -1,17 +1,17 @@
package org.apache.tuscany.sca.domain.search.impl;
-public class DomainSearchResultFactory extends ResultFactoryList {
+public class DomainSearchResultFactory extends PriorityFieldListResultFactory {
private static final long serialVersionUID = -7421799172738469027L;
public DomainSearchResultFactory() {
- add(new ContributionResultFactory());
- add(new CompositeResultFactory());
- add(new ComponentResultFactory());
- add(new ComponentTypeResultFactory());
- add(new ArtifactResultProcessor.ArtifactResultFactory());
- add(new BindingResultFactory());
- add(new FileContentResultProcessor.FileContentResultFactory());
+ add(SearchFields.COMPOSITE_FIELD);
+ add(SearchFields.COMPONENT_FIELD);
+ add(SearchFields.COMPONENT_TYPE_FIELD);
+ add(SearchFields.CONTRIBUTION_FIELD);
+ add(SearchFields.BINDING_FIELD);
+ add(SearchFields.FILE_CONTENT_FIELD);
+ add(SearchFields.ARTIFACT_FIELD);
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java
index 760f9a6bc2..16a2b38239 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java
@@ -12,7 +12,6 @@ public class DomainSearchResultProcessor extends ResultProcessorList {
super(new DomainSearchResultFactory());
- add(new ArtifactResultProcessor());
add(new FileContentResultProcessor());
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResult.java
deleted file mode 100644
index 1e5d3aec7a..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResult.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-public class FileContentResult extends ResultImpl {
-
- private static final long serialVersionUID = 950227008096181276L;
-
- private String content;
-
- public FileContentResult() {
- // empty constructor
- }
-
- public FileContentResult(String name) {
- super(name);
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- public String getContent() {
- return content;
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java
index e20a170e19..7e1b2bff2e 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java
@@ -1,110 +1,80 @@
package org.apache.tuscany.sca.domain.search.impl;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.util.Enumeration;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
+import java.net.URL;
import org.apache.lucene.document.Document;
-import org.apache.lucene.search.Query;
import org.apache.tuscany.sca.domain.search.Result;
-import org.apache.tuscany.sca.domain.search.ResultFactory;
import org.apache.tuscany.sca.domain.search.ResultProcessor;
public class FileContentResultProcessor implements ResultProcessor {
- public static class FileContentResultFactory implements
- ResultFactory<FileContentResult> {
+ public Result process(Document document, Result result) {
- public FileContentResultFactory() {
- // empty constructor
- }
-
- public FileContentResult createResult(String name) {
- return new FileContentResult(name);
- }
-
- public String getName(Document document) {
- return document.get(SearchFields.FILE_FIELD);
- }
-
- public String getType() {
- return SearchFields.FILE_FIELD;
- }
-
- public FileContentResult createResult(Document document) {
- String name = getName(document);
-
- if (name != null) {
- return createResult(name);
- }
-
- return null;
-
- }
-
- }
-
- public Result process(Document document, Query query, Result result) {
-
- if (result instanceof FileContentResult) {
- FileContentResult fileContentResult = (FileContentResult) result;
+ if (document.getFieldable(SearchFields.FILE_CONTENT_FIELD) != null) {
Reader reader;
ParentField parentField = new ParentField(document
.get(SearchFields.PARENT_FIELD));
- String parentURI = parentField.getElementURI(parentField
- .getElementsCount() - 1);
- String name = document.get(SearchFields.FILE_FIELD);
- if (name == null) {
- return result;
- }
+ int lastParentElementIndex = parentField.getElementsCount() - 1;
+ String parentURI;
- if (parentURI.indexOf(ZipDocumentProcessor.ARCHIVE_SEPARATOR) != -1) {
- String[] locations = parentURI.split(Character
- .toString(ZipDocumentProcessor.ARCHIVE_SEPARATOR));
+ if (SearchFields.ARTIFACT_FIELD.equals(parentField
+ .getElementType(lastParentElementIndex))) {
+ parentURI = parentField.getElementURI(lastParentElementIndex);
- try {
- ZipFile zip = new ZipFile(new File(locations[0]));
+ // if (parentURI.startsWith("jar:")) {
- // TODO: normalize the entry path and check if the entry still exists
- ZipEntry entry = zip.getEntry(locations[1].substring(1) + name);
-
- Enumeration<? extends ZipEntry> entries = zip.entries();
-
- while (entries.hasMoreElements()) System.out.println(entries.nextElement().getName());
-
- reader = new InputStreamReader(zip.getInputStream(entry));
+ try {
+ reader = new InputStreamReader(new URL(parentURI)
+ .openStream());
} catch (IOException e) {
return result;
}
- } else {
+ // } else {
+ //
+ // try {
+ // reader = new InputStreamReader(new FileInputStream(
+ // new File(parentURI + (parentURI.length() > 0 ? "/" : "") +
+ // name)));
+ //
+ // } catch (FileNotFoundException e) {
+ // return result;
+ // }
+ //
+ // }
try {
- reader = new InputStreamReader(new FileInputStream(
- new File(parentURI + '/' + name)));
- } catch (FileNotFoundException e) {
- return result;
- }
+ 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);
+ }
+
+ }
- try {
- fileContentResult.setContent(HighlightingUtil
- .bestFragmentHighlighted(query, reader));
+ result.setValue(sb.toString());
+
+ } catch (Exception e) {
+ // ignore content loading, TODO: maybe it should return an
+ // error
+ // message as the content
+
+ }
- } catch (IOException e) {
- // ignore content loading, TODO: maybe it return an error
- // message as the content
}
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java
index 138c9c42e9..25b1f3b41d 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java
@@ -2,7 +2,6 @@ package org.apache.tuscany.sca.domain.search.impl;
import java.util.LinkedList;
-import org.apache.lucene.document.Field;
import org.apache.tuscany.sca.domain.search.DocumentMap;
import org.apache.tuscany.sca.domain.search.DocumentProcessor;
@@ -20,36 +19,36 @@ public class FileDocumentProcessor extends LinkedList<DocumentProcessor>
if (!file.isLeaf()) {
if (doc == null) {
- doc = documents.get(file.getPath());
+ doc = documents.get(SearchFields.FILE_CONTENT_FIELD + file.getPath());
}
- doc.add(new Field(SearchFields.DIRECTORY_FIELD, file
- .getPath(), Field.Store.YES,
- Field.Index.ANALYZED));
+ //FileContent[] files = file.getChildren();
+
+// for (FileContent childFile : files) {
+// // Document fileDoc = parentProcessor.process(
+// // parentProcessor, documents, childFile, null,
+// // parent);
+//
+// Document fileDoc = null;
+//
+// fileDoc = process(this, documents, childFile, null, parent);
+//
+// if (fileDoc == null) {
+// continue;
+// }
+//
+// fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
+// Field.Store.YES, Field.Index.ANALYZED));
+//
+// }
- parent += DomainPathAnalyzer.PATH_SEPARATOR
- + SearchFields.FILE_FIELD
- + DomainPathAnalyzer.TYPE_SEPARATOR + file.getPath()
- + DomainPathAnalyzer.URI_SEPARATOR + file.getName();
-
- FileContent[] files = file.getChildren();
-
- for (FileContent childFile : files) {
- Document fileDoc = parentProcessor.process(parentProcessor,
- documents, childFile, null, parent);
-
- fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
- Field.Store.YES, Field.Index.ANALYZED));
-
- }
-
return doc;
} else {
for (DocumentProcessor processor : this) {
- Document newDoc = processor.process(this, documents,
- object, doc, parent);
+ Document newDoc = processor.process(this, documents, file,
+ doc, parent);
if (newDoc != null) {
return newDoc;
@@ -60,7 +59,7 @@ public class FileDocumentProcessor extends LinkedList<DocumentProcessor>
}
}
-
+
return doc;
}
@@ -75,7 +74,7 @@ public class FileDocumentProcessor extends LinkedList<DocumentProcessor>
return null;
}
- return path;
+ return SearchFields.FILE_CONTENT_FIELD + path;
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java
index 0703438125..942679169f 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java
@@ -1,43 +1,76 @@
package org.apache.tuscany.sca.domain.search.impl;
import java.io.IOException;
-import java.io.Reader;
import java.io.StringReader;
+import java.util.Map;
import org.apache.lucene.analysis.CachingTokenFilter;
import org.apache.lucene.search.Query;
+import org.apache.lucene.search.highlight.Fragmenter;
import org.apache.lucene.search.highlight.Highlighter;
import org.apache.lucene.search.highlight.InvalidTokenOffsetsException;
+import org.apache.lucene.search.highlight.NullFragmenter;
import org.apache.lucene.search.highlight.SimpleFragmenter;
import org.apache.lucene.search.highlight.SpanScorer;
+import org.apache.tuscany.sca.domain.search.Result;
final public class HighlightingUtil {
- public static String bestFragmentHighlighted(Query query, Reader reader) throws IOException {
- StringBuilder sb = new StringBuilder();
- int c;
+ public static void highlightResult(Result result, Query query) {
+ highlightResult(result, query, new SimpleFragmenter(70));
+ }
+
+ public static void highlightResult(Result result, Query query, Fragmenter fragmenter) {
+ Map<String, Result> contents = result.getContents();
+
+ if (contents != null) {
+
+ for (Result content : contents.values()) {
+ highlightResult(content, query, fragmenter);
+ }
+
+ }
- // TODO: load the chars into a buffer instead of one at a time
- while ((c = reader.read()) != -1) {
- char character = (char) c;
-
- if (!Character.isIdentifierIgnorable(character)) {
- sb.append(character);
+ try {
+ String highlightedText = HighlightingUtil.bestFragmentHighlighted(
+ result.getField(), query, result.getValue(), fragmenter);
+
+ // checks if something was highlighted before resetting the value
+ if (highlightedText != null && highlightedText.length() > 0) {
+ result.setValue(highlightedText);
}
-
+
+ } catch (IOException e) {
+ // ignore highlighting
}
+
+ }
+
+ public static String highlight(String field, Query query, String text) throws IOException {
+ String highlightedText = bestFragmentHighlighted(field, query, text, new NullFragmenter());
- String text = sb.toString();
+ if (highlightedText == null || text.length() >= highlightedText.length()) {
+ return text;
+ }
- CachingTokenFilter tokenStream = new CachingTokenFilter(new NamingAnalyzer().tokenStream(
- SearchFields.FILE_CONTENT_FIELD, new StringReader(text)));
+ return highlightedText;
- Highlighter highlighter = new Highlighter(new DomainSearchFormatter(), new SpanScorer(query, SearchFields.FILE_CONTENT_FIELD, tokenStream, ""));
- highlighter.setTextFragmenter(new SimpleFragmenter(100));
+ }
+
+ public static String bestFragmentHighlighted(String field, Query query, String text) throws IOException {
+ return bestFragmentHighlighted(field, query, text, new SimpleFragmenter(100));
+ }
+
+ public static String bestFragmentHighlighted(String field, Query query, String text, Fragmenter fragmenter) throws IOException {
+ CachingTokenFilter tokenStream = new CachingTokenFilter(new DomainSearchAnalyzer().tokenStream(
+ field, new StringReader(text)));
+
+ Highlighter highlighter = new Highlighter(new DomainSearchFormatter(), new SpanScorer(query, field, tokenStream, ""));
+ highlighter.setTextFragmenter(fragmenter);
tokenStream.reset();
try {
- return highlighter.getBestFragments(tokenStream, text, 2, "...");
+ return highlighter.getBestFragments(tokenStream, text, 2, " ... ");
} catch (InvalidTokenOffsetsException e) {
@@ -45,7 +78,7 @@ final public class HighlightingUtil {
return "";
}
-
+
}
public static String replaceHighlightMarkupBy(CharSequence text,
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java
index 11885909e1..e4b84881fd 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java
@@ -29,7 +29,7 @@ public class ParentField implements Serializable {
for (int i = 0; i < length ; i++) {
char c = parentFieldValue.charAt(i);
- if (c == DomainPathAnalyzer.PATH_SEPARATOR) {
+ if (c == DomainPathAnalyzer.PATH_SEPARATOR || c == DomainPathAnalyzer.PATH_START) {
if (sb.length() > 0 || element != null) {
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java
new file mode 100644
index 0000000000..53fd286cdb
--- /dev/null
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java
@@ -0,0 +1,36 @@
+package org.apache.tuscany.sca.domain.search.impl;
+
+import java.util.LinkedList;
+
+import org.apache.lucene.document.Document;
+import org.apache.tuscany.sca.domain.search.Result;
+import org.apache.tuscany.sca.domain.search.ResultFactory;
+
+public class PriorityFieldListResultFactory extends LinkedList<String> implements ResultFactory<Result> {
+
+ private static final long serialVersionUID = 6806221945324235828L;
+
+ public PriorityFieldListResultFactory() {
+ // empty constructor
+ }
+
+ public Result createResult(Document document) {
+
+ for (String field : this) {
+ String value = document.get(field);
+
+ if (value != null) {
+ return new ResultImpl(field, value);
+ }
+
+ }
+
+ return null;
+
+ }
+
+ public Result createResult(String field, String value) {
+ return new ResultImpl(field, value);
+ }
+
+}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyResult.java
deleted file mode 100644
index 361279e62d..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyResult.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-public class PropertyResult extends ResultImpl {
-
- private static final long serialVersionUID = 5744678253277504237L;
-
- private String[] values;
-
- public PropertyResult(String name, String... values) {
- super(name);
-
- this.values = values;
-
- }
-
- public String[] getValues() {
- return this.values.clone();
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ReferenceResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ReferenceResult.java
deleted file mode 100644
index fbd724ce2d..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ReferenceResult.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-public class ReferenceResult extends ResultImpl {
-
- private static final long serialVersionUID = -2846199490484466090L;
-
- private String[] operations;
-
- private String[] callbackOperations;
-
- public ReferenceResult(String name, String[] operations, String[] callbackOperations) {
- super(name);
-
- this.operations = operations;
- this.callbackOperations = callbackOperations;
-
- }
-
- public String[] getOperations() {
- return this.operations.clone();
- }
-
- public String[] getCallbackOperations() {
- return this.callbackOperations.clone();
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultFactoryList.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultFactoryList.java
deleted file mode 100644
index c2a4edc7f0..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultFactoryList.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-import java.util.LinkedList;
-
-import org.apache.lucene.document.Document;
-import org.apache.tuscany.sca.domain.search.Result;
-import org.apache.tuscany.sca.domain.search.ResultFactory;
-
-public class ResultFactoryList extends LinkedList<ResultFactory<? extends Result>> implements ResultFactory<Result> {
-
- private static final long serialVersionUID = 6806221945324235828L;
-
- public ResultFactoryList() {
- // empty constructor
- }
-
- public Result createResult(Document document) {
-
- for (ResultFactory<? extends Result> resultFactory : this) {
- Result result = resultFactory.createResult(document);
-
- if (result != null) {
- return result;
- }
-
- }
-
- return null;
-
- }
-
- public Result createResult(String name) {
- return null;
- }
-
- public String getName(Document document) {
-
- for (ResultFactory<? extends Result> resultFactory : this) {
- String name = resultFactory.getName(document);
-
- if (name != null) {
- return name;
- }
-
- }
-
- return null;
-
- }
-
- public String getType() {
- return "";
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java
index aef4a8e53c..6d620a3292 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java
@@ -9,7 +9,7 @@ import java.util.Map;
import org.apache.tuscany.sca.domain.search.Result;
-public abstract class ResultImpl implements Result {
+final public class ResultImpl implements Result {
private static final long serialVersionUID = 7084570994751217396L;
@@ -17,14 +17,26 @@ public abstract class ResultImpl implements Result {
private HashMap<String, Result> contents;
- private String name;
+ private String value;
+
+ private String field;
public ResultImpl() {
// empty constructor
}
- public ResultImpl(String name) {
- this.name = name;
+ public ResultImpl(String field, String value) {
+ setValue(value);
+ setField(field);
+
+ }
+
+ public String getField() {
+ return this.field;
+ }
+
+ public void setField(String field) {
+ this.field = field;
}
public Result getContainer() {
@@ -41,8 +53,8 @@ public abstract class ResultImpl implements Result {
}
- public String getName() {
- return this.name;
+ public String getValue() {
+ return this.value;
}
public void setContainer(Result container) {
@@ -69,8 +81,8 @@ public abstract class ResultImpl implements Result {
if (obj instanceof Result) {
Result artifactResult = (Result) obj;
- if (artifactResult.getName() == this.name || this.name != null
- && this.name.equals(artifactResult.getName())) {
+ if (artifactResult.getValue() == this.value || this.value != null
+ && this.value.equals(artifactResult.getValue())) {
if (artifactResult.getContainer() == this.container
|| this.container != null
@@ -96,7 +108,7 @@ public abstract class ResultImpl implements Result {
}
public void addContent(Result artifactResult) {
- internalGetContents().put(artifactResult.getName(), artifactResult);
+ internalGetContents().put(artifactResult.getValue(), artifactResult);
if (artifactResult.getContainer() != this) {
artifactResult.setContainer(this);
@@ -139,22 +151,22 @@ public abstract class ResultImpl implements Result {
* 31
+ (this.contents == null || this.contents.isEmpty() ? 13
: this.contents.hashCode());
- hash = hash * 31 + (this.name == null ? 17 : this.name.hashCode());
+ hash = hash * 31 + (this.value == null ? 17 : this.value.hashCode());
return hash;
}
- public void setName(String name) {
- this.name = name;
+ public void setValue(String value) {
+ this.value = value;
}
public String toString() {
StringBuilder sb = new StringBuilder("<");
Result container = getContainer();
- sb.append(getClass().getName()).append(" name='").append(getName())
- .append("' container='").append(container != null ? container.getName() : null).append("'>\n");
+ sb.append(getClass().getName()).append(" name='").append(getValue())
+ .append("' container='").append(container != null ? container.getValue() : null).append("'>\n");
Method[] methods = getClass().getMethods();
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java
index e186bdd6d0..ff3dcf7b7f 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java
@@ -4,145 +4,162 @@ import java.util.HashMap;
import java.util.LinkedList;
import org.apache.lucene.document.Document;
-import org.apache.lucene.search.Query;
import org.apache.tuscany.sca.domain.search.Result;
import org.apache.tuscany.sca.domain.search.ResultFactory;
import org.apache.tuscany.sca.domain.search.ResultProcessor;
-public class ResultProcessorList extends LinkedList<ResultProcessor> implements ResultProcessor {
+public class ResultProcessorList extends LinkedList<ResultProcessor> implements
+ ResultProcessor {
private static final long serialVersionUID = 7147307292452694895L;
-
- private ResultFactoryList resultFactoryList;
-
+
private HashMap<String, ResultHashMap> resultRoots = new HashMap<String, ResultHashMap>();
+
+ private ResultFactory<? extends Result> resultFactory;
- public ResultProcessorList(ResultFactoryList resultFactoryList) {
- this.resultFactoryList = resultFactoryList;
+ public ResultProcessorList(ResultFactory<? extends Result> resultFactory) {
+ this.resultFactory = resultFactory;
}
-
- public Result process(Document document, Query query, Result result) {
-
- if (result == null) {
- result = this.resultFactoryList.createResult(document);
- }
-
+
+ public Result process(Document document, Result result) {
+
if (result == null) {
- return null;
+ result = this.resultFactory.createResult(document);
+
+ if (result == null) {
+ return null;
+ }
+
}
-
+
ResultHashMap resultHashMap;
-
+
String parent = document.get(SearchFields.PARENT_FIELD);
-
+
if (parent == null) {
resultHashMap = new ResultHashMap(result);
- resultRoots.put(result.getName(), resultHashMap);
-
+ resultRoots.put(result.getValue(), resultHashMap);
+
} else {
-
+
ParentField parentField = new ParentField(parent);
HashMap<String, ResultHashMap> current = this.resultRoots;
- Result currentResult = null;
+ //Result currentResult = null;
int elementsCount = parentField.getElementsCount();
-
- for (int i = 0 ; i < elementsCount ; i++) {
- String actualURI = parentField.getElementURI(i);
+
+ for (int i = 0; i < elementsCount; i++) {
+ String actualName = parentField.getElementName(i);
String type = parentField.getElementType(i);
-
- if (actualURI.length() > 0) {
- ResultHashMap actualResultHashMap = current.get(actualURI);
-
+
+ if (actualName.length() > 0) {
+ ResultHashMap actualResultHashMap = current.get(actualName);
+
if (actualResultHashMap == null) {
- ResultHashMap aux = new ResultHashMap(type, parentField.getElementName(i));
-
- if (current.put(actualURI, aux) == null && currentResult != null) {
- currentResult.addContent(aux.result);
- }
-
+ ResultHashMap aux = new ResultHashMap(type, parentField
+ .getElementName(i));
+
+ current.put(aux.result.getValue(), aux);
+// if (current.put(aux.result.getValue(), aux) == null
+// && currentResult != null) {
+// currentResult.addContent(aux.result);
+// }
+
current = aux;
- currentResult = aux.result;
-
+ //currentResult = aux.result;
+
} else {
current = actualResultHashMap;
- currentResult = actualResultHashMap.result;
-
+ //currentResult = actualResultHashMap.result;
+
}
-
+
}
-
+
}
-
- resultHashMap = current.get(result.getName());
-
+
+ resultHashMap = current.get(result.getValue());
+
if (resultHashMap == null) {
resultHashMap = new ResultHashMap(result);
- current.put(result.getName(), resultHashMap);
-
- if (currentResult != null) {
- currentResult.addContent(result);
- }
-
+ current.put(result.getValue(), resultHashMap);
+
+// if (currentResult != null) {
+// currentResult.addContent(result);
+// }
+
}
-
+
}
-
+
for (ResultProcessor processor : this) {
- result = processor.process(document, query, result);
+ result = processor.process(document, result);
}
-
+
resultHashMap.result = result;
-
+
return result;
-
+
}
- public Result[] getResultRoots() {
- int size = this.resultRoots.size();
+ private static void addContentsToResult(ResultHashMap resultHashMap) {
+
+ for (ResultHashMap actual : resultHashMap.values()) {
+ addContentsToResult(actual);
+
+ resultHashMap.result.addContent(actual.result);
+
+ }
+ }
+
+ public Result[] createResultRoots() {
+ int size = this.resultRoots.size();
+
if (size == 0) {
return new Result[0];
}
-
+
Result[] res = new Result[size];
-
+
int i = 0;
for (ResultHashMap resultHashMap : this.resultRoots.values()) {
+
+ addContentsToResult(resultHashMap);
res[i++] = resultHashMap.result;
+
}
+ this.resultRoots.clear();
+
return res;
-
+
}
-
- private Result createResult(String type, String name) {
+
+ private Result createResult(String field, String value) {
+ Result result = this.resultFactory.createResult(field, value);
- for (ResultFactory<? extends Result> actualResultFactory : this.resultFactoryList) {
-
- if (type.equals(actualResultFactory.getType())) {
- return actualResultFactory.createResult(name);
- }
-
+ if (result != null) {
+ return result;
}
-
+
throw new IllegalArgumentException();
-
+
}
-
+
private class ResultHashMap extends HashMap<String, ResultHashMap> {
private static final long serialVersionUID = 7982561264440904411L;
-
+
Result result;
-
+
ResultHashMap(String type, String name) {
- this.result = createResult(type, name);
+ this(createResult(type, name));
}
-
+
ResultHashMap(Result result) {
this.result = result;
}
-
+
}
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java
index 5d0a60ccd6..2f3e0bdb7f 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java
@@ -2,11 +2,7 @@ package org.apache.tuscany.sca.domain.search.impl;
public interface SearchFields {
- final public static String LOCATION_FIELD = "location";
-
- final public static String DIRECTORY_FIELD = "directory";
-
- final public static String FILE_FIELD = "file";
+ final public static String ARTIFACT_FIELD = "artifact";
final public static String COMPONENT_TYPE_FIELD = "componenttype";
@@ -18,8 +14,6 @@ public interface SearchFields {
final public static String BINDING_FIELD = "binding";
- final public static String ARTIFACT_FIELD = "artifact";
-
final public static String CONTRIBUTION_FIELD = "contribution";
final public static String COMPONENT_FIELD = "component";
@@ -48,7 +42,7 @@ public interface SearchFields {
final public static String INCLUDEDBY_FIELD = "includedby";
- final public static String KEY_FIELD = "propertykey";
+ final public static String PROPERTY_KEY_FIELD = "propertykey";
final public static String VALUE_FIELD = "propertyvalue";
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ServiceResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ServiceResult.java
deleted file mode 100644
index fd9d980137..0000000000
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ServiceResult.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.apache.tuscany.sca.domain.search.impl;
-
-public class ServiceResult extends ResultImpl {
-
- private static final long serialVersionUID = -2846199490484466090L;
-
- private String[] operations;
-
- private String[] callbackOperations;
-
- public ServiceResult(String name, String[] operations, String[] callbackOperations) {
- super(name);
-
- this.operations = operations;
- this.callbackOperations = callbackOperations;
-
- }
-
- public String[] getOperations() {
- return this.operations.clone();
- }
-
- public String[] getCallbackOperations() {
- return this.callbackOperations.clone();
- }
-
-}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java
index 9ce20bdea1..a81bcfff53 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java
@@ -5,24 +5,26 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-public class SystemFileContent extends File implements FileContent {
+public class SystemFileContent implements FileContent {
private static final long serialVersionUID = -8337926886777467728L;
final boolean leaf;
-
+
final private File file;
public SystemFileContent(File file) {
- super(file.getPath());
-
this.leaf = !file.isDirectory();
this.file = file;
}
-
+
+ public File getFile() {
+ return this.file;
+ }
+
public InputStream getInputStream() throws IOException {
- return new FileInputStream(this);
+ return new FileInputStream(this.file);
}
public FileContent[] getChildren() {
@@ -41,4 +43,12 @@ public class SystemFileContent extends File implements FileContent {
return this.leaf;
}
+ public String getName() {
+ return this.file.getName();
+ }
+
+ public String getPath() {
+ return this.file.getPath();
+ }
+
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java
new file mode 100644
index 0000000000..618d984830
--- /dev/null
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java
@@ -0,0 +1,91 @@
+package org.apache.tuscany.sca.domain.search.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.JarURLConnection;
+import java.net.URL;
+
+public class WrappedFileContent implements FileContent {
+
+ final private FileContent fileContent;
+
+ public WrappedFileContent(URL url) throws IOException {
+ String protocol = url.getProtocol();
+
+ if (protocol.equals("jar")) {
+ JarURLConnection jarConn = (JarURLConnection) url.openConnection();
+ //Enumeration<JarEntry> entries = jarConn.getJarFile().entries();
+ String file = url.getFile();
+ file = file.substring(file.lastIndexOf('!') + 1);
+
+// if (file.charAt(file.length() - 1) != '/') {
+//
+// int beginIndex;
+//
+// if (file.charAt(0) == '/') {
+// beginIndex = 1;
+//
+// } else {
+// beginIndex = 0;
+// }
+//
+// file = file.substring(beginIndex);
+//
+// while (entries.hasMoreElements()) {
+// String actualFile = entries.nextElement().getName();
+//
+// if (actualFile.charAt(0) == '/') {
+// beginIndex = 1;
+//
+// } else {
+// beginIndex = 0;
+// }
+//
+// if (actualFile.length() - beginIndex == file.length() + 1 && actualFile.charAt(actualFile.length() - 1) == '/') {
+//
+// if (actualFile.startsWith(file, beginIndex)) {
+// file = actualFile;
+//
+// break;
+//
+// }
+//
+// }
+//
+// }
+//
+// }
+
+ this.fileContent = ZipFileContent.createZipFileContent(jarConn.getJarFile(), file);
+
+ } else if (protocol.equals("file")) {
+ this.fileContent = new SystemFileContent(new File(url.getFile()));
+
+ } else {
+ this.fileContent = new DefaultFileContent(url);
+ }
+
+ }
+
+ public FileContent[] getChildren() {
+ return this.fileContent.getChildren();
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return this.fileContent.getInputStream();
+ }
+
+ public String getName() {
+ return this.fileContent.getName();
+ }
+
+ public String getPath() {
+ return this.fileContent.getPath();
+ }
+
+ public boolean isLeaf() {
+ return this.fileContent.isLeaf();
+ }
+
+}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java
index 3f3112dd60..b36d2c1d79 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java
@@ -2,7 +2,6 @@ package org.apache.tuscany.sca.domain.search.impl;
import java.io.File;
import java.io.IOException;
-import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.apache.lucene.document.Field;
@@ -11,8 +10,6 @@ import org.apache.tuscany.sca.domain.search.DocumentProcessor;
public class ZipDocumentProcessor implements DocumentProcessor {
- final public static char ARCHIVE_SEPARATOR = '\u0004';
-
public Object getDocumentKey(Object object) {
if (object instanceof File) {
@@ -39,18 +36,18 @@ public class ZipDocumentProcessor implements DocumentProcessor {
SystemFileContent file = (SystemFileContent) object;
try {
- ZipFile zip = new ZipFile(file);
+ ZipFile zip = new ZipFile(file.getFile());
if (document == null) {
document = documents.get(file.getPath());
}
parent += DomainPathAnalyzer.PATH_SEPARATOR
- + SearchFields.FILE_FIELD
- + DomainPathAnalyzer.TYPE_SEPARATOR + file.getPath() + ARCHIVE_SEPARATOR
+ + SearchFields.ARTIFACT_FIELD
+ + DomainPathAnalyzer.TYPE_SEPARATOR + "jar:file:" + file.getPath() + DomainPathAnalyzer.ARCHIVE_SEPARATOR + '/' + file.getName()
+ DomainPathAnalyzer.URI_SEPARATOR + file.getName();
- document.add(new Field(SearchFields.FILE_FIELD, file.getName(), Field.Store.YES,
+ document.add(new Field(SearchFields.ARTIFACT_FIELD, file.getName(), Field.Store.YES,
Field.Index.ANALYZED));
ZipFileContent[] zipFiles = ZipFileContent.createZipFileContent(zip);
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java
index 10aea9fa9e..87c08cd4f7 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java
@@ -7,20 +7,18 @@ import java.util.HashMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-import org.apache.tuscany.sca.domain.search.DocumentProcessor;
-
public class ZipFileContent implements FileContent {
-
+
final private ZipFile file;
-
+
final private ZipEntry entry;
-
+
private FileContent[] children;
-
+
private ZipFileContent(ZipFile file, ZipEntry entry) {
this.file = file;
this.entry = entry;
-
+
}
public InputStream getInputStream() throws IOException {
@@ -28,7 +26,8 @@ public class ZipFileContent implements FileContent {
}
public String getPath() {
- return this.file.getName() + ZipDocumentProcessor.ARCHIVE_SEPARATOR + '/' + this.entry.getName();
+ return this.file.getName() + DomainPathAnalyzer.ARCHIVE_SEPARATOR + '/'
+ + this.entry.getName();
}
public FileContent[] getChildren() {
@@ -36,153 +35,270 @@ public class ZipFileContent implements FileContent {
}
public String getName() {
- String name = this.entry.getName();
- int lastSlashIndex = name.lastIndexOf('/');
-
- if (lastSlashIndex == -1) {
- return name;
- }
-
- if (lastSlashIndex == name.length() - 1 && name.length() > 1) {
- lastSlashIndex = name.lastIndexOf('/', name.length() - 2);
-
- if (lastSlashIndex == -1) {
- return name.substring(0, name.length() - 1);
- }
-
- return name.substring(lastSlashIndex + 1, name.length() - 1);
-
- }
-
- return name.substring(lastSlashIndex + 1);
-
+ return this.entry.getName();
+// int lastSlashIndex = name.lastIndexOf('/');
+//
+// if (lastSlashIndex == -1) {
+// return name;
+// }
+//
+// if (lastSlashIndex == name.length() - 1 && name.length() > 1) {
+// lastSlashIndex = name.lastIndexOf('/', name.length() - 2);
+//
+// if (lastSlashIndex == -1) {
+// return name.substring(0, name.length() - 1);
+// }
+//
+// return name.substring(lastSlashIndex + 1, name.length() - 1);
+//
+// }
+//
+// return name.substring(lastSlashIndex + 1);
+
}
public boolean isLeaf() {
return !this.entry.isDirectory();
}
-
+
public static ZipFileContent[] createZipFileContent(ZipFile file) {
Enumeration<? extends ZipEntry> entries = file.entries();
-
+
if (!entries.hasMoreElements()) {
return null;
}
-
+
HashMap<String, ZipMap> roots = new HashMap<String, ZipMap>();
-
+
do {
ZipEntry entry = entries.nextElement();
String name = entry.getName();
-
+
if (name.length() > 0) {
-
+
String[] path = name.split("/");
-
+
ZipMap current = roots.get(path[0]);
-
+
if (current == null) {
current = new ZipMap();
roots.put(path[0], current);
-
+
if (path.length == 1) {
current.setEntry(file, entry);
continue;
}
-
+
}
-
- for (int i = 1 ; i < path.length - 1 ; i++) {
+
+ for (int i = 1; i < path.length - 1; i++) {
ZipMap actual = current.get(path[i]);
-
+
if (actual == null) {
actual = new ZipMap();
current.put(path[i], actual);
-
+
}
-
+
current = actual;
-
+
}
-
+
ZipMap entryMap = current.get(path[path.length - 1]);
-
+
if (entryMap == null) {
entryMap = new ZipMap();
current.put(path[path.length - 1], entryMap);
-
+
}
-
+
entryMap.setEntry(file, entry);
-
+
}
-
+
} while (entries.hasMoreElements());
-
+
for (ZipMap map : roots.values()) {
createZipFileContentChildren(map);
}
-
+
ZipFileContent[] ret = new ZipFileContent[roots.size()];
int i = 0;
-
+
for (ZipMap rootMap : roots.values()) {
ret[i++] = rootMap.zipContent;
}
-
+
return ret;
+
+ }
+
+ public static ZipFileContent createZipFileContent(ZipFile file,
+ String filePath) {
+
+ Enumeration<? extends ZipEntry> entries = file.entries();
+
+ if (!entries.hasMoreElements()) {
+ return null;
+ }
+
+ int beginIndex;
+ int endIndex;
+
+ if (filePath.charAt(0) == '/') {
+ beginIndex = 1;
+
+ } else {
+ beginIndex = 0;
+ }
+
+ ZipMap root = new ZipMap();
+ if (filePath.length() > 1
+ && filePath.charAt(filePath.length() - 1) == '/') {
+ endIndex = filePath.length() - 1;
+
+ } else {
+ endIndex = filePath.length();
+ }
+
+ filePath = filePath.substring(beginIndex, endIndex);
+ // HashMap<String, ZipMap> roots = new HashMap<String, ZipMap>();
+
+ do {
+ ZipEntry entry = entries.nextElement();
+ String name = entry.getName();
+
+ if (name.length() > 0) {
+
+ if (name.charAt(name.length() - 1) == '/') {
+ endIndex = 1;
+
+ } else {
+ endIndex = 0;
+ }
+
+ if (name.length() - endIndex == filePath.length()) {
+ root.setEntry(file, entry);
+
+ } else if (filePath.length() == 0 || (name.startsWith(filePath) && name.charAt(filePath.length()) == '/')) {
+
+ name = name.substring(filePath.length());
+ String[] path = name.split("/");
+
+ ZipMap current = root;
+
+ // if (current == null) {
+ // current = new ZipMap();
+ // roots.put(path[0], current);
+ //
+ // if (path.length == 1) {
+ // current.setEntry(file, entry);
+ // continue;
+ //
+ // }
+ //
+ // }
+
+ if (path.length > 0) {
+
+ int i;
+
+ if (path[0].length() == 0) {
+ i = 1;
+
+ } else {
+ i = 0;
+ }
+
+ for (; i < path.length - 1; i++) {
+ ZipMap actual = current.get(path[i]);
+
+ if (actual == null) {
+ actual = new ZipMap();
+ current.put(path[i], actual);
+
+ }
+
+ current = actual;
+
+ }
+
+ ZipMap entryMap = current.get(path[path.length - 1]);
+
+ if (entryMap == null) {
+ entryMap = new ZipMap();
+ current.put(path[path.length - 1], entryMap);
+
+ }
+
+ entryMap.setEntry(file, entry);
+
+ }
+
+ }
+
+ }
+
+ } while (entries.hasMoreElements());
+
+ createZipFileContentChildren(root);
+
+ return root.zipContent;
+
}
-
+
private static void createZipFileContentChildren(ZipMap map) {
ZipFileContent[] children = new ZipFileContent[map.size()];
int i = 0;
-
+
for (ZipMap childMap : map.values()) {
-
+
if (childMap.zipContent == null) {
- throw new RuntimeException("could not load zip file hierarchy for file: " + map.zipContent.file);
+ throw new RuntimeException(
+ "could not load zip file hierarchy for file: "
+ + map.zipContent.file);
}
-
+
children[i++] = childMap.zipContent;
-
+
createZipFileContentChildren(childMap);
-
+
}
-
+
map.zipContent.children = children;
-
+
}
-
+
@Override
public String toString() {
return this.file.getName() + '/' + this.entry.getName();
}
-
+
private static class ZipMap extends HashMap<String, ZipMap> {
-
+
private static final long serialVersionUID = 6514645087432837480L;
-
+
ZipFileContent zipContent;
-
+
void setEntry(ZipFile zipFile, ZipEntry entry) {
this.zipContent = new ZipFileContent(zipFile, entry);
}
-
+
ZipFileContent[] getChildren() {
-
+
ZipFileContent ret[] = new ZipFileContent[this.size()];
int i = 0;
-
+
for (ZipMap actual : this.values()) {
ret[i++] = actual.zipContent;
}
-
+
return ret;
-
+
}
-
+
}
}
diff --git a/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java b/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java
index 4cb81a1961..b8b014b73b 100644
--- a/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java
+++ b/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java
@@ -15,12 +15,13 @@ public class DomainPathAnalyzerTestCase extends TestCase {
public void test() throws IOException {
Tokenizer tokenizer = new DomainPathAnalyzer.DomainPathTokenizer(new StringReader(
- DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.CONTRIBUTION_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + "123tuscany" + DomainPathAnalyzer.TYPE_SEPARATOR + "SCA" +
+ Character.toString(DomainPathAnalyzer.PATH_START) + SearchFields.CONTRIBUTION_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + "123tuscany" + DomainPathAnalyzer.PATH_START + DomainPathAnalyzer.TYPE_SEPARATOR + "SCA" +
DomainPathAnalyzer.PATH_SEPARATOR + DomainPathAnalyzer.TYPE_SEPARATOR + "TuscanySCA" + DomainPathAnalyzer.TYPE_SEPARATOR + "321" + DomainPathAnalyzer.URI_SEPARATOR + "123"));
- assertNextToken(Character.toString(DomainPathAnalyzer.PATH_SEPARATOR), tokenizer);
+ assertNextToken(Character.toString(DomainPathAnalyzer.PATH_START), tokenizer);
assertNextToken("123", tokenizer);
assertNextToken("tuscany", tokenizer);
+ assertNextToken(Character.toString(DomainPathAnalyzer.PATH_START), tokenizer);
assertNextToken("sca", tokenizer);
assertNextToken(Character.toString(DomainPathAnalyzer.PATH_SEPARATOR), tokenizer);
assertNextToken("tuscany", tokenizer);