http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/OpendapProfileElementExtractor.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/OpendapProfileElementExtractor.java b/opendapps/src/main/java/org/apache/oodt/opendapps/OpendapProfileElementExtractor.java deleted file mode 100644 index 04f5089..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/OpendapProfileElementExtractor.java +++ /dev/null @@ -1,174 +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.oodt.opendapps; - -//OODT imports -import org.apache.oodt.opendapps.config.OpendapConfig; -import org.apache.oodt.profile.EnumeratedProfileElement; -import org.apache.oodt.profile.Profile; -import org.apache.oodt.profile.RangedProfileElement; - -//JDK imports -import java.util.Arrays; -import java.util.Enumeration; -import java.util.logging.Level; -import java.util.logging.Logger; - -//OPeNDAP/THREDDS imports -import opendap.dap.Attribute; -import opendap.dap.AttributeTable; -import opendap.dap.DAS; -import opendap.dap.NoSuchAttributeException; - -import static org.apache.oodt.opendapps.DapNames.*; - -/** - * - * - * This class is used to set custom functionality for scraping data into - * different types of objects. The class looks at the {@link OpendapConfig} and - * then tries to stuff what's in each <var> into - * {@link RangedProfileElement} or {@link EnumeratedProfileElement}. The class - * is designed with extensibility in mind in case new {@link org.apache.oodt.profile.ProfileElement} - * types are created in the future. - * - */ -public class OpendapProfileElementExtractor { - - private static final Logger LOG = Logger - .getLogger(OpendapProfileElementExtractor.class.getName()); - - private OpendapConfig conf; - - public OpendapProfileElementExtractor(OpendapConfig conf) { - this.conf = conf; - } - - public RangedProfileElement extractRangedProfileElement(String elemName, String varname, - Profile profile, DAS das) throws NoSuchAttributeException { - RangedProfileElement elem = new RangedProfileElement(profile); - elem.setName(elemName); - AttributeTable attTable; - try { - attTable = das.getAttributeTable(varname); - - // make variable names case insensitive - if(attTable == null) { - attTable = das.getAttributeTable(varname.toLowerCase()); - } - if(attTable == null) { - attTable = das.getAttributeTable(varname.toUpperCase()); - } - if(attTable == null) { - throw new NoSuchAttributeException("Att table for [" + varname + "] is null!"); - } - } catch (NoSuchAttributeException e) { - LOG.log(Level.SEVERE, e.getMessage()); - LOG.log(Level.WARNING, "Error extracting attribute table for element: [" - + elemName + "]: Message: " + e.getMessage()); - throw e; - - } - - Enumeration attributeNames = attTable.getNames(); - - while (attributeNames.hasMoreElements()) { - String attrName = (String) attributeNames.nextElement(); - Attribute attr = attTable.getAttribute(attrName); - - if (!attr.isContainer()) { - Enumeration attrValues; - - try { - attrValues = attr.getValues(); - } catch (NoSuchAttributeException e) { - LOG.log(Level.SEVERE, e.getMessage()); - LOG.log(Level.WARNING, "Attempt to resolve attribute: [" + attrName - + "] failed: Message: " + e.getMessage()); - continue; - } - - while (attrValues.hasMoreElements()) { - String attrValue = (String) attrValues.nextElement(); - if (attrName.equals(ACTUAL_RANGE)) { - elem.setMinValue(attrValue); - if (attrValues.hasMoreElements()) { - elem.setMaxValue((String) attrValues.nextElement()); - } - } else if (attrName.equals(UNITS)) { - elem.setUnit(attrValue); - } else if (attrName.equals(START)) { - elem.setMinValue(attrValue); - } else if (attrName.equals(END)) { - elem.setMaxValue(attrValue); - } - } - } - - } // not a container attribute - - return elem; - } - - @SuppressWarnings("unchecked") - public EnumeratedProfileElement extractEnumeratedProfileElement(String elemName, String varname, - Profile profile, DAS das) - throws NoSuchAttributeException { - EnumeratedProfileElement elem = new EnumeratedProfileElement(profile); - elem.setName(elemName); - - AttributeTable attTable; - try { - attTable = das.getAttributeTable(elemName); - } catch (NoSuchAttributeException e) { - LOG.log(Level.WARNING, "Error extracting attribute table for element: [" - + elemName + "]: Message: " + e.getMessage()); - throw e; - - } - - Enumeration attributeNames = attTable.getNames(); - while (attributeNames.hasMoreElements()) { - String attrName = (String) attributeNames.nextElement(); - Attribute attr = attTable.getAttribute(attrName); - Enumeration attrValues; - try { - attrValues = attr.getValues(); - } catch (NoSuchAttributeException e) { - LOG.log(Level.WARNING, "Attempt to resolve attribute: [" + attrName - + "] failed: Message: " + e.getMessage()); - continue; - } - - while (attrValues.hasMoreElements()) { - String attrValue = (String) attrValues.nextElement(); - if (attrName.equals(ACTUAL_RANGE)) { - String[] vals = attrValue.split(" "); - elem.getValues().addAll(Arrays.asList(vals)); - } else if (attrName.equals(UNITS)) { - elem.setUnit(attrValue); - } else { - elem.getValues().add(attrValue); - } - } - - } - - return elem; - } - -}
http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/OpendapProfileHandler.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/OpendapProfileHandler.java b/opendapps/src/main/java/org/apache/oodt/opendapps/OpendapProfileHandler.java deleted file mode 100644 index 871cd0c..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/OpendapProfileHandler.java +++ /dev/null @@ -1,186 +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.oodt.opendapps; - -//JDK imports -import java.io.FileNotFoundException; -import java.net.MalformedURLException; -import java.util.List; -import java.util.Vector; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import opendap.dap.DConnect; - -import org.apache.oodt.cas.metadata.Metadata; -import org.apache.oodt.opendapps.config.DapRoot; -import org.apache.oodt.opendapps.config.OpendapConfig; -import org.apache.oodt.opendapps.config.OpendapConfigReader; -import org.apache.oodt.opendapps.extractors.DasMetadataExtractor; -import org.apache.oodt.opendapps.extractors.MetadataExtractor; -import org.apache.oodt.opendapps.extractors.NcmlMetadataExtractor; -import org.apache.oodt.opendapps.extractors.ThreddsMetadataExtractor; -import org.apache.oodt.opendapps.util.ProfileUtils; -import org.apache.oodt.profile.Profile; -import org.apache.oodt.profile.ProfileException; -import org.apache.oodt.profile.handlers.ProfileHandler; -import org.apache.oodt.xmlquery.XMLQuery; - -/** - * - * - * A generic reusable OODT {@link ProfileHandler} for use in extracting metadata - * from OPeNDAP and THREDDS-accessible datasets. - * - */ -public class OpendapProfileHandler implements ProfileHandler { - - private static final String PROFILE_HANDLER_ID = "OODT OPeNDAP Profile Handler"; - - private static Logger LOG = Logger.getLogger(OpendapProfileHandler.class - .getName()); - - private OpendapConfig conf; - - public OpendapProfileHandler(){ - } - - /** - * Implementation of interface method - */ - public List<Profile> findProfiles(XMLQuery xmlQuery) throws ProfileException { - String configFileLoc = null; - String q = xmlQuery.getKwdQueryString(); - if (q.contains("ConfigUrl=")){ - Pattern parameterPattern = Pattern.compile("ConfigUrl=(.+?)( .*)?$"); - Matcher fileMatch = parameterPattern.matcher(q); - while (fileMatch.find()) { - configFileLoc = fileMatch.group(1); - } - } else { - configFileLoc = System.getProperty("org.apache.oodt.opendap.config.filePath"); - } - - if (configFileLoc.isEmpty()){ - throw new ProfileException( - "Configuration file not found. Please specify in System property opendap.config.filePath or as URL parameter ConfigUrl"); - } else { - try { - this.conf = OpendapConfigReader.read(configFileLoc); - } catch (FileNotFoundException e) { - throw new ProfileException("FileNotFoundException: File not found!"); - } catch (MalformedURLException e) { - throw new ProfileException("MalformedURLException: please fix file URL"); - } - } - - List<Profile> profiles = new Vector<Profile>(); - List<DapRoot> roots = this.conf.getRoots(); - - // loop over THREDDS catalogs - for (DapRoot root : roots) { - LOG.log(Level.INFO,"Parsing DapRoot="+root.getDatasetUrl()); - - DatasetExtractor d = new DatasetExtractor(xmlQuery, root.getCatalogUrl() - .toExternalForm(), root.getDatasetUrl().toExternalForm(), conf); - if (d.getDapUrls() != null) { - for (String opendapUrl : d.getDapUrls()) { - - // wrap the profile generation in try-catch to avoid stopping the whole harvesting process in case an exception is thrown - try { - - LOG.log(Level.FINE,"Connecting to opendapurl="+opendapUrl); - - Profile profile = new Profile(); - DConnect dConn; - try { - dConn = new DConnect(opendapUrl, true); - } catch (FileNotFoundException e) { - LOG.log(Level.WARNING, "Opendap URL not found: [" + opendapUrl - + "]: Message: " + e.getMessage()); - throw new ProfileException("Opendap URL not found: [" + opendapUrl - + "]: Message: " + e.getMessage()); - } - - // retrieve already extracted THREDDS metadata - Metadata datasetMet = d.getDatasetMet(opendapUrl); - - // extract DAS metadata - MetadataExtractor dasExtractor = new DasMetadataExtractor(dConn); - dasExtractor.extract(datasetMet, conf); - - // extract NcML metadata, if available - if (datasetMet.containsKey(ThreddsMetadataExtractor.SERVICE_TYPE_NCML)) { - // retrieve URL of NcML document, previously stored - final String ncmlUrl = datasetMet.getMetadata(ThreddsMetadataExtractor.SERVICE_TYPE_NCML); - MetadataExtractor ncmlExtractor = new NcmlMetadataExtractor(ncmlUrl); - ncmlExtractor.extract(datasetMet, conf); - } - - // debug: write out all metadata entries - for (String key : datasetMet.getAllKeys()) { - LOG.log(Level.FINER, "Metadata key="+key+" value="+datasetMet.getMetadata(key)); - } - - // <resAttributes> - profile.setResourceAttributes(ProfileUtils.getResourceAttributes( - this.conf, opendapUrl, dConn, datasetMet)); - - // <profAttributes> - profile.setProfileAttributes(ProfileUtils - .getProfileAttributes(this.conf, datasetMet)); - // <profElement> - profile.getProfileElements().putAll( - ProfileUtils.getProfileElements(this.conf, dConn, datasetMet, profile)); - profiles.add(profile); - LOG.log(Level.FINE, "Added profile id="+profile.getProfileAttributes().getID()); - - - } catch(Exception e) { - // in case of exception, don't harvest this dataset, but keep going - LOG.log(Level.WARNING,"Error while building profile for opendapurl="+opendapUrl); - LOG.log(Level.WARNING,e.getMessage()); - } - - } - } - } - return profiles; - } - - /* - * (non-Javadoc) - * - * @see org.apache.oodt.profile.handlers.ProfileHandler#get(java.lang.String) - */ - public Profile get(String id) throws ProfileException { - throw new ProfileException("method not implemented yet!"); - } - - /* - * (non-Javadoc) - * - * @see org.apache.oodt.profile.handlers.ProfileHandler#getID() - */ - public String getID() { - return PROFILE_HANDLER_ID; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/Profiler.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/Profiler.java b/opendapps/src/main/java/org/apache/oodt/opendapps/Profiler.java deleted file mode 100644 index 8884db9..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/Profiler.java +++ /dev/null @@ -1,155 +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.oodt.opendapps; - -//JDK imports -import java.io.File; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -//OODT imports -import org.apache.commons.io.FileUtils; -import org.apache.oodt.opendapps.util.ProfileChecker; -import org.apache.oodt.opendapps.util.ProfileSerializer; -import org.apache.oodt.profile.Profile; -import org.apache.oodt.profile.handlers.ProfileHandler; -import org.apache.oodt.xmlquery.XMLQuery; -import org.xml.sax.SAXException; - -/** - * Command line class to drive the creation of OODT profiles from THREDDS - * catalogs with OpenDAP endpoints. - * <p/> - * This class reads the list of THREDDS catalog URLs from the given opendapps - * configuration file, parses the catalogs, and it writes the OODT profiles (one - * for each THREDDS dataset) in the file "profiles.xml" in the specified - * directory, or in the local execution directory if none is specified. - * <p/> - * Usage: java -classpath [path to opendapps-version-jar-with-dependencies.jar] - * org.apache.oodt.opendapps.Profiler [config_file_location] - * [optional_output_dir] - * <p/> - * Usage example: java -classpath - * ./target/opendapps-0.4-SNAPSHOT-jar-with-dependencies.jar - * org.apache.oodt.opendapps.Profiler /home/users/testuser/opendap.config.xml - * /tmp - * - * @author Luca Cinquini - * - */ -public class Profiler { - - private static Logger LOG = Logger.getLogger(Profiler.class.getName()); - - /** - * Optional directory to serialize the profiles to. - */ - private File outputDir; - - /** - * Command line invocation method. - * - * @param args - */ - public static void main(String[] args) throws Exception { - - // parse command line input - if (args.length != 1 && args.length != 2) { - usage(); - } - File configFile = new File(args[0]); - Profiler profiler = new Profiler(); - if (args.length == 2) { - profiler.setOutputDir( new File(args[1]) ); - } - - // run profiler - profiler.makeProfiles(configFile); - - } - - /** - * No argument constructor. - */ - public Profiler() {} - - /** - * Setter method for output directory. - * @param outputDir - */ - public void setOutputDir(File outputDir) { - this.outputDir = outputDir; - } - - /** - * Method to generate OODT profiles according to the specifications contained in a configuration file. - * - * @param configFile - * @return - */ - public List<Profile> makeProfiles(final File configFile) throws Exception { - - // parse THREDDS catalogs, create OODT profiles - ProfileHandler profileHandler = new OpendapProfileHandler(); - XMLQuery xmlQuery = Profiler.buildXMLQuery(configFile); - @SuppressWarnings(value = "unchecked") - final List<Profile> profiles = profileHandler.findProfiles(xmlQuery); - - // check profiles - for (final Profile profile : profiles) { - final StringBuilder sb = new StringBuilder(); - boolean ok = ProfileChecker.check(profile, sb); - // print out the profile summary for quick review by the publisher - System.out.println(sb.toString()); - if (!ok) { - LOG.log(Level.SEVERE, "ERROR: invalid profile:"+profile.getResourceAttributes().getIdentifier()); - } - } - - // serialize profiles to XML - String xml = ProfileSerializer.toXML(profiles); - LOG.log(Level.FINE, xml); - - // write XML to disk - if (outputDir != null) { - final File file = new File(outputDir, "profiles.xml"); - FileUtils.writeStringToFile(file, xml); - } - - return profiles; - - } - - private static XMLQuery buildXMLQuery(final File file) throws SAXException { - - final String query = "<query><queryKWQString>" - + "PFunction=findall?ConfigUrl=" + file.getAbsolutePath() - + "</queryKWQString></query>"; - return new XMLQuery(query); - - } - - private static void usage() { - System.out - .println("Usage: java -classpath [path to opendapps-version-jar-with-dependencies.jar] org.apache.oodt.opendapps.Profiler <config file location> [<output_dir>]"); - System.out - .println("Example: java -classpath ./target/opendapps-0.4-SNAPSHOT-jar-with-dependencies.jar org.apache.oodt.opendapps.Profiler /home/users/testuser/opendap.config.xml /tmp"); - System.exit(-1); - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/config/ConstantSpec.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/config/ConstantSpec.java b/opendapps/src/main/java/org/apache/oodt/opendapps/config/ConstantSpec.java deleted file mode 100644 index 118621e..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/config/ConstantSpec.java +++ /dev/null @@ -1,86 +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.oodt.opendapps.config; - -/** - * - * A specification of a constant field to flow through into either the generated - * {@link org.apache.oodt.profile.Profile}s {@link org.apache.oodt.profile.ProfileAttributes} section or its - * {@link org.apache.oodt.profile.ResourceAttributes} section. Part of the {@link OpendapConfig}. - * - */ -public class ConstantSpec { - - private String type; - - private String name; - - private String value; - - public ConstantSpec() { - this.type = null; - this.name = null; - this.value = null; - } - - /** - * @return the type - */ - public String getType() { - return type; - } - - /** - * @param type - * the type to set - */ - public void setType(String type) { - this.type = type; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name - * the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the value - */ - public String getValue() { - return value; - } - - /** - * @param value - * the value to set - */ - public void setValue(String value) { - this.value = value; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/config/DapRoot.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/config/DapRoot.java b/opendapps/src/main/java/org/apache/oodt/opendapps/config/DapRoot.java deleted file mode 100644 index 2784368..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/config/DapRoot.java +++ /dev/null @@ -1,88 +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.oodt.opendapps.config; - -//JDK imports -import java.net.URL; - -/** - * - * A set of root {@link URL} information for OPeNDAP/THREDDS catalogs to crawl - * and obtain dataset metadata from. - * - */ -public class DapRoot { - - private URL datasetUrl; - - private URL catalogUrl; - - private String filter; - - public DapRoot() { - this.datasetUrl = null; - this.catalogUrl = null; - this.filter = null; - } - - /** - * @return the datasetUrl - */ - public URL getDatasetUrl() { - return datasetUrl; - } - - /** - * @param datasetUrl - * the datasetUrl to set - */ - public void setDatasetUrl(URL datasetUrl) { - this.datasetUrl = datasetUrl; - } - - /** - * @return the catalogUrl - */ - public URL getCatalogUrl() { - return catalogUrl; - } - - /** - * @param catalogUrl - * the catalogUrl to set - */ - public void setCatalogUrl(URL catalogUrl) { - this.catalogUrl = catalogUrl; - } - - /** - * @return the filter - */ - public String getFilter() { - return filter; - } - - /** - * @param filter - * the filter to set - */ - public void setFilter(String filter) { - this.filter = filter; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/config/DatasetMetElem.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/config/DatasetMetElem.java b/opendapps/src/main/java/org/apache/oodt/opendapps/config/DatasetMetElem.java deleted file mode 100644 index 2c1f10a..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/config/DatasetMetElem.java +++ /dev/null @@ -1,68 +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.oodt.opendapps.config; - - -/** - * - * Specification for the {@link OpendapConfig} that specifies what THREDDS - * dataset met to use to create {@link org.apache.oodt.profile.EnumeratedProfileElement}s from. - * - */ -public class DatasetMetElem { - - private String profileElementName; - - private String value; - - public DatasetMetElem() { - this.profileElementName = null; - this.value = null; - } - - /** - * @return the profileElementName - */ - public String getProfileElementName() { - return profileElementName; - } - - /** - * @param profileElementName - * the profileElementName to set - */ - public void setProfileElementName(String profileElementName) { - this.profileElementName = profileElementName; - } - - /** - * @return the value - */ - public String getValue() { - return value; - } - - /** - * @param value - * the value to set - */ - public void setValue(String value) { - this.value = value; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfig.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfig.java b/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfig.java deleted file mode 100644 index 7d9dacb..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfig.java +++ /dev/null @@ -1,128 +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.oodt.opendapps.config; - -//JDK imports -import java.util.List; -import java.util.Vector; - -/** - * - * The configuration object for the {@link OpendapProfileHandler}. - * - */ -public class OpendapConfig { - - private List<DapRoot> roots; - - private List<RewriteSpec> rewriteSpecs; - - private List<ConstantSpec> constSpecs; - - private List<DatasetMetElem> datasetMetSpecs; - - private ProcessingInstructions processingInstructions; - - public OpendapConfig() { - this.roots = new Vector<DapRoot>(); - this.rewriteSpecs = new Vector<RewriteSpec>(); - this.constSpecs = new Vector<ConstantSpec>(); - this.datasetMetSpecs = new Vector<DatasetMetElem>(); - this.processingInstructions = new ProcessingInstructions(); - } - - /** - * @return the roots - */ - public List<DapRoot> getRoots() { - return roots; - } - - /** - * @param roots - * the roots to set - */ - public void setRoots(List<DapRoot> roots) { - this.roots = roots; - } - - /** - * @return the rewriteSpecs - */ - public List<RewriteSpec> getRewriteSpecs() { - return rewriteSpecs; - } - - /** - * @param rewriteSpecs - * the rewriteSpecs to set - */ - public void setRewriteSpecs(List<RewriteSpec> rewriteSpecs) { - this.rewriteSpecs = rewriteSpecs; - } - - /** - * @return the constSpecs - */ - public List<ConstantSpec> getConstSpecs() { - return constSpecs; - } - - /** - * @param constSpecs - * the constSpecs to set - */ - public void setConstSpecs(List<ConstantSpec> constSpecs) { - this.constSpecs = constSpecs; - } - - /** - * @return the datasetMetSpecs - */ - public List<DatasetMetElem> getDatasetMetSpecs() { - return datasetMetSpecs; - } - - /** - * @param datasetMetSpecs - * the datasetMetSpecs to set - */ - public void setDatasetMetSpecs(List<DatasetMetElem> datasetMetSpecs) { - this.datasetMetSpecs = datasetMetSpecs; - } - - /** - * Returns all processing instructions. - * - * @return the processingInstructions - */ - public ProcessingInstructions getProcessingInstructions() { - return this.processingInstructions; - } - - /** - * Adds a processing instruction. - * - * @param key - * @param value - */ - public void addProcessingInstruction(String key, String value) { - this.processingInstructions.addInstruction(key, value); - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfigMetKeys.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfigMetKeys.java b/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfigMetKeys.java deleted file mode 100644 index cf68dab..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfigMetKeys.java +++ /dev/null @@ -1,87 +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.oodt.opendapps.config; - -/** - * - * A set of metadata keys for reading the {@link OpendapConfig}. - * - */ -public interface OpendapConfigMetKeys { - - String RES_ATTR_SPEC_TYPE = "resAttr"; - - String PROF_ATTR_SPEC_TYPE = "profAttr"; - - String PROF_ELEM_SPEC_TYPE = "profElem"; - - String ENUM_ELEMENT_TYPE = "EnumeratedProfileElement"; - - String RANGED_ELEMENT_TYPE = "RangedProfileElement"; - - String DAP_ROOT_TAG = "root"; - - String DATASET_URL_ATTR = "datasetURL"; - - String CATALOG_URL_ATTR = "catalogURL"; - - String FILTER_ATTR = "filter"; - - String REWRITE_ROOT_TAG = "rewrite"; - - String REWRITE_VAR_TAG = "var"; - - String REWRITE_VAR_NAME_ATTR = "name"; - - String REWRITE_VAR_RENAME_ATTR = "rename"; - - String REWRITE_VAR_TYPE_ATTR = "type"; - - String CONSTANT_ROOT_TAG = "constants"; - - String CONSTANT_TAG = "const"; - - String CONSTANT_NAME_ATTR = "name"; - - String CONSTANT_TYPE_ATTR = "type"; - - String CONSTANT_VALUE_ATTR = "value"; - - String DATASET_MET_ROOT_TAG = "datasetMetadata"; - - String DATASET_MET_ELEM_TAG = "elem"; - - String DATASET_MET_NAME_ATTR = "name"; - - String DATASET_MET_VALUE_ATTR = "value"; - - String RES_LOCATION_ATTR = "resLocation"; - - String PROCESSING_INSTRUCTIONS_TAG = "processingInstructions"; - - String PROCESSING_INSTRUCTION_TAG = "processingInstruction"; - - String PROCESSING_INSTRUCTION_NAME_ATTR = "name"; - - String PROCESSING_INSTRUCTION_VALUE_ATTR = "value"; - - String EXCLUDE_VARIABLES_ATTR = "excludeVariables"; - - String DATETIME_FORMAT_ATTR = "datetimeFormat"; - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfigReader.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfigReader.java b/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfigReader.java deleted file mode 100644 index 4137805..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapConfigReader.java +++ /dev/null @@ -1,133 +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.oodt.opendapps.config; - -// OODT imports -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.CATALOG_URL_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.CONSTANT_NAME_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.CONSTANT_ROOT_TAG; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.CONSTANT_TAG; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.CONSTANT_TYPE_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.CONSTANT_VALUE_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.DAP_ROOT_TAG; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.DATASET_MET_ELEM_TAG; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.DATASET_MET_NAME_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.DATASET_MET_ROOT_TAG; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.DATASET_MET_VALUE_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.DATASET_URL_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.FILTER_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.PROCESSING_INSTRUCTIONS_TAG; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.PROCESSING_INSTRUCTION_NAME_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.PROCESSING_INSTRUCTION_TAG; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.PROCESSING_INSTRUCTION_VALUE_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.REWRITE_ROOT_TAG; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.REWRITE_VAR_NAME_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.REWRITE_VAR_RENAME_ATTR; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.REWRITE_VAR_TAG; -import static org.apache.oodt.opendapps.config.OpendapConfigMetKeys.REWRITE_VAR_TYPE_ATTR; - -//JDK imports -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.net.MalformedURLException; -import java.net.URL; - -import org.apache.oodt.commons.xml.XMLUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * - * Reads the {@link OpendapConfig} from a provided file and returns it. - * - */ -public class OpendapConfigReader { - - public static OpendapConfig read(String confFilePath) - throws FileNotFoundException, MalformedURLException { - OpendapConfig conf = new OpendapConfig(); - Document doc = XMLUtils.getDocumentRoot(new FileInputStream(new File( - confFilePath))); - Element rootElem = doc.getDocumentElement(); - - NodeList dapRootNodeList = rootElem.getElementsByTagName(DAP_ROOT_TAG); - for (int i = 0; i < dapRootNodeList.getLength(); i++) { - Element dapRootElem = (Element) dapRootNodeList.item(i); - DapRoot root = new DapRoot(); - root.setCatalogUrl(new URL(dapRootElem.getAttribute(CATALOG_URL_ATTR))); - root.setDatasetUrl(new URL(dapRootElem.getAttribute(DATASET_URL_ATTR))); - root.setFilter(dapRootElem.getAttribute(FILTER_ATTR)); - conf.getRoots().add(root); - } - - Element rewriteRootElem = XMLUtils.getFirstElement(REWRITE_ROOT_TAG, - rootElem); - NodeList rewriteNodeList = rewriteRootElem - .getElementsByTagName(REWRITE_VAR_TAG); - for (int i = 0; i < rewriteNodeList.getLength(); i++) { - Element rewriteElem = (Element) rewriteNodeList.item(i); - RewriteSpec spec = new RewriteSpec(); - spec.setOrigName(rewriteElem.getAttribute(REWRITE_VAR_NAME_ATTR)); - spec.setRename(rewriteElem.getAttribute(REWRITE_VAR_RENAME_ATTR)); - spec.setElementType(rewriteElem.getAttribute(REWRITE_VAR_TYPE_ATTR)); - conf.getRewriteSpecs().add(spec); - } - - Element datasetMetRootElem = XMLUtils.getFirstElement(DATASET_MET_ROOT_TAG, - rootElem); - NodeList datasetMetElemNodeList = datasetMetRootElem - .getElementsByTagName(DATASET_MET_ELEM_TAG); - for (int i = 0; i < datasetMetElemNodeList.getLength(); i++) { - Element datasetMetElem = (Element) datasetMetElemNodeList.item(i); - DatasetMetElem datasetMetSpec = new DatasetMetElem(); - datasetMetSpec.setProfileElementName(datasetMetElem - .getAttribute(DATASET_MET_NAME_ATTR)); - datasetMetSpec.setValue(datasetMetElem - .getAttribute(DATASET_MET_VALUE_ATTR)); - conf.getDatasetMetSpecs().add(datasetMetSpec); - } - - Element constRootElem = XMLUtils.getFirstElement(CONSTANT_ROOT_TAG, - rootElem); - NodeList constNodeList = constRootElem.getElementsByTagName(CONSTANT_TAG); - for (int i = 0; i < constNodeList.getLength(); i++) { - Element constElem = (Element) constNodeList.item(i); - ConstantSpec constSpec = new ConstantSpec(); - constSpec.setName(constElem.getAttribute(CONSTANT_NAME_ATTR)); - constSpec.setType(constElem.getAttribute(CONSTANT_TYPE_ATTR)); - constSpec.setValue(constElem - .getAttribute(CONSTANT_VALUE_ATTR)); - conf.getConstSpecs().add(constSpec); - } - - Element processingInstructionsElem = XMLUtils.getFirstElement(PROCESSING_INSTRUCTIONS_TAG, rootElem); - if (processingInstructionsElem!=null) { - NodeList instNodeList = processingInstructionsElem.getElementsByTagName(PROCESSING_INSTRUCTION_TAG); - for (int i = 0; i < instNodeList.getLength(); i++) { - Element instElem = (Element) instNodeList.item(i); - conf.addProcessingInstruction(instElem.getAttribute(PROCESSING_INSTRUCTION_NAME_ATTR), - instElem.getAttribute(PROCESSING_INSTRUCTION_VALUE_ATTR) ); - } - } - - return conf; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapProfileMetKeys.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapProfileMetKeys.java b/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapProfileMetKeys.java deleted file mode 100644 index f833be8..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/config/OpendapProfileMetKeys.java +++ /dev/null @@ -1,36 +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.oodt.opendapps.config; - -/** - * Interface containing names for the metadata keys written to an OpenDAP profile document. - * - * @author Luca Cinquini - * - */ -public interface OpendapProfileMetKeys { - - String VARIABLES = "Variables"; - - String COORDINATES = "Coordinates"; - - String VARIABLES_LONG_NAMES = "Variable Long Names"; - - String CF_STANDARD_NAMES = "CF Standard Names"; - - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/config/ProcessingInstructions.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/config/ProcessingInstructions.java b/opendapps/src/main/java/org/apache/oodt/opendapps/config/ProcessingInstructions.java deleted file mode 100644 index 4e2e01f..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/config/ProcessingInstructions.java +++ /dev/null @@ -1,102 +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.oodt.opendapps.config; - -import java.util.Collections; -import java.util.concurrent.ConcurrentHashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.springframework.util.StringUtils; - -/** - * Class that holds special configuration instructions for generating an Opendap profile. - * Instructions are stored as (name, values) pairs: each named instruction can have multiple values. - * An instructions may be specified in the Opendap XML configuration file as a single element with comma-separated values, - * or as multiple elements with the same name (and one or more values each). - * - * @author Luca Cinquini - * - */ -public class ProcessingInstructions { - - /** - * Local storage for processing instructions. - * Note that the order of the XML elements is not preserved (on purpose). - */ - private final Map<String, Set<String>> instructions = new ConcurrentHashMap<String, Set<String>>(); - - /** - * Returns all values for a named instruction, - * or an empty set if the instruction was not specified. - * @param key - * @return - */ - public Set<String> getInstructionValues(String key) { - if (instructions.containsKey(key)) { - return Collections.unmodifiableSet( instructions.get(key) ); - } else { - return Collections.unmodifiableSet( new HashSet<String>() ); - } - } - - /** - * If an instruction contains a single value, it is returned. - * If the instruction has no values or multiple values, returns null instead. - * @param key - * @return - */ - public String getInstructionValue(String key) { - if (instructions.get(key)!=null && instructions.get(key).size()==1) { - for (String value : instructions.get(key)) { - return value; - } - } - return null; - } - - /** - * Returns all instructions. - * @return - */ - public Map<String, Set<String>> getInstructions() { - return Collections.unmodifiableMap(instructions); - } - - /** - * Method to add a value to a named instruction. - * Value can be a comma separated list of values. - * Leading and trailing spaces for each value are removed. - * @param key - * @param value - */ - public void addInstruction(String key, String value) { - if (StringUtils.hasText(key)) { - if (!instructions.containsKey(key)) { - instructions.put(key, new HashSet<String>()); - } - String[] vals = value.split(","); - for (String val : vals) { - if (StringUtils.hasText(val)) { - instructions.get(key).add(val.trim()); - } - } - } - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/config/RewriteSpec.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/config/RewriteSpec.java b/opendapps/src/main/java/org/apache/oodt/opendapps/config/RewriteSpec.java deleted file mode 100644 index fd8a0fe..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/config/RewriteSpec.java +++ /dev/null @@ -1,86 +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.oodt.opendapps.config; - -/** - * - * A specification for rewriting OPeNDAP element names and tags from their - * original OPeNDAP/THREDDS names into OODT profile elements, and their names - * and types. Part of the {@link OpendapConfig}. - * - */ -public class RewriteSpec { - - private String origName; - - private String rename; - - private String elementType; - - public RewriteSpec() { - this.origName = null; - this.rename = null; - this.elementType = null; - } - - /** - * @return the origName - */ - public String getOrigName() { - return origName; - } - - /** - * @param origName - * the origName to set - */ - public void setOrigName(String origName) { - this.origName = origName; - } - - /** - * @return the rename - */ - public String getRename() { - return rename; - } - - /** - * @param rename - * the rename to set - */ - public void setRename(String rename) { - this.rename = rename; - } - - /** - * @return the elementType - */ - public String getElementType() { - return elementType; - } - - /** - * @param elementType - * the elementType to set - */ - public void setElementType(String elementType) { - this.elementType = elementType; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/DasMetadataExtractor.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/DasMetadataExtractor.java b/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/DasMetadataExtractor.java deleted file mode 100644 index 7b01ed1..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/DasMetadataExtractor.java +++ /dev/null @@ -1,186 +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.oodt.opendapps.extractors; - -//JDK imports -import org.apache.oodt.cas.metadata.Metadata; -import org.apache.oodt.opendapps.config.OpendapConfig; -import org.apache.oodt.opendapps.config.OpendapConfigMetKeys; -import org.apache.oodt.opendapps.config.OpendapProfileMetKeys; -import org.apache.oodt.opendapps.config.ProcessingInstructions; -import org.apache.oodt.opendapps.util.ProfileUtils; - -import org.springframework.util.StringUtils; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Enumeration; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -import opendap.dap.Attribute; -import opendap.dap.AttributeTable; -import opendap.dap.DAS; -import opendap.dap.DConnect; - -//OPENDAP imports -//OODT imports - -/** - * Implementation of {@link MetadataExtractor} to extract metadata from an - * OpenDAP DAS source. Currently this class only extracts metadata from the - * NetCDF global attributes of type String, disregarding all others. - * - * @author Luca Cinquini - * - */ -public class DasMetadataExtractor implements MetadataExtractor { - - // constants from NetCDF metadata convention - public static final String NC_GLOBAL = "NC_GLOBAL"; - public static final String LONG_NAME = "long_name"; - public static final String STANDARD_NAME = "standard_name"; - - // NetCDF data types - public static final int INT32_TYPE = 6; - public static final int INT64_TYPE = 7; - public static final int FLOAT32_TYPE = 8; - public static final int FLOAT64_TYPE = 9; - public static final int STRING_TYPE = 10; - - // output format for all global attributes interpreted as dates - private final static String OUTPUT_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - private final static DateFormat outputDatetimeFormat = new SimpleDateFormat(OUTPUT_DATETIME_FORMAT); - - private static Logger LOG = Logger.getLogger(DasMetadataExtractor.class - .getName()); - - /** - * The DAS stream which is the metadata source. - */ - private final DConnect dConn; - - public DasMetadataExtractor(DConnect dConn) { - this.dConn = dConn; - } - - /** - * The main metadata extraction method. - * - * @param metadata - * : the metadata target, specifically the CAS metadata container. - */ - public void extract(Metadata metadata, OpendapConfig config) { - - LOG.log(Level.INFO, "Parsing DAS metadata from: " + dConn.URL()); - - // list of excluded variables - Set<String> excludedVariables - = config.getProcessingInstructions().getInstructionValues(OpendapConfigMetKeys.EXCLUDE_VARIABLES_ATTR); - - try { - DAS das = dConn.getDAS(); - @SuppressWarnings("unchecked") - Enumeration<String> names = das.getNames(); - while (names.hasMoreElements()) { - String attName = names.nextElement(); - LOG.log(Level.FINE, "Extracting DAS attribute: " + attName); - AttributeTable at = das.getAttributeTable(attName); - Enumeration<String> e = at.getNames(); - - // NetCDF global attributes - // store attribute name, all values for ALL attributes (strings and numerics) - ProcessingInstructions processingInstructions = config.getProcessingInstructions(); - if (attName.equals(NC_GLOBAL)) { - while (e.hasMoreElements()) { - String key = e.nextElement(); - Attribute att = at.getAttribute(key); - // convert all DAS attribute names to lower case - String lkey = key.toLowerCase(); - - // look for global attribute name in date/time configuration specification - String dateTimeFormatKey = OpendapConfigMetKeys.DATETIME_FORMAT_ATTR + ":" + lkey; - String dateTimeFormatValue = processingInstructions.getInstructionValue(dateTimeFormatKey); - // add this attribute as properly formatted date/time - if (StringUtils.hasText(dateTimeFormatValue)) { - DateFormat inFormat = new SimpleDateFormat(dateTimeFormatValue); - Enumeration<String> edt = att.getValues(); - while (edt.hasMoreElements()) { - String value = edt.nextElement(); - try { - Date date = inFormat.parse(value); - ProfileUtils.addIfNotNull(metadata, lkey, outputDatetimeFormat.format(date)); - } catch(ParseException pe) { - LOG.log(Level.WARNING, - "Error parsing date/time from DAS attribute: "+key+" value="+value+" error="+pe.getMessage()); - } - } - // add this global attribute as string - } else { - ProfileUtils.addIfNotExisting(metadata, lkey, att.getValues()); - } - } - - // NetCDF coordinates - } else { - - if ( attName.equalsIgnoreCase("lat") || attName.equalsIgnoreCase("latitude") - || attName.equalsIgnoreCase("lon") || attName.equalsIgnoreCase("longitude") - || attName.equalsIgnoreCase("time") - || attName.equalsIgnoreCase("alt") || attName.equalsIgnoreCase("altitude") - || attName.equalsIgnoreCase("lev") || attName.equalsIgnoreCase("level") - || attName.equalsIgnoreCase("depth") - ) { - - if (!excludedVariables.contains(attName)) { - // store coordinate name - ProfileUtils.addIfNotNull(metadata, OpendapProfileMetKeys.COORDINATES, attName); - } - - } else { - - if (!excludedVariables.contains(attName)) { - // store variable name - ProfileUtils.addIfNotNull(metadata, OpendapProfileMetKeys.VARIABLES, attName); - // store "standard_name", "long_name" - while (e.hasMoreElements()) { - String key = e.nextElement(); - Attribute att = at.getAttribute(key); - if (key.equalsIgnoreCase(STANDARD_NAME)) { - ProfileUtils.addIfNotNull(metadata, OpendapProfileMetKeys.CF_STANDARD_NAMES, att.getValueAt(0)); - } else if (key.equalsIgnoreCase(LONG_NAME)) { - ProfileUtils.addIfNotNull(metadata, OpendapProfileMetKeys.VARIABLES_LONG_NAMES, att.getValueAt(0)); - } - } - } - - } - } - - } - - } catch (Exception e) { - LOG.log(Level.WARNING, "Error parsing DAS metadata: " + e.getMessage()); - } - - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/MetadataExtractor.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/MetadataExtractor.java b/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/MetadataExtractor.java deleted file mode 100644 index 1cf9805..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/MetadataExtractor.java +++ /dev/null @@ -1,43 +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.oodt.opendapps.extractors; - -//OODT imports -import org.apache.oodt.cas.metadata.Metadata; -import org.apache.oodt.opendapps.config.OpendapConfig; - -/** - * Interface for extracting metadata from a generic web accessible resource into - * a CAS metadata container. Each implementation class must be responsible for - * instantiating and accessing the specific metadata source as appropriate. - * - * @author Luca Cinquini - * - */ -public interface MetadataExtractor { - - /** - * Method to (further) populate the metadata container. - * Any extracted metadata is added to the current metadata content. - * - * @param metadata - * @param config - */ - void extract(Metadata metadata, OpendapConfig config); - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/NcmlMetadataExtractor.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/NcmlMetadataExtractor.java b/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/NcmlMetadataExtractor.java deleted file mode 100644 index 9b40330..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/NcmlMetadataExtractor.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.oodt.opendapps.extractors; - -//JDK imports -import java.util.logging.Level; -import java.util.logging.Logger; - -//OODT imports -import org.apache.oodt.cas.metadata.Metadata; -import org.apache.oodt.opendapps.config.OpendapConfig; - -/** - * Implementation of {@link MetadataExtractor} that parses an NcML XML document. - * Currently this class is simply a stub that doesn't do anything. - * - * @author Luca Cinquini - * - */ -public class NcmlMetadataExtractor implements MetadataExtractor { - - private final String ncmlUrl; - - private static Logger LOG = Logger.getLogger(NcmlMetadataExtractor.class - .getName()); - - public NcmlMetadataExtractor(String ncmlUrl) { - this.ncmlUrl = ncmlUrl; - } - - /** - * Stub implementation of interface method. - */ - public void extract(Metadata metadata, OpendapConfig config) { - - LOG.log(Level.FINE, "Parsing NcML metadata from: " + ncmlUrl); - - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/ThreddsMetadataExtractor.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/ThreddsMetadataExtractor.java b/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/ThreddsMetadataExtractor.java deleted file mode 100644 index 406feb4..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/extractors/ThreddsMetadataExtractor.java +++ /dev/null @@ -1,315 +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.oodt.opendapps.extractors; - -//JDK imports -import java.net.MalformedURLException; -import java.net.URL; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; - -//OODT imports -import org.apache.oodt.cas.metadata.Metadata; -import org.apache.oodt.opendapps.config.OpendapConfig; -import org.apache.oodt.opendapps.util.ProfileUtils; - - -//Spring imports -import org.springframework.util.StringUtils; - -//THREDDS imports -import thredds.catalog.InvAccess; -import thredds.catalog.InvDataset; -import thredds.catalog.InvDocumentation; -import thredds.catalog.InvProperty; -import thredds.catalog.ServiceType; -import thredds.catalog.ThreddsMetadata.Contributor; -import thredds.catalog.ThreddsMetadata.GeospatialCoverage; -import thredds.catalog.ThreddsMetadata.Range; -import thredds.catalog.ThreddsMetadata.Source; -import thredds.catalog.ThreddsMetadata.Vocab; -import ucar.nc2.units.DateType; -import ucar.unidata.geoloc.LatLonRect; - -/** - * Implementation of {@link MetadataExtractor} that extracts metadata from a - * Thredds dataset. - * - * @author Luca Cinquini - * - */ -public class ThreddsMetadataExtractor implements MetadataExtractor { - - private static Logger LOG = Logger.getLogger(ThreddsMetadataExtractor.class - .getName()); - - // constant missing for 4.2 version of NetCDF library - public final static String SERVICE_TYPE_NCML = "NCML"; - - /** - * The source of metadata to be extracted. - */ - private final InvDataset dataset; - - public ThreddsMetadataExtractor(final InvDataset dataset) { - this.dataset = dataset; - } - - public void extract(Metadata met, OpendapConfig config) { - - LOG.log(Level.INFO, "Crawling catalog URL=" + dataset.getCatalogUrl() - + " dataset ID=" + dataset.getID()); - - ProfileUtils.addIfNotNull(met, "Authority", dataset.getAuthority()); - ProfileUtils.addIfNotNull(met, "CatalogUrl", dataset.getCatalogUrl()); - try { - ProfileUtils.addIfNotNull(met, "Host", (new URL(dataset.getCatalogUrl())).getHost() ); - } catch(MalformedURLException e) { - LOG.log(Level.WARNING, e.getMessage()); - } - ProfileUtils.addIfNotNull(met, "DatasetFullName", dataset.getFullName()); - if (dataset.getContributors() != null) { - for (Contributor contributor : dataset.getContributors()) { - ProfileUtils.addIfNotNull(met, "Contributor", contributor.getName()); - } - } - - if (dataset.getCreators() != null) { - for (Source source : dataset.getCreators()) { - ProfileUtils.addIfNotNull(met, "Creator", source.getName()); - } - } - - if (dataset.getDataFormatType() != null) { - ProfileUtils.addIfNotNull(met, "DataFormatType", dataset - .getDataFormatType().toString()); - } - - if (dataset.getDataType() != null) { - ProfileUtils.addIfNotNull(met, "DataType", dataset.getDataType() - .toString()); - } - - if (dataset.getDates() != null) { - for (DateType dateType : dataset.getDates()) { - String dateString = null; - try { - dateString = ProfileUtils.toISO8601(dateType.getDate()); - } catch (Exception e) { - LOG.log(Level.WARNING, - "Error converting date: [" + dateType.getDate() + "]: Message: " - + e.getMessage()); - } - ProfileUtils.addIfNotNull(met, "Dates", dateString); - } - } - - if (dataset.getDocumentation() != null) { - for (InvDocumentation doc : dataset.getDocumentation()) { - // textual documentation - if (StringUtils.hasText(doc.getInlineContent())) { - if (StringUtils.hasText(doc.getType())) { - // use specific documentation type, when available - ProfileUtils.addIfNotNull(met, doc.getType(), doc.getInlineContent()); - } else { - // otherwise use generic "Documentation" tag - ProfileUtils.addIfNotNull(met, "Documentation", doc.getInlineContent()); - } - } - // hyperlinked documentation - if (StringUtils.hasText(doc.getXlinkHref())) { - String tuple = this.encodeXlinkTuple(doc.getXlinkHref(), doc.getXlinkTitle(), doc.getType()); - ProfileUtils.addIfNotNull(met, "Xlink", tuple); - } - - } - } - - ProfileUtils.addIfNotNull(met, "FullName", dataset.getFullName()); - GeospatialCoverage geoCoverage = dataset.getGeospatialCoverage(); - - if (geoCoverage != null) { - - LatLonRect bbox = geoCoverage.getBoundingBox(); - if (bbox != null) { - ProfileUtils.addIfNotNull(met, "SouthwestBC", bbox.getLowerLeftPoint() - .toString()); - ProfileUtils.addIfNotNull(met, "NorthwestBC", bbox.getUpperLeftPoint() - .toString()); - ProfileUtils.addIfNotNull(met, "NortheastBC", bbox.getUpperRightPoint() - .toString()); - ProfileUtils.addIfNotNull(met, "SoutheastBC", bbox.getLowerRightPoint() - .toString()); - } - - // try north south, east west - if (geoCoverage.getNorthSouthRange() != null) { - Range nsRange = geoCoverage.getNorthSouthRange(); - ProfileUtils.addIfNotNull(met, "NorthSouthRangeStart", - String.valueOf(nsRange.getStart())); - ProfileUtils.addIfNotNull(met, "NorthSouthRangeResolution", - String.valueOf(nsRange.getResolution())); - ProfileUtils.addIfNotNull(met, "NorthSouthRangeSize", - String.valueOf(nsRange.getSize())); - ProfileUtils.addIfNotNull(met, "NorthSouthRangeUnits", - nsRange.getUnits()); - ProfileUtils.addIfNotNull(met, "NorthSouthRangeStop", - String.valueOf(nsRange.getStart()+nsRange.getSize())); - } - - if (geoCoverage.getEastWestRange() != null) { - Range nsRange = geoCoverage.getEastWestRange(); - ProfileUtils.addIfNotNull(met, "EastWestRangeStart", - String.valueOf(nsRange.getStart())); - ProfileUtils.addIfNotNull(met, "EastWestRangeResolution", - String.valueOf(nsRange.getResolution())); - ProfileUtils.addIfNotNull(met, "EastWestRangeSize", - String.valueOf(nsRange.getSize())); - ProfileUtils.addIfNotNull(met, "EastWestRangeUnits", - nsRange.getUnits()); - ProfileUtils.addIfNotNull(met, "EastWestRangeStop", - String.valueOf(nsRange.getStart()+nsRange.getSize())); - } - - ProfileUtils.addIfNotNull(met, "GeospatialCoverageLatitudeResolution", - String.valueOf(dataset.getGeospatialCoverage().getLatResolution())); - ProfileUtils.addIfNotNull(met, "GeospatialCoverageLongitudeResolution", - String.valueOf(dataset.getGeospatialCoverage().getLonResolution())); - - // add geo-spatial coverage alternative form - ProfileUtils.addIfNotNull(met, "GeospatialCoverageLatSouth", String.valueOf(dataset.getGeospatialCoverage().getLatSouth())); - ProfileUtils.addIfNotNull(met, "GeospatialCoverageLatNorth", String.valueOf(dataset.getGeospatialCoverage().getLatNorth())); - ProfileUtils.addIfNotNull(met, "GeospatialCoverageLonWest", String.valueOf(dataset.getGeospatialCoverage().getLonWest())); - ProfileUtils.addIfNotNull(met, "GeospatialCoverageLonEast", String.valueOf(dataset.getGeospatialCoverage().getLonEast())); - - if (dataset.getGeospatialCoverage().getNames() != null) { - for (Vocab gName : dataset.getGeospatialCoverage().getNames()) { - ProfileUtils.addIfNotNull(met, "GeospatialCoverage", gName.getText()); - } - } - - } - - ProfileUtils.addIfNotNull(met, "History", dataset.getHistory()); - if (dataset.getKeywords() != null) { - for (Vocab vocab : dataset.getKeywords()) { - ProfileUtils.addIfNotNull(met, "Keywords", vocab.getText()); - } - } - ProfileUtils.addIfNotNull(met, "Name", dataset.getName()); - ProfileUtils.addIfNotNull(met, "Processing", dataset.getProcessing()); - if (dataset.getProjects() != null) { - for (Vocab vocab : dataset.getProjects()) { - ProfileUtils.addIfNotNull(met, "Projects", vocab.getText()); - } - } - - if (dataset.getProperties() != null) { - for (InvProperty prop : dataset.getProperties()) { - ProfileUtils.addIfNotNull(met, prop.getName(), prop.getValue()); - } - } - - if (dataset.getPublishers() != null) { - for (Source source : dataset.getPublishers()) { - // Note: use "Publisher" (singular) as from the OODT profile specification - ProfileUtils.addIfNotNull(met, "Publisher", source.getName()); - } - } - - ProfileUtils.addIfNotNull(met, "RestrictAccess", - dataset.getRestrictAccess()); - if (dataset.getTimeCoverage() != null) { - String startDateTimeStr = null, endDateTimeStr = null; - try { - startDateTimeStr = ProfileUtils.toISO8601(dataset.getTimeCoverage() - .getStart().getDate()); - endDateTimeStr = ProfileUtils.toISO8601(dataset.getTimeCoverage() - .getEnd().getDate()); - } catch (Exception e) { - LOG.log( - Level.WARNING, - "Error converting start/end date time strings: Message: " - + e.getMessage()); - } - - ProfileUtils.addIfNotNull(met, "StartDateTime", startDateTimeStr); - ProfileUtils.addIfNotNull(met, "EndDateTime", endDateTimeStr); - } - - if (dataset.getTimeCoverage() != null - && dataset.getTimeCoverage().getResolution() != null) { - ProfileUtils.addIfNotNull(met, "TimeCoverageResolution", dataset - .getTimeCoverage().getResolution().getText()); - } - // dataset unique ID - ProfileUtils.addIfNotNull(met, "UniqueID", dataset.getUniqueID()); - - // dataset ID is typically not null - ProfileUtils.addIfNotNull(met, "ID", dataset.getID()); - - // generate a UUID for each dataset, to be used as profile ID - ProfileUtils.addIfNotNull(met, "UUID", UUID.randomUUID().toString()); - - // store access services - only the OpenDAP endpoint for now - for (InvAccess access : dataset.getAccess()) { - String url = access.getStandardUri().toString(); - String type = access.getService().getServiceType().toString(); - String name = access.getService().getName(); - - // add opendap access URL - if (type.equalsIgnoreCase(ServiceType.OPENDAP.toString())) { - // store opendap URL - ProfileUtils.addIfNotNull(met,"OpendapUrl",url); - // note: special processing of opendap endpoints since URL in thredds catalog is unusable without a suffix - ProfileUtils.addIfNotNull(met,"Access", this.encodeAccessTuple(url+".html", ProfileUtils.MIME_TYPE_OPENDAP_HTML, type)); - } - } - // add TREDDS XML catalog URL - String url = dataset.getCatalogUrl(); // catalog_url.xml#dataset_id - ProfileUtils.addIfNotNull(met,"Access", this.encodeAccessTuple(url, ProfileUtils.MIME_TYPE_THREDDS, "Catalog/XML")); - ProfileUtils.addIfNotNull(met,"Access", this.encodeAccessTuple(url.replaceAll("\\.xml", ".html"), ProfileUtils.MIME_TYPE_HTML, "Catalog/HTML")); - - } - - /** - * Utility method that joins the parts of an xlink tuple (href, title, type) with a delimiting character. - * @param href : the xlink URL, must be not null - * @param title : the xlink title, may be null - * @param type : the xlink type, may be null - * @return - */ - private String encodeXlinkTuple(final String href, final String title, final String type) { - return href + ProfileUtils.CHAR + (StringUtils.hasText(title) ? title : "Reference") + ProfileUtils.CHAR + ( - StringUtils.hasText(type) ? type : "HTML"); - } - - /** - * Utility method that joins the part of A THREDDS access point (url, service type, service name) with a delimiting character - * @param url : the access URL - * @param type : the service type, mapped to a mime type - * @param name : the service name - * @return - */ - private String encodeAccessTuple(final String url, final String type, final String name) { - return url + ProfileUtils.CHAR + (StringUtils.hasText(type) ? type : "") + ProfileUtils.CHAR + ( - StringUtils.hasText(name) ? name : ""); - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/util/OpendapURLEvaluator.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/util/OpendapURLEvaluator.java b/opendapps/src/main/java/org/apache/oodt/opendapps/util/OpendapURLEvaluator.java deleted file mode 100644 index eeec45c..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/util/OpendapURLEvaluator.java +++ /dev/null @@ -1,48 +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.oodt.opendapps.util; - -//JDK imports -import java.io.IOException; - -import org.apache.oodt.opendapps.DatasetExtractor; -import org.apache.oodt.xmlquery.XMLQuery; - -/** - * - * Evaluates the resultant OPeNDAP URLs returned from a THREDDS catalog by the - * {@link DatasetExtractor}. - * - */ -public class OpendapURLEvaluator { - - public static void main(String[] args) throws IOException { - String datasetUrl = args[0]; - String catalogUrl = args[1]; - - DatasetExtractor gen = new DatasetExtractor(getQuery(), catalogUrl, - datasetUrl, null); - System.out.println(gen.getDapUrls()); - } - - private static XMLQuery getQuery() { - return new XMLQuery("PFunction=findall", "cmdline", "cmdline", null, null, - null, null, null, XMLQuery.DEFAULT_MAX_RESULTS, true); - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/util/ProfileChecker.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/util/ProfileChecker.java b/opendapps/src/main/java/org/apache/oodt/opendapps/util/ProfileChecker.java deleted file mode 100644 index 1996381..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/util/ProfileChecker.java +++ /dev/null @@ -1,186 +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.oodt.opendapps.util; - -// JDK imports -import java.util.List; - -// OODT imports -import org.apache.oodt.profile.Profile; -import org.apache.oodt.profile.ProfileElement; - -// Spring imports -import org.springframework.util.StringUtils; - -/** - * Utility class that checks an OODT Profile versus a list of required/optional elements, - * and provides a validation summary for quick inspection by the publisher. - * - * @author Luca Cinquini - * - */ -public class ProfileChecker { - - // list of mandatory profile elements - private final static String[] mandatoryProfileElements = new String[] { }; - - // list of optional profile elements - private final static String[] optionalProfileElements = new String[] { "mission_name", "sensor", "institute", - "variable", "cf_standard_name", "variable_long_name", - "spatial_coverage", - "north_degrees", "east_degrees", "south_degrees", "west_degrees", - "datetime_start", "datetime_stop" }; - - /** - * Main method to check an OODT profile. - * - * @param profile : the OODT profile that needs validation. - * @param sb : buffer to write the output to. - * @return : true if the profile is valid, false otherwise. - */ - public static boolean check(final Profile profile, final StringBuilder sb) { - - // profile passes by default - boolean ok = true; - sb.append("\nChecking profile=").append(profile.getProfileAttributes().getID()); - - ok = checkResourceAttribute("Identifier", profile.getResourceAttributes().getIdentifier(), true, sb); - - ok = ok && checkResourceAttribute("Title", profile.getResourceAttributes().getTitle(), true, sb); - - ok = ok && checkResourceAttribute("Description", profile.getResourceAttributes().getDescription(), false, sb); - - ok = ok && checkResourceAttribute("Location of type "+ProfileUtils.MIME_TYPE_OPENDAP_HTML, - selectResourceLocationByMimeType(profile.getResourceAttributes().getResLocations(), ProfileUtils.MIME_TYPE_OPENDAP_HTML), - true, sb); - - ok = ok && checkResourceAttribute("Location of type "+ProfileUtils.MIME_TYPE_THREDDS, - selectResourceLocationByMimeType(profile.getResourceAttributes().getResLocations(), ProfileUtils.MIME_TYPE_THREDDS), - true, sb); - - ok = ok && checkResourceAttribute("Location of type "+ProfileUtils.MIME_TYPE_HTML, - selectResourceLocationByMimeType(profile.getResourceAttributes().getResLocations(), ProfileUtils.MIME_TYPE_HTML), - true, sb); - - ok = ok && checkResourceAttribute("Location of type "+ProfileUtils.MIME_TYPE_GIS, - selectResourceLocationByMimeType(profile.getResourceAttributes().getResLocations(), ProfileUtils.MIME_TYPE_GIS), - true, sb); - - for (String name : mandatoryProfileElements) { - ok = ok && checkProfileElement(profile, name, true, sb); - } - for (String name : optionalProfileElements) { - ok = ok && checkProfileElement(profile, name, false, sb); - } - - return ok; - } - - /** - * Method to check that a profile Resource Attribute has a valid value. - * - * @param name - * @param value - * @param mandatory - * @param sb - * @return - */ - private static boolean checkResourceAttribute(String name, String value, boolean mandatory, StringBuilder sb) { - sb.append("\n\tResource Attribute '").append(name).append("' = "); - if (!StringUtils.hasText(value) || value.equalsIgnoreCase("null")) { - if (mandatory) { - return false; // bad value - } - } else { - sb.append(value); - } - return true; - } - - /** - * Method to check that the profile contains at least one valid value for of a specific element name. - * - * @param profile - * @param name - * @param mandatory - * @param sb - * @return - */ - private static boolean checkProfileElement(Profile profile, String name, boolean mandatory, StringBuilder sb) { - - sb.append("\n\tProfile Element '").append(name).append("' = "); - // profile element is valid by default - boolean ok = true; - - if (profile.getProfileElements().containsKey(name)) { - ProfileElement profElement = (ProfileElement)profile.getProfileElements().get(name); - - // profile element found - List<String> values = profElement.getValues(); - if (values.size()>0) { - boolean first = true; - for (String value : values) { - if (!StringUtils.hasText(value) || value.equalsIgnoreCase("null")) { - if (mandatory) { - ok = false; // invalid value for this profile element - } - } else { - if (!first) { - sb.append(", "); - } - sb.append(value); - first = false; - } - } - } else { - if (mandatory) { - ok = false; // no values found for this profile element - } - } - - } else { - if (mandatory) { - ok = false; // no profile element found - } - } - - return ok; - - } - - /** - * Method to select the resource location of a specific mime type, if found. - * - * @param resLocations - * @param mimeType - * @return - */ - private static String selectResourceLocationByMimeType(List<String> resLocations, String mimeType) { - - for (String resLocation : resLocations) { - String[] parts = resLocation.split("\\|"); // regular expression of ProfileUtils.CHAR - if (parts[1].equals(mimeType)) { - return parts[0]; - } - } - - // resource location not found - return null; - - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/opendapps/src/main/java/org/apache/oodt/opendapps/util/ProfileSerializer.java ---------------------------------------------------------------------- diff --git a/opendapps/src/main/java/org/apache/oodt/opendapps/util/ProfileSerializer.java b/opendapps/src/main/java/org/apache/oodt/opendapps/util/ProfileSerializer.java deleted file mode 100644 index 56de711..0000000 --- a/opendapps/src/main/java/org/apache/oodt/opendapps/util/ProfileSerializer.java +++ /dev/null @@ -1,109 +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.oodt.opendapps.util; - -//JDK imports -import java.io.StringWriter; -import java.util.List; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -//OODT imports -import org.apache.oodt.profile.Profile; - -/** - * Utility class to serialize a list of profiles to an XML document. - * <p/> - * Based on functionality already contained in the OODT grid ProfileQueryServlet - * class, but separated as a stand alone utility to reduce dependencies. - * - * @author Luca Cinquini - * - */ -public class ProfileSerializer { - - /** - * Function to serialize a list of {@link Profile}s to XML. - * - * @param profiles - * @return - * @throws TransformerException - */ - public static String toXML(final List<Profile> profiles) - throws TransformerException { - - final StringWriter writer = new StringWriter(); - writer.append("<?xml version='1.0' encoding='UTF-8'?>"); - writer.append("<!DOCTYPE profiles PUBLIC '" + Profile.PROFILES_DTD_FPI + "' '").append(Profile.PROFILES_DTD_URL) - .append("'>"); - writer.append("<profiles>"); - - final Transformer transformer = createTransformer(); - final Document doc = Profile.createProfileDocument(); - for (final Profile profile : profiles) { - - Node profileNode = profile.toXML(doc); - DOMSource source = new DOMSource(profileNode); - StreamResult result = new StreamResult(writer); - transformer.transform(source, result); - - } - - writer.append("</profiles>"); - - return writer.toString(); - - } - - /** - * Create a transformer, properly configured for XML text serialization. - * - * @return a <code>Transformer</code> value. - * @throws TransformerException - * if an error occurs. - */ - private static Transformer createTransformer() throws TransformerException { - - Transformer transformer; - synchronized (TRANSFORMER_FACTORY) { - transformer = TRANSFORMER_FACTORY.newTransformer(); - } - - transformer.setOutputProperty(OutputKeys.METHOD, "xml"); - transformer.setOutputProperty(OutputKeys.VERSION, "1.0"); - transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - transformer.setOutputProperty(OutputKeys.STANDALONE, "no"); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml"); - transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", - "4"); - - return transformer; - } - - /** Sole transformer factory this class will ever need. */ - private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory - .newInstance(); - -}
