diff options
Diffstat (limited to '')
20 files changed, 425 insertions, 465 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 ef23b1b4cd..3e17ae007b 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 @@ -75,6 +75,7 @@ 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.domain.search.IndexException; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.monitor.Problem; @@ -225,7 +226,14 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl // add it to the search index, contributionUpdated is called to guarantee // only one contribution with the same URI in the index if (domainSearch != null) { // can be null in unit tests - domainSearch.contributionUpdated(contribution, contribution); + + try { + domainSearch.updateContribution(contribution, contribution); + + } catch (IndexException e) { + logger.warning("Could not update contribution on index: " + contribution.getURI()); + } + } return key; @@ -274,7 +282,13 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl // delete it from the search index if (domainSearch != null) { // can be null in unit tests - domainSearch.contributionRemoved(contribution); + + try { + domainSearch.removeContribution(contribution); + } catch (IndexException e) { + logger.warning("Could not remove contribution from index: " + contribution.getURI()); + } + } return; diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerUtil.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerUtil.java index 069cc9f5ae..c015689cf1 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerUtil.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DomainManagerUtil.java @@ -23,7 +23,6 @@ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java index 04c807cba8..d68cfa3786 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java @@ -39,7 +39,6 @@ import org.apache.tuscany.sca.data.collection.Item; import org.apache.tuscany.sca.data.collection.ItemCollection; import org.apache.tuscany.sca.data.collection.LocalItemCollection; import org.apache.tuscany.sca.data.collection.NotFoundException; -import org.apache.tuscany.sca.domain.search.DomainSearch; import org.osoa.sca.ServiceRuntimeException; import org.osoa.sca.annotations.Init; import org.osoa.sca.annotations.Reference; diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java index 6937a848c1..38a23f9023 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 @@ -17,6 +17,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.search.DomainSearch; +import org.apache.tuscany.sca.domain.search.IndexException; import org.apache.tuscany.sca.domain.search.Result; import org.apache.tuscany.sca.domain.search.impl.DomainSearchFormatter; import org.apache.tuscany.sca.domain.search.impl.HighlightingUtil; @@ -52,7 +53,7 @@ public class Searcher implements ItemCollection, LocalItemCollection { private int elementCounter; public void delete(String key) throws NotFoundException { - System.out.println("delete"); + } private static void startIndentation(int size, StringWriter writer) { @@ -159,7 +160,13 @@ public class Searcher implements ItemCollection, LocalItemCollection { for (Contribution contribution : contributions) { if (!contribution.getURI().equals(DomainManagerUtil.DEPLOYMENT_CONTRIBUTION_URI)) { - this.domainSearch.contributionUpdated(contribution, contribution); + + try { + this.domainSearch.updateContribution(contribution, contribution); + } catch (IndexException e) { + + } + } } } @@ -194,7 +201,7 @@ public class Searcher implements ItemCollection, LocalItemCollection { item.setContents("No results match: <u>" + query + "</u>"); } - System.out.println(item.getContents()); + // System.out.println(item.getContents()); return item; @@ -234,16 +241,6 @@ public class Searcher implements ItemCollection, LocalItemCollection { } } - // - // System.out.println("set-size: " + set.size()); - // for (char character : set) { - // System.out.print(","); - // System.out.print((int) character); - // System.out.print("/*" + character + "*/"); - // - // } - // - // System.out.println(); return sb.toString(); 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 8dc5d023dd..105d1acddb 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 @@ -310,7 +310,7 @@ <component name="DomainSearchComponent"> <implementation.java class="org.apache.tuscany.sca.domain.search.impl.DomainSearchImpl"/> - <!--<property name="indexDirectoryPath">domainSearchIndex</property> --> + <property name="indexDirectoryPath">domainSearchIndex</property> </component> </composite> diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java index d185bdf21d..47deb41a6f 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java @@ -23,6 +23,11 @@ import java.util.HashMap; import org.apache.tuscany.sca.domain.search.impl.Document; /** + * A map that holds a collection of {@link Document}s. Each {@link Document} key + * should ideally be something that is unique across the entire contribution + * documents. This class overrides {@link HashMap#get(Object)} method, so it + * adds an empty {@link Document} object if the specified key is not found in + * the map. * * @version $Rev$ $Date$ */ @@ -30,6 +35,14 @@ public class DocumentMap extends HashMap<Object, Document> { private static final long serialVersionUID = -2402910290314939928L; + /** + * Returns a {@link Document} object mapped from the specified key. If no + * {@link Document} object is found from the specified key, a empty + * {@link Document} object is created and added to the map. + * + * @param key the {@link Document} key + * @return the {@link Document} object mapped from the key + */ @Override public Document get(Object key) { Document doc = super.get(key); diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java index 3f23c4d354..0f183e8875 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java @@ -21,6 +21,9 @@ package org.apache.tuscany.sca.domain.search; import org.apache.tuscany.sca.domain.search.impl.Document; /** + * A {@link DocumentProcessor} implementations knows how to extract data from a + * contribution {@link Object}. The extract data is added to a {@link Document}, + * which is stored in a {@link DocumentMap}. * * @version $Rev$ $Date$ */ @@ -28,12 +31,34 @@ public interface DocumentProcessor { final public static Document FAKE_DOCUMENT = new Document(); + /** + * Process a contribution {@link Object}, extracting from it data that + * should be indexed. The data should be add to a {@link Document} object, + * which can be found accessing the {@link DocumentMap} if it's not passed + * as an argument. The key used to find the {@link Document} object should + * be the one returned by {@link #getDocumentKey(Object)} method. + * + * @param parentProcessor the processor that invoked this processor, if any + * @param documents the {@link DocumentMap} object + * @param object the object where data should be extracted from + * @param document the {@link Document} object to store the extracted data + * @param parent string that represent the object's parent path in the + * contribution + * @return the resulted {@link Document} object + */ Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document document, String parent); + /** + * Returns a object key generated from object passed as argument. The key + * should be unique in a contribution. + * + * @param object the object + * @return a key generated from the object + */ Object getDocumentKey(Object object); } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java index 065994319b..3f8ae0026b 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java @@ -19,129 +19,86 @@ package org.apache.tuscany.sca.domain.search; import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; import org.apache.tuscany.sca.domain.search.impl.Document; + /** + * This class is a {@link DocumentProcessor} that holds a map from {@link Class} + * -> {@link DocumentProcessor}, and based on this map this processor delegates + * the object to be processed to its respective {@link DocumentProcessor}. * * @version $Rev$ $Date$ */ -public class DocumentProcessorsMap extends - HashMap<Class<?>, List<DocumentProcessor>> implements DocumentProcessor { +public class DocumentProcessorsMap extends HashMap<Class<?>, DocumentProcessor> implements DocumentProcessor { private static final long serialVersionUID = 3967390896890947159L; - private Object documentKey; - - public void addDocumentProcessor(Class<?> clazz, DocumentProcessor processor) { - List<DocumentProcessor> processors = get(clazz); - - if (processors == null) { - processors = new LinkedList<DocumentProcessor>(); - put(clazz, processors); - - } - - processors.add(processor); - - } - - private void appendProcessors(LinkedList<DocumentProcessor> processorsList, - List<DocumentProcessor> processors, - Object object) { - - if (processors != null) { - - for (DocumentProcessor processor : processors) { - - if (this.documentKey == null) { - this.documentKey = processor.getDocumentKey(object); - - if (processorsList == null) { - return; - } - - } - - if (processorsList != null) { - processorsList.add(processor); - } - - } - - } - - } - - private void findAllDocumentProcessors(LinkedList<DocumentProcessor> processorsList, Object object) { - Class<?> clazz = object.getClass(); - appendProcessors(processorsList, get(clazz), object); + private DocumentProcessor findDocumentProcessor(Object object, Class<?> clazz) { + DocumentProcessor processor = get(clazz); - while (clazz != null) { + if (processor == null) { Class<?>[] interfaces = clazz.getInterfaces(); for (Class<?> interfac : interfaces) { - Class<?>[] interfaces2 = interfac.getInterfaces(); - appendProcessors(processorsList, get(interfac), object); + processor = findDocumentProcessor(object, interfac); - for (Class<?> interface2 : interfaces2) { - appendProcessors(processorsList, get(interface2), object); + if (processor != null) { + return processor; } } - clazz = clazz.getSuperclass(); - appendProcessors(processorsList, get(clazz), object); + if (!clazz.isInterface()) { + return findDocumentProcessor(object, clazz.getSuperclass()); + } } + return processor; + } + /** + * @see DocumentProcessor#getDocumentKey(Object) + */ public Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document document, String parent) { - LinkedList<DocumentProcessor> processorsList; - - try { - - this.documentKey = document; - processorsList = new LinkedList<DocumentProcessor>(); - findAllDocumentProcessors(processorsList, object); + DocumentProcessor processor = findDocumentProcessor(object, object.getClass()); - if (document == null && this.documentKey != null) { - document = documents.get(this.documentKey); + if (processor == null) { + throw new IllegalArgumentException(); + } - if (document == null) { - document = FAKE_DOCUMENT; - } + if (document == null) { + document = documents.get(processor.getDocumentKey(object)); + if (document == null) { + document = FAKE_DOCUMENT; } - } finally { - this.documentKey = null; } - for (DocumentProcessor processor : processorsList) { - processor.process(parentProcessor, documents, object, document, parent); - } + processor.process(parentProcessor, documents, object, document, parent); return document; } + /** + * @see DocumentProcessor#getDocumentKey(Object) + */ public Object getDocumentKey(Object object) { + DocumentProcessor processor = findDocumentProcessor(object, object.getClass()); - try { - findAllDocumentProcessors(null, object); - - return this.documentKey; + if (processor != null) { + return processor.getDocumentKey(object); - } finally { - this.documentKey = null; + } else { + return null; } } 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 53bcdbe4c3..be7f603b0b 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 @@ -18,48 +18,91 @@ */ package org.apache.tuscany.sca.domain.search; +import java.io.IOException; + +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.search.Query; import org.apache.tuscany.sca.contribution.Contribution; import org.osoa.sca.annotations.Remotable; /** + * This is the interface that must be implemented by the service that provides + * the functionality index/search and search contribution data. * * @version $Rev$ $Date$ */ @Remotable public interface DomainSearch { + /** + * Returns <code>true</code> if the index is somehow created already, otherwise <code>false</code>. + * + * @return <code>true</code> if the index is somehow created already, otherwise <code>false</code> + */ boolean indexExists(); - Result[] parseAndSearch(String searchQuery, boolean highlight) throws Exception; + /** + * Parse a query string, execute it against the index and return the results. + * + * @param searchQuery the string containing the search query + * @param highlight <code>true</code> if the results should be highlighted + * + * @return an array containing the search results + * + * @throws CorruptIndexException + * @throws IOException + * @throws ParseException + */ + Result[] parseAndSearch(String searchQuery, boolean highlight) throws IndexException, ParseException; - Result[] search(Query searchQuery, boolean hightlight) throws Exception; + /** + * Executes a search query against the index and return the results. + * + * @param searchQuery the search query + * @param hightlight highlight <code>true</code> if the results should be highlighted + * + * @return an array containing the search results + * + * @throws CorruptIndexException + * @throws IOException + */ + Result[] search(Query searchQuery, boolean hightlight) throws IndexException; - String highlight(String field, String text, String searchQuery) throws Exception; + /** + * Highlights in the specified text strings that matches the specified search query. The matches can be filtered by field. + * + * @param field the field to filter + * @param text the text to be highlighted + * @param searchQuery the search query + * + * @return the text highlighted + * + * @throws ParseException + * @throws IOException + */ + String highlight(String field, String text, String searchQuery) throws ParseException; /** - * Notifies the listener that a contribution has been added. + * Adds a contribution to the index. * - * @param repository The contribution repository - * @param contribution The new contribution + * @param contribution the contribution to be added */ - void contributionAdded(Contribution contribution); + void addContribution(Contribution contribution) throws IndexException; /** - * Notifies the listener that a contribution has been removed. + * Removes a contribution from the index. * - * @param repository The contribution repository - * @param contribution The removed contribution. + * @param contribution the contribution to be removed */ - void contributionRemoved(Contribution contribution); + void removeContribution(Contribution contribution) throws IndexException; /** - * Notifies the listener that a contribution has been updated. + * Updates a contribution in the index. * - * @param repository The contribution repository - * @param oldContribution The old contribution - * @param contribution The new contribution + * @param oldContribution the old contribution state + * @param contribution the new contribution state */ - void contributionUpdated(Contribution oldContribution, Contribution contribution); + void updateContribution(Contribution oldContribution, Contribution contribution) throws IndexException; } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchModuleActivator.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/IndexException.java index 5db27931b6..6c74c86387 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchModuleActivator.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/IndexException.java @@ -16,27 +16,30 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.tuscany.sca.domain.search.impl; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.ModuleActivator; +package org.apache.tuscany.sca.domain.search; /** + * Exception thrown when a exception occurs while accessing the index. * * @version $Rev$ $Date$ */ -public class DomainSearchModuleActivator implements ModuleActivator { +public class IndexException extends Exception { - public DomainSearchModuleActivator() { - // empty constructor - } + private static final long serialVersionUID = -6395734136706805723L; - public void start(ExtensionPointRegistry registry) { - registry.addExtensionPoint(new DefaultSearchContributionListenerExtensionPoint()); + /** + * @see Exception#Exception(String) + */ + public IndexException(String message) { + super(message); } - public void stop(ExtensionPointRegistry registry) { - // does nothing + /** + * @see Exception#Exception(String,Throwable) + */ + public IndexException(String message, Throwable cause) { + super(message, cause); } } 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 53fb9c4803..edbebac6b4 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 @@ -22,27 +22,100 @@ import java.io.Serializable; import java.util.Map; /** + * <p> + * The object that implements this interface carries a search's result data. + * </p> + * <p> + * A result contains a value, which is the value displayed to the user. It also + * contains a field name, which is the field the value is related to. + * </p> + * <p> + * A search result may be split into different {@link Result} objects, each one + * contained inside other, representing a complex result hierarchy. For example: + * a result structure may represent as result a folder and files/folders + * contained in it. + * </p> + * + * @see ResultProcessor + * @see ResultFactory * * @version $Rev$ $Date$ */ public interface Result extends Serializable { + /** + * Returns the value held by this object. + * + * @return the value held by this object + */ String getValue(); + /** + * Sets the result value. + * + * @param value the result value + */ void setValue(String value); + /** + * Returns the {@link Result} object that contains this object or + * <code>null</code> if it's not contained in any object. + * + * @return the {@link Result} object that contains this object or + * <code>null</code> if it's not contained in any object + */ Result getContainer(); + /** + * A {@link Map} containing {@link Result} objects contained in this + * {@link Object}. The contents are mapped from a key, which may be any kind + * of identifier, the identifier is chosen by the {@link Result} + * implementation. + * + * @return the contents map + */ Map<String, Result> getContents(); + /** + * Adds a {@link Result} content to this result. + * + * @param artifactResult the {@link Result} content + * @throw {@link UnsupportedOperationException} if the {@link Result} + * implementations does not support this operation + * @see #getContents() + */ void addContent(Result artifactResult); + /** + * Removes a {@link Result} content from this result. + * + * @param artifactResult the {@link Result} content + * @throw {@link UnsupportedOperationException} if the {@link Result} + * implementations does not support this operation + * @see #getContents() + */ void removeContent(Result artifactResult); + /** + * Sets this object's container. + * + * @param container the object's container + * @see #getContainer() + */ void setContainer(Result container); + /** + * Returns the field related to the result's value. + * + * @return the field name + */ String getField(); + /** + * Sets the field related to the result's value. + * + * @param field the field name + */ 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 dd4bc74284..7a4fb1f5f4 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 @@ -21,13 +21,31 @@ package org.apache.tuscany.sca.domain.search; import org.apache.lucene.document.Document; /** + * This interface should be implemented to provide a way to create + * {@link Result} objects from a field name and its value or a {@link Document} + * resulted from a search. * + * @see Result * @version $Rev$ $Date$ */ public interface ResultFactory<T extends Result> { + /** + * Creates a {@link Result} instance from a field name and its value. + * + * @param field the field name + * @param value the value + * @return the {@link Result} instance + */ T createResult(String field, String value); + /** + * Creates a {@link Result} instance from a {@link Document} object resulted + * from a search. + * + * @param document the result {@link Document} + * @return the {@link Result} instance + */ 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 90638cd2c8..8dee35623e 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 @@ -21,11 +21,30 @@ package org.apache.tuscany.sca.domain.search; import org.apache.lucene.document.Document; /** + * This interface should be implemented by classes that process a + * {@link Document} object resulted from a search and create a {@link Result} + * object from it. * * @version $Rev$ $Date$ */ public interface ResultProcessor { + /** + * <p> + * Process the {@link Document} object and returns a {@link Result} object + * containing the processed data. + * </p> + * <p> + * A {@link Result} object may be specified to hold the processed data. If + * no object is specified, the implementation must create a new object a + * return it. + * </p> + * + * @param document the {@link Document} object resulted from a search + * @param result the {@link Result} object that will hold the processed data + * or <code>null</code> a new object should be returned. + * @return a {@link Result} object containing the processed data + */ 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/SearchContributionListenerExtensionPoint.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/SearchContributionListenerExtensionPoint.java deleted file mode 100644 index 827cfce1d1..0000000000 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/SearchContributionListenerExtensionPoint.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.domain.search; - -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.service.ContributionRepository; - -/** - * - * @version $Rev$ $Date$ - */ -public interface SearchContributionListenerExtensionPoint { - - /** - * Notifies the listener that a contribution has been added. - * - * @param repository The contribution repository - * @param contribution The new contribution - */ - void contributionAdded(ContributionRepository repository, Contribution contribution); - - /** - * Notifies the listener that a contribution has been removed. - * - * @param repository The contribution repository - * @param contribution The removed contribution. - */ - void contributionRemoved(ContributionRepository repository, Contribution contribution); - - /** - * Notifies the listener that a contribution has been updated. - * - * @param repository The contribution repository - * @param oldContribution The old contribution - * @param contribution The new contribution - */ - void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution); - -} 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 92aae110b4..fcfce34d88 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 @@ -28,107 +28,80 @@ import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DocumentProcessor; /** - * * @version $Rev$ $Date$ */ public class ArtifactDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document document, - String parent) { - - if (object instanceof Artifact) { - Artifact artifact = (Artifact) object; - // String uri = artifact.getURI(); + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, + Object object, + Document document, + String parent) { - // 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 Artifact) { + Artifact artifact = (Artifact)object; - if (!(object instanceof Contribution)) { + if (!(object instanceof Contribution)) { - String location = artifact.getLocation(); + String location = artifact.getLocation(); - try { + try { - if (document == null) { - document = documents.get(SearchFields.ARTIFACT_FIELD + location); - } + if (document == null) { + document = documents.get(SearchFields.ARTIFACT_FIELD + location); + } - FileContent fileContent = new WrappedFileContent(new URL( - location)); + FileContent fileContent = new WrappedFileContent(new URL(location)); - document.add(new Field(SearchFields.ARTIFACT_FIELD, - fileContent.getName(), 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(); + parent += + DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.ARTIFACT_FIELD + + DomainPathAnalyzer.TYPE_SEPARATOR + + location + + DomainPathAnalyzer.URI_SEPARATOR + + fileContent.getName(); - // parent += DomainPathAnalyzer.PATH_SEPARATOR - // + SearchFields.FILE_FIELD - // + DomainPathAnalyzer.TYPE_SEPARATOR + location + - // DomainPathAnalyzer.URI_SEPARATOR + fileContent.getName(); + // parent += DomainPathAnalyzer.PATH_SEPARATOR + // + SearchFields.FILE_FIELD + // + DomainPathAnalyzer.TYPE_SEPARATOR + location + + // DomainPathAnalyzer.URI_SEPARATOR + fileContent.getName(); - Document fileDoc = parentProcessor.process(parentProcessor, - documents, fileContent, null, parent); + Document fileDoc = parentProcessor.process(parentProcessor, documents, fileContent, null, parent); - fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent, - Field.Store.YES, Field.Index.ANALYZED)); + fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED)); - } catch (IOException e) { - // ignore location - } + } catch (IOException e) { + // ignore location + } - } + } - return document == null ? FAKE_DOCUMENT : document; + return document == null ? FAKE_DOCUMENT : document; - } + } - throw new IllegalArgumentException(); + throw new IllegalArgumentException(); - } + } - public Object getDocumentKey(Object obj) { + public Object getDocumentKey(Object obj) { - if (obj instanceof Artifact) { - Artifact artifact = (Artifact) obj; - String uri = artifact.getLocation(); + if (obj instanceof Artifact) { + Artifact artifact = (Artifact)obj; + String uri = artifact.getLocation(); - if (uri != null && uri.length() == 0) { - return null; - } + if (uri != null && uri.length() == 0) { + return null; + } - return SearchFields.ARTIFACT_FIELD + uri; + return SearchFields.ARTIFACT_FIELD + uri; - } + } - throw new IllegalArgumentException(); + throw new IllegalArgumentException(); - } + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultSearchContributionListenerExtensionPoint.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultSearchContributionListenerExtensionPoint.java deleted file mode 100644 index 8ed859c2e6..0000000000 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultSearchContributionListenerExtensionPoint.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.domain.search.impl; - -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.service.ContributionRepository; -import org.apache.tuscany.sca.domain.search.SearchContributionListenerExtensionPoint; - -/** - * - * @version $Rev$ $Date$ - */ -public class DefaultSearchContributionListenerExtensionPoint implements SearchContributionListenerExtensionPoint { - - public void contributionAdded(ContributionRepository repository, Contribution contribution) { - System.out.println("contributionAdded:"); - System.out.println(repository); - System.out.println(contribution); - - } - - public void contributionRemoved(ContributionRepository repository, Contribution contribution) { - System.out.println("contributionRemoved:"); - System.out.println(repository); - System.out.println(contribution); - - } - - public void contributionUpdated(ContributionRepository repository, - Contribution oldContribution, - Contribution contribution) { - - System.out.println("contributionUpdated:"); - System.out.println(repository); - System.out.println(oldContribution); - System.out.println(contribution); - - } - -} 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 544da46dad..554da34ea1 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 @@ -28,7 +28,6 @@ import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; /** - * * @version $Rev$ $Date$ */ public class DomainSearchDocumentProcessorsMap extends DocumentProcessorsMap { @@ -36,15 +35,15 @@ public class DomainSearchDocumentProcessorsMap extends DocumentProcessorsMap { private static final long serialVersionUID = -4651637686945322606L; public DomainSearchDocumentProcessorsMap() { - addDocumentProcessor(Contribution.class, new ContributionDocumentProcessor()); - addDocumentProcessor(Artifact.class, new ArtifactDocumentProcessor()); - addDocumentProcessor(Property.class, new PropertyDocumentProcessor()); - addDocumentProcessor(ComponentType.class, new ComponentTypeDocumentProcessor()); - addDocumentProcessor(Binding.class, new BindingDocumentProcessor()); - addDocumentProcessor(Component.class, new ComponentDocumentProcessor()); - addDocumentProcessor(Composite.class, new CompositeDocumentProcessor()); - addDocumentProcessor(FileContent.class, new DomainSearchFileDocumentProcessor()); - addDocumentProcessor(Property.class, new PropertyDocumentProcessor()); + put(Contribution.class, new ContributionDocumentProcessor()); + put(Artifact.class, new ArtifactDocumentProcessor()); + put(Property.class, new PropertyDocumentProcessor()); + put(ComponentType.class, new ComponentTypeDocumentProcessor()); + put(Binding.class, new BindingDocumentProcessor()); + put(Component.class, new ComponentDocumentProcessor()); + put(Composite.class, new CompositeDocumentProcessor()); + put(FileContent.class, new DomainSearchFileDocumentProcessor()); + put(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/DomainSearchImpl.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java index 182f1d09ba..59b80ac026 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 @@ -19,7 +19,6 @@ package org.apache.tuscany.sca.domain.search.impl; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.util.HashSet; @@ -40,13 +39,13 @@ import org.apache.lucene.store.SimpleFSLockFactory; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DomainSearch; +import org.apache.tuscany.sca.domain.search.IndexException; 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; /** - * * @version $Rev$ $Date$ */ @Scope("COMPOSITE") @@ -75,7 +74,6 @@ public class DomainSearchImpl implements DomainSearch { public DomainSearchImpl() { this.qp.setAllowLeadingWildcard(true); - } private Directory getIndexDirectory() throws IOException { @@ -108,7 +106,7 @@ public class DomainSearchImpl implements DomainSearch { } @AllowsPassByReference - public void contributionAdded(Contribution contribution) { + public void addContribution(Contribution contribution) throws IndexException { IndexWriter indexWriter = null; @@ -132,7 +130,7 @@ public class DomainSearchImpl implements DomainSearch { } - throw new RuntimeException("Problem while indexing!", e); + throw new IndexException(e.getMessage(), e); } finally { @@ -152,7 +150,7 @@ public class DomainSearchImpl implements DomainSearch { } @AllowsPassByReference - public void contributionRemoved(Contribution contribution) { + public void removeContribution(Contribution contribution) throws IndexException { IndexWriter indexWriter = null; @@ -178,7 +176,7 @@ public class DomainSearchImpl implements DomainSearch { } - throw new RuntimeException("Problem while indexing!", e); + throw new IndexException(e.getMessage(), e); } finally { @@ -199,8 +197,7 @@ public class DomainSearchImpl implements DomainSearch { } - private void contributionRemoved(Contribution contribution, IndexWriter indexWriter) throws CorruptIndexException, - IOException { + private void contributionRemoved(Contribution contribution, IndexWriter indexWriter) throws IndexException { String contributionURI = contribution.getURI(); StringBuilder sb = new StringBuilder(SearchFields.PARENT_FIELD); @@ -218,14 +215,18 @@ public class DomainSearchImpl implements DomainSearch { indexWriter.deleteDocuments(query); } catch (ParseException e) { - throw new RuntimeException("Could not parse query: " + sb.toString(), e); + // ignore exception + + } catch (CorruptIndexException ex) { + throw new IndexException(ex.getMessage(), ex); + + } catch (IOException ex) { + throw new IndexException(ex.getMessage(), ex); } } - private void contributionAdded(Contribution contribution, IndexWriter indexWriter) throws CorruptIndexException, - IOException { - + private void contributionAdded(Contribution contribution, IndexWriter indexWriter) throws IndexException { DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap(); DocumentMap docs = new DocumentMap(); @@ -236,37 +237,30 @@ public class DomainSearchImpl implements DomainSearch { e.printStackTrace(); } - FileWriter writer = new FileWriter("indexed.txt"); + // 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.write(luceneDoc.toString()); + // writer.write('\n'); + // writer.write('\n'); + + try { + indexWriter.addDocument(luceneDoc); + + } catch (CorruptIndexException e) { + throw new IndexException(e.getMessage(), e); + + } catch (IOException e) { + throw new IndexException(e.getMessage(), e); + } + } - - 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); - // - // } + // writer.close(); } @AllowsPassByReference - public void contributionUpdated(Contribution oldContribution, Contribution contribution) { + public void updateContribution(Contribution oldContribution, Contribution contribution) throws IndexException { IndexWriter indexWriter = null; @@ -291,7 +285,7 @@ public class DomainSearchImpl implements DomainSearch { } - throw new RuntimeException("Problem while indexing!", e); + throw new IndexException(e.getMessage(), e); } finally { @@ -310,65 +304,53 @@ public class DomainSearchImpl implements DomainSearch { } - public Result[] parseAndSearch(String searchQuery, final boolean highlight) throws Exception { - - final IndexSearcher searcher = new IndexSearcher(getIndexDirectory()); - - DomainSearchResultProcessor resultProcessor = new DomainSearchResultProcessor(new DomainSearchResultFactory()); - - final Query query = qp.parse(searchQuery); - System.out.println("query: " + searchQuery); - - TopDocs topDocs = searcher.search(query, 1000); + public Result[] parseAndSearch(String searchQuery, final boolean highlight) throws IndexException, ParseException { + return search(this.qp.parse(searchQuery), highlight); + } - int indexed = 0; - HashSet<String> set = new HashSet<String>(); - for (ScoreDoc scoreDoc : topDocs.scoreDocs) { - org.apache.lucene.document.Document luceneDocument = searcher.doc(scoreDoc.doc); + public Result[] search(Query searchQuery, boolean highlight) throws IndexException { - resultProcessor.process(luceneDocument, null); + try { + final IndexSearcher searcher = new IndexSearcher(getIndexDirectory()); + DomainSearchResultProcessor resultProcessor = + new DomainSearchResultProcessor(new DomainSearchResultFactory()); + TopDocs topDocs = searcher.search(searchQuery, 1000); - indexed++; - set.add(luceneDocument.toString()); + int indexed = 0; + HashSet<String> set = new HashSet<String>(); + for (ScoreDoc scoreDoc : topDocs.scoreDocs) { + org.apache.lucene.document.Document luceneDocument = searcher.doc(scoreDoc.doc); - System.out.println(luceneDocument); + resultProcessor.process(luceneDocument, null); - } + indexed++; + set.add(luceneDocument.toString()); - /* - * 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(); - Result[] results = resultProcessor.createResultRoots(); + if (highlight) { - if (highlight) { + for (Result result : results) { + HighlightingUtil.highlightResult(result, searchQuery); + } - for (Result result : results) { - HighlightingUtil.highlightResult(result, query); } - } + return results; - return results; + } catch (CorruptIndexException ex) { + throw new IndexException(ex.getMessage(), ex); - } + } catch (IOException ex) { + throw new IndexException(ex.getMessage(), ex); + } - public Result[] search(Query searchQuery, boolean hightlight) { - // TODO Auto-generated method stub - return null; } - public String highlight(String field, String text, String searchQuery) throws Exception { - final Query query = qp.parse(searchQuery); + public String highlight(String field, String text, String searchQuery) throws ParseException { + final Query query = this.qp.parse(searchQuery); return HighlightingUtil.highlight(field, query, text); 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 cd253c4859..356eb88070 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 @@ -33,7 +33,6 @@ import org.apache.lucene.search.highlight.SpanScorer; import org.apache.tuscany.sca.domain.search.Result; /** - * * @version $Rev$ $Date$ */ final public class HighlightingUtil { @@ -53,22 +52,17 @@ final public class HighlightingUtil { } - 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); - } + String highlightedText = + HighlightingUtil.bestFragmentHighlighted(result.getField(), query, result.getValue(), fragmenter); - } catch (IOException e) { - // ignore highlighting + // checks if something was highlighted before resetting the value + if (highlightedText != null && highlightedText.length() > 0) { + result.setValue(highlightedText); } } - public static String highlight(String field, Query query, String text) throws IOException { + public static String highlight(String field, Query query, String text) { String highlightedText = bestFragmentHighlighted(field, query, text, new NullFragmenter()); if (highlightedText == null || text.length() >= highlightedText.length()) { @@ -83,26 +77,30 @@ final public class HighlightingUtil { 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(); + public static String bestFragmentHighlighted(String field, Query query, String text, Fragmenter fragmenter) { try { - return highlighter.getBestFragments(tokenStream, text, 2, " ... "); + 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(); - } catch (InvalidTokenOffsetsException e) { + try { + return highlighter.getBestFragments(tokenStream, text, 2, " ... "); - // could not create fragments, return empty string - return ""; + } catch (InvalidTokenOffsetsException e) { + // could not create fragments, return empty string + } + } catch (IOException ex) { + // should never happen } + return ""; + } public static String replaceHighlightMarkupBy(CharSequence text, String startHighlight, String endHighlight) { 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 index 0a1dfa75e9..78434d4c0d 100644 --- 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 @@ -25,7 +25,6 @@ import java.net.JarURLConnection; import java.net.URL; /** - * * @version $Rev$ $Date$ */ public class WrappedFileContent implements FileContent { @@ -37,49 +36,9 @@ public class WrappedFileContent implements FileContent { 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")) { |