/*
(non-Javadoc)

@see
net.jawr.web.resource.bundle.generator.ResourceGenerator#createResource
(java.lang.String, java.nio.charset.Charset)
555934
@Override
	public Reader generateResource(String path, GeneratorContext context) {

		MessageBundleScriptCreator creator = new MessageBundleScriptCreator(context, control);
		addLinkedResources(path, context);
		return creator.createScript(context.getCharset());
	}
637162
@Override
	public String load(String resource, String[] paths, String charset) throws IOException {
		for (ResourceLoader loader : loaders) {
			if (loader.exists(resource, paths)) {
				return loader.load(resource, paths, charset);
			}
		}
		throw new IOException("No such file " + resource);
	}
284990
public ResponseBuilder createResource() {
        final String baseUrl = getBaseUrl();
        final String identifier = baseUrl + req.getPartition() + req.getPath() + id;
        final String contentType = req.getContentType();
        final Session session = ofNullable(req.getSession()).orElseGet(HttpSession::new);

        LOGGER.info("Creating resource as {}", identifier);

        final Optional<RDFSyntax> rdfSyntax = ofNullable(contentType).flatMap(RDFSyntax::byMediaType)
            .filter(SUPPORTED_RDF_TYPES::contains);

        final IRI defaultType = nonNull(contentType) && !rdfSyntax.isPresent() ? LDP.NonRDFSource : LDP.RDFSource;
        final IRI internalId = rdf.createIRI(TRELLIS_PREFIX + req.getPartition() + req.getPath() + id);

        // Add LDP type (ldp:Resource results in the defaultType)
        final IRI ldpType = ofNullable(req.getLink())
            .filter(l -> "type".equals(l.getRel())).map(Link::getUri).map(URI::toString)
            .filter(l -> l.startsWith(LDP.URI)).map(rdf::createIRI)
            .filter(l -> !LDP.Resource.equals(l)).orElse(defaultType);

        if (ldpType.equals(LDP.NonRDFSource) && rdfSyntax.isPresent()) {
            return status(BAD_REQUEST).type(TEXT_PLAIN).entity("Cannot save a NonRDFSource with RDF syntax");
        }

        try (final TrellisDataset dataset = TrellisDataset.createDataset()) {

            // Add Audit quads
            audit.ifPresent(svc ->
                    svc.creation(internalId, session).stream().map(skolemizeQuads(resourceService, baseUrl))
                .forEachOrdered(dataset::add));

            dataset.add(rdf.createQuad(PreferServerManaged, internalId, RDF.type, ldpType));

            // Add user-supplied data
            if (ldpType.equals(LDP.NonRDFSource)) {
                // Check the expected digest value
                final Digest digest = req.getDigest();
                if (nonNull(digest) && !getDigestForEntity(digest).equals(digest.getDigest())) {
                    return status(BAD_REQUEST);
                }

                final Map<String, String> metadata = singletonMap(CONTENT_TYPE, ofNullable(contentType)
                        .orElse(APPLICATION_OCTET_STREAM));
                final IRI binaryLocation = rdf.createIRI(binaryService.getIdentifierSupplier(req.getPartition())
                        .get());
                dataset.add(rdf.createQuad(PreferServerManaged, internalId, DC.hasPart, binaryLocation));
                dataset.add(rdf.createQuad(PreferServerManaged, binaryLocation, DC.modified,
                            rdf.createLiteral(now().toString(), XSD.dateTime)));
                dataset.add(rdf.createQuad(PreferServerManaged, binaryLocation, DC.format,
                            rdf.createLiteral(ofNullable(contentType).orElse(APPLICATION_OCTET_STREAM))));
                dataset.add(rdf.createQuad(PreferServerManaged, binaryLocation, DC.extent,
                            rdf.createLiteral(Long.toString(entity.length()), XSD.long_)));

                // Persist the content
                persistContent(binaryLocation, metadata);
            } else {
                readEntityIntoDataset(identifier, baseUrl, PreferUserManaged, rdfSyntax.orElse(TURTLE), dataset);

                // Check for any constraints
                checkConstraint(dataset, PreferUserManaged, ldpType, TRELLIS_PREFIX + req.getPartition(),
                        rdfSyntax.orElse(TURTLE));
            }

            if (resourceService.put(internalId, dataset.asDataset())) {
                final ResponseBuilder builder = status(CREATED).location(create(identifier));

                // Add LDP types
                ldpResourceTypes(ldpType).map(IRI::getIRIString).forEach(type -> builder.link(type, "type"));

                return builder;
            }
        }

        LOGGER.error("Unable to persist data to location at {}", internalId.getIRIString());
        return serverError().type(TEXT_PLAIN)
            .entity("Unable to persist data. Please consult the logs for more information");
    }
510018
protected Reader createResourceReader(Resource resource) {
        try {
            return new InputStreamReader(resource.getInputStream());
        }
        catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
916893
static void createFileFromResource(String resource, Resource file) throws IOException {
	createFileFromResource(resource, file, null);
    }
645463
@Override
    public Resource createResource(URI uri) {
        DroolsFactoryImpl.init();
        BpsimFactoryImpl.init();
        JBPMBpmn2ResourceImpl result = new JBPMBpmn2ResourceImpl(uri);
        ExtendedMetaData extendedMetadata = new XmlExtendedMetadata();
        result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
                                           extendedMetadata);
        result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
                                           extendedMetadata);

        result.getDefaultSaveOptions().put(XMLResource.OPTION_SAVE_TYPE_INFORMATION,
                                           new OnlyContainmentTypeInfo());

        result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
                                           Boolean.TRUE);
        result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
                                           Boolean.TRUE);

        result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER,
                                           Boolean.TRUE);

        result.getDefaultSaveOptions().put(XMLResource.OPTION_ELEMENT_HANDLER,
                                           new ElementHandlerImpl(true));

        result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODING,
                                           "UTF-8");
        result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE,
                                           new ArrayList<Object>());
        result.getDefaultSaveOptions().put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION,
                                           true);
        result.getDefaultSaveOptions().put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
                                           XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);

        return result;
    }
1365644
@Pure
	protected Resource createResource(ResourceSet  resourceSet) {
		URI uri = computeUnusedUri(resourceSet);
		Resource resource = getResourceFactory().createResource(uri);
		resourceSet.getResources().add(resource);
		return resource;
	}
446235
public static Action resourceContent(String resourcePath, String charset) {
        URL resource = Action.class.getClassLoader().getResource(resourcePath);
        if (resource == null) {
            throw new IllegalArgumentException(String.format("Resource %s not found.", resourcePath));
        }
        Action charsetAction = charset == null ? noop() : charset(Charset.forName(charset));
        return composite(resourceContent(resource), charsetAction);
    }
711023
@Override
	protected Reader generateResource(String path, GeneratorContext context) {

		Reader reader = null;
		ResourceReaderHandler readerHandler = context.getResourceReaderHandler();

		String skinRootDir = getSkinRootDir(path, skinMapping.keySet());
		Map<String, VariantSet> ctxVariantSetMap = skinMapping.get(skinRootDir);

		String skinVariantPath = path.substring(skinRootDir.length());
		String[] paths = skinVariantPath.split(JawrConstant.URL_SEPARATOR);

		VariantResourceReaderStrategy strategy = getVariantStrategy(context, ctxVariantSetMap);
		Map<String, String> variantMap = null;
		do {
			variantMap = strategy.nextVariantMapConbination();
			if (variantMap != null) {
				JoinableResourceBundle bundle = context.getBundle();
				reader = getResourceReader(bundle, path, readerHandler, skinRootDir, paths, variantMap);
			}
		} while (variantMap != null && reader == null);

		return reader;
	}
803804
@Override
    public Object createResource(ResourceInfo info) throws Exception {
        Properties propertyNames = createPropertyNames();
        Properties props = createProperties(propertyNames);

        // The listOfPropMap is how the nested properties (name, value pairs) are
        // pulled from the Nester class. This iterates the map and stores them in the
        // props object
        if (listOfPropMap != null)
        {
            for (Map<String, Object> nestedProperties : listOfPropMap)
            {
                props.put(nestedProperties.get(NAME), nestedProperties.get(VALUE));
            }
        }

        Session session = createSession(props);

        return session;
    }
505829
private void writeResources(List<Resource> resources)
            throws JsonGenerationException, IOException {

        List<String> resourceStrings = new ArrayList<String>();

        for (Resource resource : resources) {
            resourceStrings.add(resource.getId());
        }
        writeJsonArray(JsonDocumentFields.RESOURCE, resourceStrings);
    }
799323
public void addCreatedResource(Location location, Resource resource) {
        resourceList.add(resource);
        locationToResourceMap.put(location, resource);
    }
295864
public DocumentSource createDocumentSource(URL base, String urlstring)
    {
        try
        {
            Constructor<? extends DocumentSource> constr = getDocumentSourceClass().getConstructor(URL.class, String.class);
            return constr.newInstance(base, urlstring);
        } catch (Exception e) {
            log.warn("Could not create the DocumentSource instance: " + e.getMessage());
            return null;
        }
    }
465072
protected ResourceConfig createResourceConfig(WebConfig webConfig)
        throws BeansException
    {
        return WebApplicationContextUtils.getWebApplicationContext(webConfig.getServletContext())
            .getBean(webConfig.getServletConfig().getInitParameter(REST_APPLICATION), ResourceConfig.class);
    }
154800
private void createResources(CmsUploadListener listener) throws CmsException, UnsupportedEncodingException {

        CmsObject cms = getCmsObject();
        String[] isRootPathVals = m_parameterMap.get(I_CmsUploadConstants.UPLOAD_IS_ROOT_PATH_FIELD_NAME);
        if ((isRootPathVals != null) && (isRootPathVals.length > 0) && Boolean.parseBoolean(isRootPathVals[0])) {
            cms = m_rootCms;
        }
        // get the target folder
        String targetFolder = getTargetFolder(cms);
        m_uploadHook = OpenCms.getWorkplaceManager().getUploadHook(cms, targetFolder);

        List<String> filesToUnzip = getFilesToUnzip();

        // iterate over the list of files to upload and create each single resource
        for (FileItem fileItem : m_multiPartFileItems) {
            if ((fileItem != null) && (!fileItem.isFormField())) {
                // read the content of the file
                byte[] content = fileItem.get();
                fileItem.delete();

                // determine the new resource name
                String fileName = m_parameterMap.get(
                    fileItem.getFieldName() + I_CmsUploadConstants.UPLOAD_FILENAME_ENCODED_SUFFIX)[0];
                fileName = URLDecoder.decode(fileName, "UTF-8");

                if (filesToUnzip.contains(CmsResource.getName(fileName.replace('\\', '/')))) {
                    // import the zip
                    CmsImportFolder importZip = new CmsImportFolder();
                    try {
                        importZip.importZip(content, targetFolder, cms, false);
                    } finally {
                        // get the created resource names
                        for (CmsResource importedResource : importZip.getImportedResources()) {
                            m_resourcesCreated.put(
                                importedResource.getStructureId().toString(),
                                importedResource.getName());
                        }
                    }
                } else {
                    // create the resource
                    CmsResource importedResource = createSingleResource(cms, fileName, targetFolder, content);
                    // add the name of the created resource to the list of successful created resources
                    m_resourcesCreated.put(importedResource.getStructureId().toString(), importedResource.getName());
                }

                if (listener.isCanceled()) {
                    throw listener.getException();
                }
            }
        }
    }
309730
public SIXAResource createXAResource(boolean useSingleResource)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "createXAResource", new Boolean(useSingleResource));

    SIXAResource resource = null;

      //get the message store resource
    resource = transactionFactory.createXAResource();
    
      
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "createXAResource", resource);

    return resource;
  }
71552
@SuppressWarnings("unchecked")
    protected <T extends RepositoryResourceImpl> T createNewResource() {

        T result;
        if (null == getType()) {
            result = (T) createTestResource(getRepositoryConnection());
        } else {
            result = ResourceFactory.getInstance().createResource(getType(), getRepositoryConnection(), null);
        }
        return result;
    }