Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright 2012 Pearson Education
*
* 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.semantictools.frame.api;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import org.semantictools.context.renderer.MediaTypeFileManager;
import org.semantictools.context.renderer.model.BibliographicReference;
import org.semantictools.context.renderer.model.ContextProperties;
import org.semantictools.context.renderer.model.DocumentMetadata;
import org.semantictools.context.renderer.model.FrameConstraints;
import org.semantictools.context.renderer.model.Person;
import org.semantictools.context.renderer.model.ReferenceManager;
import org.semantictools.context.renderer.model.SampleJson;
public class ContextManager {
// private static final Logger logger = LoggerFactory.getLogger(ContextManager.class);
public static final String SKIP_VALIDATION = "skipValidation";
private static final String RDFTYPE = "rdfType";
private static final String RDFTYPE_REF = "rdfTypeRef";
private static final String RDF_PROPERTY = "rdfProperty";
private static final String MEDIATYPE = "mediaType";
private static final String MEDIATYPEURI = "mediaTypeURI";
private static final String MEDIATYPEREF = "mediaTypeRef";
private static final String CONTEXTURI = "contextURI";
private static final String CONTEXTREF = "contextRef";
private static final String GRAPH_TYPES = "graphTypes";
private static final String USE_PREFIX = "usePrefix";
private static final String SET = "@set";
private static final String ENABLE_VERSION_HISTORY = "enableVersionHistory";
private static final String IDREF = "idref";
private static final String REQUIRES_ID = "requiresId";
private static final String OPTIONAL = "optional";
private static final String MIXED_VALUE = "mixedValue";
private static final String STATUS = "status";
private static final String DATE = "date";
private static final String ABSTRACT = "abstract";
private static final String EDITORS = "editors";
private static final String AUTHORS = "authors";
private static final String TITLE = "title";
private static final String SAMPLE_TEXT = "sampleText";
private static final String EXCLUDE_TYPE = "excludeType";
private static final String INTRODUCTION = "introduction";
private static final String SIMPLE_NAMES = "simpleNames";
private static final String INCLUDES_SUFFIX = ".includes";
private static final String EXCLUDES_SUFFIX = ".excludes";
private static final String EXCLUDE_SUBTYPES_SUFFIX = ".excludeSubtypes";
private static final String PURL_DOMAIN = "purlDomain";
private static final String EXPANDED_VALUE = "expandedValue";
private static final String CAPTION_SUFFIX = ".caption";
private static final String TEMPLATE = "template";
private static final String VALIDATE_JSON_SAMPLES = "validateJsonSamples";
private static final String HOW_TO_READ = "includeHowToReadSection";
private static final String JSON_LD_SECTION = "includeJsonldSection";
private static final String RESERVED_WORDS = "includeReservedWordsSection";
private static final String MEDIA_TYPE_SECTION = "includeMediaTypeConformance";
private static final String OVERVIEW_DIAGRAM = "includeOverviewDiagram";
private MediaTypeFileManager fileManager;
private Map contextMap = new HashMap();
private DocumentMetadata defaultMetadata;
public ContextManager(DocumentMetadata defaultMetadata, MediaTypeFileManager fileManager) {
this.fileManager = fileManager;
this.defaultMetadata = defaultMetadata;
}
public MediaTypeFileManager getMediaTypeFileManager() {
return fileManager;
}
/**
* Loads ContextProperties from a properties file.
* The file must contain properties of the following form:
*
*
*.rdfType = <The fully qualified URI for the RDF class to which the representation applies>
*
*.mediaType = <The MIME type for the JSON-LD context>
*
*.contextURI = <The fully qualified URI at which the JSON-LD context will be published<
*
*.idref = <A space separated list of URIs for properties that will be coerced to "@id" values in the JSON-LD context>
*
* @param propertiesFile
* @throws IOException
*/
public void loadContextProperties(File propertiesFile)
throws IOException, ContextPropertiesSyntaxException {
Properties properties = new Properties();
FileInputStream input = new FileInputStream(propertiesFile);
try {
properties.load(input);
parseProperties(propertiesFile, properties);
} finally {
input.close();
}
}
public void loadAll(File baseDir) throws ContextPropertiesSyntaxException, IOException {
File[] list = baseDir.listFiles();
if (list == null) return;
for (int i=0; i listContextPropertiesForClass(String rdfClassURI) {
List list = new ArrayList();
for (ContextProperties p : contextMap.values()) {
if (rdfClassURI.equals(p.getRdfTypeURI())) {
list.add(p);
}
}
return list;
}
public List listContextProperties() {
return new ArrayList( contextMap.values() );
}
private void parseProperties(File sourceFile, Properties properties) {
ContextProperties sink = new ContextProperties(defaultMetadata, properties);
sink.setSourceFile(sourceFile);
for (Map.Entry