001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.search.filters;
019:
020: import de.finix.contelligent.CallData;
021: import de.finix.contelligent.Component;
022: import de.finix.contelligent.ComponentCreationException;
023: import de.finix.contelligent.ComponentLink;
024: import de.finix.contelligent.ComponentNotFoundException;
025: import de.finix.contelligent.ComponentPath;
026: import de.finix.contelligent.search.engine.CrawlerFilter;
027: import de.finix.contelligent.search.engine.FilterException;
028: import de.finix.contelligent.xml.elements.IndexBuilderFilterElement;
029:
030: public class LinkTargetType implements CrawlerFilter {
031:
032: /**
033: *
034: */
035: public LinkTargetType() {
036: super ();
037: }
038:
039: /*
040: * (non-Javadoc)
041: *
042: * @see de.finix.contelligent.search.engine.CrawlerFilter#filter(de.finix.contelligent.Component,
043: * de.finix.contelligent.xml.elements.IndexBuilderFilterElement,
044: * de.finix.contelligent.CallData)
045: */
046: public boolean filter(ComponentPath componentPath,
047: IndexBuilderFilterElement configuration, CallData callData)
048: throws FilterException {
049:
050: String[] args = configuration.getStringArgs();
051:
052: if (args.length != 1)
053: throw new FilterException(
054: "ParentHasSubcomponentValue Filter needs 1 arguments: [type]");
055:
056: // the subcomponent Name to use to test a parent
057: String type = args[0];
058:
059: Component component = null;
060: try {
061: component = callData.getActualManager().getComponent(
062: componentPath, callData, false);
063: } catch (ComponentCreationException e) {
064: throw new FilterException(
065: "ERROR: Filtered Component could not be created", e);
066: } catch (ComponentNotFoundException e) {
067: throw new FilterException(
068: "ERROR: Filtered Component could not be resolved",
069: e);
070: }
071:
072: if (component.getComponentContext().getType().isInstanceOf(
073: "contelligent.core.Link")) {
074: ComponentLink link = (ComponentLink) component;
075: ComponentPath targetPath = link.getTargetPath();
076: Component target = null;
077: try {
078: target = callData.getActualManager().getComponent(
079: targetPath, callData);
080: } catch (ComponentCreationException e) {
081: throw new FilterException(
082: "ERROR: linkedComponent could not be created",
083: e);
084: } catch (ComponentNotFoundException e) {
085: throw new FilterException(
086: "ERROR: linkedComponent does not exist", e);
087: }
088: if (target.getComponentContext().getType().isInstanceOf(
089: type)) {
090: return true;
091: }
092: }
093: return false;
094: }
095:
096: /*
097: * (non-Javadoc)
098: *
099: * @see de.finix.contelligent.search.engine.CrawlerFilter#supportsNestedFilters()
100: */
101: public boolean supportsNestedFilters() {
102: return false;
103: }
104:
105: }
|