ExtractorManager.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.apache.slide.extractor |
![]() |
![]() |
Jakarta Slide |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* $Header$
* $Revision: 360272 $
* $Date: 2005-12-31 06:47:45 -0500 (Sat, 31 Dec 2005) $
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed 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.slide.extractor;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.util.conf.Configurable;
import org.apache.slide.util.conf.Configuration;
import org.apache.slide.util.conf.ConfigurationException;
/**
* The ExtractorManager class
*
*/
public class ExtractorManager implements Configurable {
private final static ExtractorManager manager = new ExtractorManager();
private List extractors = new ArrayList();
private ExtractorManager() {}
public static ExtractorManager getInstance() {
return manager;
}
public void addExtractor(Extractor extractor) {
extractors.add(extractor);
}
public List getPropertyExtractors(String namespace, NodeRevisionDescriptors descriptors, NodeRevisionDescriptor descriptor) {
List matchingExtractors = new ArrayList();
for ( Iterator i = extractors.iterator(); i.hasNext(); ) {
Extractor extractor = (Extractor)i.next();
if ( extractor instanceof PropertyExtractor && matches(extractor, namespace, descriptors, descriptor)) {
matchingExtractors.add(extractor);
}
}
return matchingExtractors;
};
public List getContentExtractors(String namespace, NodeRevisionDescriptors descriptors, NodeRevisionDescriptor descriptor) {
List matchingExtractors = new ArrayList();
for ( Iterator i = extractors.iterator(); i.hasNext(); ) {
Extractor extractor = (Extractor)i.next();
if ( extractor instanceof ContentExtractor && matches(extractor, namespace, descriptors, descriptor)) {
matchingExtractors.add(extractor);
}
}
return matchingExtractors;
};
public List getContentExtractors(String namespace, String uri, NodeRevisionDescriptor descriptor) {
List matchingExtractors = new ArrayList();
for ( Iterator i = extractors.iterator(); i.hasNext(); ) {
Extractor extractor = (Extractor)i.next();
if ( extractor instanceof ContentExtractor && matches(extractor, namespace, uri, descriptor)) {
matchingExtractors.add(extractor);
}
}
return matchingExtractors;
};
public List getExtractors(String namespace, NodeRevisionDescriptors descriptors, NodeRevisionDescriptor descriptor) {
List matchingExtractors = new ArrayList();
for ( Iterator i = extractors.iterator(); i.hasNext(); ) {
Extractor extractor = (Extractor)i.next();
if ( matches(extractor, namespace, descriptors, descriptor)) {
matchingExtractors.add(extractor);
}
}
return matchingExtractors;
};
public boolean hasContentExtractor(String namespace,
String uri,
NodeRevisionDescriptor descriptor)
{
for ( Iterator i = extractors.iterator(); i.hasNext(); ) {
Extractor extractor = (Extractor)i.next();
if ( extractor instanceof ContentExtractor && matches(extractor, namespace, uri, descriptor)) {
return true;
}
}
return false;
};
static boolean matches(Extractor extractor, String namespace, NodeRevisionDescriptors descriptors, NodeRevisionDescriptor descriptor) {
boolean matching = true;
if ( descriptor != null && !extractor.isAcceptableContentType(descriptor.getContentType())) {
matching = false;
}
if ( descriptors != null && extractor.getUri() != null && !descriptors.getUri().startsWith(extractor.getUri()) ) {
matching = false;
}
if ( extractor.getNamespace() != null && !extractor.getNamespace().equals(namespace)) {
matching = false;
}
return matching;
}
static boolean matches(Extractor extractor, String namespace, String uri, NodeRevisionDescriptor descriptor) {
if ( descriptor != null && !extractor.isAcceptableContentType(descriptor.getContentType()) ) {
return false;
}
if ( extractor.getUri() != null && !uri.startsWith(extractor.getUri()) ) {
return false;
}
if ( extractor.getNamespace() != null && !extractor.getNamespace().equals(namespace)) {
return false;
}
return true;
}
public void configure(Configuration config) throws ConfigurationException {
Enumeration extractorConfigs = config.getConfigurations("extractor");
while (extractorConfigs.hasMoreElements()) {
Configuration extractorConfig = (Configuration)extractorConfigs.nextElement();
String classname = extractorConfig.getAttribute("classname");
String uri = extractorConfig.getAttribute("uri", null);
String contentType = extractorConfig.getAttribute("content-type", null);
String namespace = extractorConfig.getAttribute("namespace", null);
try {
Class extractorClass = Class.forName(classname);
Extractor extractor = null;
try {
Constructor extractorConstructor = extractorClass.getConstructor(new Class[] { String.class, String.class, String.class } );
extractor = (Extractor) extractorConstructor.newInstance(new String[] { uri, contentType, namespace });
}
catch (NoSuchMethodException e) {
Constructor extractorConstructor = extractorClass.getConstructor(new Class[] { String.class, String.class } );
extractor = (Extractor) extractorConstructor.newInstance(new String[] { uri, contentType });
}
if ( extractor instanceof Configurable ) {
((Configurable)extractor).configure(extractorConfig.getConfiguration("configuration"));
}
addExtractor(extractor);
} catch (ClassCastException e) {
throw new ConfigurationException("Extractor '"+classname+"' is not of type Extractor", config);
} catch (ConfigurationException e) {
throw e;
} catch (Exception e) {
throw new ConfigurationException("Extractor '"+classname+"' could not be loaded", config);
}
}
}
}
The table below shows all metrics for ExtractorManager.java.




