Creates a Velocity context and populates it with replacement values
for our pre-defined placeholders.

@return Returns a velocity context with system and maven properties added
350092
protected VelocityContext createAndPopulateContext()
    {
        VelocityContext context = new VelocityContext();

        context.put( "dependencies", getDependenciesText() );

        context.put( "arguments", getArgumentsText() );

        // Note: properties that contain dots will not be properly parsed by Velocity. 
        // Should we replace dots with underscores ?        
        addPropertiesToContext( System.getProperties(), context );

        MavenProject mavenProject = config.getMavenProject();
        String encoding = config.getEncoding();

        addPropertiesToContext( mavenProject.getProperties(), context );
        addPropertiesToContext( extraConfig.getProperties(), context );

        context.put( "project", mavenProject.getModel() );
        context.put( "jnlpCodebase", extraConfig.getJnlpCodeBase() );

        // aliases named after the JNLP file structure
        context.put( "informationTitle", mavenProject.getModel().getName() );
        context.put( "informationDescription", mavenProject.getModel().getDescription() );
        if ( mavenProject.getModel().getOrganization() != null )
        {
            context.put( "informationVendor", mavenProject.getModel().getOrganization().getName() );
            context.put( "informationHomepage", mavenProject.getModel().getOrganization().getUrl() );
        }

        // explicit timestamps in local and and UTC time zones
        Date timestamp = new Date();
        context.put( "explicitTimestamp", dateToExplicitTimestamp( timestamp ) );
        context.put( "explicitTimestampUTC", dateToExplicitTimestampUTC( timestamp ) );

        context.put( "outputFile", config.getOutputFile().getName() );
        context.put( "mainClass", config.getMainClass() );

        context.put( "encoding", encoding );
        context.put( "input.encoding", encoding );
        context.put( "output.encoding", encoding );

        // TODO make this more extensible
        context.put( "allPermissions", BooleanUtils.toBoolean( extraConfig.getAllPermissions() ) );
        context.put( "offlineAllowed", BooleanUtils.toBoolean( extraConfig.getOfflineAllowed() ) );
        context.put( "jnlpspec", extraConfig.getJnlpSpec() );
        context.put( "j2seVersion", extraConfig.getJ2seVersion() );
        context.put( "iconHref", extraConfig.getIconHref() );
        // FIXME: 7/18/2017 Where is extraConfig's implementation so getIconHref can be added to it?

        return context;
    }
1192401
public static TracyThreadContext createWorkerTheadContext() {
        TracyThreadContext currentCtx = threadContext.get();
        TracyThreadContext workerCtx = null;
        if (isValidContext(currentCtx))  {
            workerCtx = new TracyThreadContext(
                currentCtx.getTaskId(), currentCtx.getOptId(), null);
        }
        return workerCtx;
    }
1245457
protected IContext makeContext()
	{
		final HttpCallContext http = HttpCallContext.peek();

		if (http != null)
		{
			return new WebContext(http.getRequest(), http.getResponse(), http.getServletContext(), http.getRequest().getLocale());
		}
		else
		{
			return new Context();
		}
	}
117338
protected synchronized PrefixedProperties createProperties() {
		if (myProperties == null) {
			PrefixedProperties resultProperties = null;
			String environment = defaultPrefix;
			if (environmentFactory != null) {
				environment = environmentFactory.getEnvironment();
			} else if (defaultPrefixSystemPropertyKey != null) {
				environment = System.getProperty(defaultPrefixSystemPropertyKey);
				if (environment == null) {
					if (logger.isWarnEnabled()) {
						logger.warn(String.format("Didn't found system property key to set default prefix: %1s",
								defaultPrefixSystemPropertyKey));
					}
				}
			}
			if (prefixConfigList != null) {
				resultProperties = PrefixedProperties.createCascadingPrefixProperties(prefixConfigList);
			} else {
				if (environment != null) {
					resultProperties = PrefixedProperties.createCascadingPrefixProperties(environment);
				} else {
					resultProperties = new PrefixedProperties();
				}
			}
			resultProperties.setDefaultPrefix(environment);
			if (logger.isInfoEnabled()) {
				logger.info(String.format("Setting default prefix to: %1s", environment));
			}
			resultProperties.setMixDefaultAndLocalPrefixSettings(mixDefaultAndLocalPrefixConfigurations);
			myProperties = resultProperties;
		}
		return myProperties;
	}
31165
@Override
  protected void configure(ValueParser values) {
    String altkey = values.getString("key");
    if (altkey != null) {
      setKey(altkey);
    }

    // allow changing skin key in the configuration
    String altSkinKey = values.getString("skinKey");
    if (altSkinKey != null) {
      this.skinKey = altSkinKey;
    }

    // retrieve the decoration model from Velocity context
    Object velocityContext = values.get("velocityContext");

    if (!(velocityContext instanceof ToolContext)) {
      return;
    }

    ToolContext ctxt = (ToolContext)velocityContext;

    Object projectObj = ctxt.get("project");
    if (projectObj instanceof MavenProject) {
      MavenProject project = (MavenProject)projectObj;
      String artifactId = project.getArtifactId();
      // use artifactId "sluggified" as the projectId
      projectId = HtmlTool.slug(artifactId);
    }

    // calculate the page ID from the current file name
    Object currentFileObj = ctxt.get("currentFileName");
    if (currentFileObj instanceof String) {

      String currentFile = (String)currentFileObj;

      // drop the extension
      int lastDot = currentFile.lastIndexOf(".");
      if (lastDot >= 0) {
        currentFile = currentFile.substring(0, lastDot);
      }

      // full file ID includes the nested dirs
      // replace nesting "/" with "-"
      fileId = HtmlTool.slug(currentFile.replace("/", "-").replace("\\", "-"));
    }

    Object decorationObj = ctxt.get("decoration");

    if (!(decorationObj instanceof DecorationModel)) {
      return;
    }

    DecorationModel decoration = (DecorationModel)decorationObj;
    Object customObj = decoration.getCustom();

    if (!(customObj instanceof Xpp3Dom)) {
      return;
    }

    // Now that we have the custom node, get the global properties
    // under the skin tag
    Xpp3Dom customNode = (Xpp3Dom)customObj;
    Xpp3Dom skinNode = customNode.getChild(skinKey);
    String namespaceKey = ":" + skinKey;

    if (skinNode == null) {
      // try searching with any namespace
      for (Xpp3Dom child : customNode.getChildren()) {
        if (child.getName().endsWith(namespaceKey)) {
          skinNode = child;
          break;
        }
      }
    }

    if (skinNode != null) {
      globalProperties = skinNode;

      if (skinNode.getName().endsWith(namespaceKey)) {
        // extract the namespace (including the colon)
        namespace = skinNode.getName().substring(0, skinNode.getName().length() - namespaceKey.length() + 1);
      }

      // for page properties, retrieve the file name and drop the `.html`
      // extension - this will be used, i.e. `index` instead of `index.html`
      Xpp3Dom pagesNode = getChild(skinNode, "pages");
      if (pagesNode != null) {

        // Get the page for the file
        // TODO try fileShortId as well?
        Xpp3Dom page = getChild(pagesNode, fileId);

        // Now check if the project artifact ID is set, and if so, if it matches the
        // current project. This allows preventing accidental reuse of parent page
        // configs in children modules
        if (page != null && projectId != null) {
          String pageProject = page.getAttribute("project");
          if (pageProject != null && !projectId.equals(pageProject)) {
            // project ID indicated, and is different - do not use the config
            page = null;
          }
        }

        if (page != null) {
          pageProperties = page;
        }
      }
    }
  }
173257
public static JKContext getCurrentContext() {
		JKContext context = (JKContext) JKThreadLocal.getValue(JKContextConstants.JK_CONTEXT);
		if (context == null) {
			context = getInstance().createDesktopContext();
			JKThreadLocal.setValue(JKContextConstants.JK_CONTEXT, context);
		}
		return context;
	}
37095
protected VelocityEngine getVelocityEngine(List<String> paths) {
		VelocityEngine ve = new VelocityEngine();
		ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
		ve.setProperty("cp.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
		ve.setProperty("cp.resource.loader.cache", "true");
		ve.setProperty("cp.resource.loader.path", StringUtils.join(paths, ","));
		ve.setProperty("cp.resource.loader.modificationCheckInterval ", "10");
		ve.setProperty("input.encoding", "UTF-8");
		ve.setProperty("output.encoding", "UTF-8");
		ve.setProperty("runtime.log", "");
		return ve;
	}
136522
public ParamValueType<WebAppDescriptor> getOrCreateContextParam()
   {
      List<Node> nodeList = model.get("context-param");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new ParamValueTypeImpl<WebAppDescriptor>(this, "context-param", model, nodeList.get(0));
      }
      return createContextParam();
   }
855633
public ContextItems getMarshaledContext() {
        ContextItems marshaledContext = new ContextItems();

        for (IManagedContext<?> managedContext : managedContexts) {
            marshaledContext.addItems(managedContext.getContextItems(false));
        }

        return marshaledContext;
    }
1102342
public AvroMultiRuntimeDefinition build(){
    Validate.isTrue(this.runtimes.size() == 1 || !StringUtils.isEmpty(this.defaultRuntime), "Default runtime " +
            "should be set if more than a single runtime provided");

    if(StringUtils.isEmpty(this.defaultRuntime)){
      // we have single runtime configured, take its name as a default
      this.defaultRuntime = this.runtimes.keySet().iterator().next();
    }

    Validate.isTrue(this.runtimes.containsKey(this.defaultRuntime), "Default runtime should be configured");
    return new AvroMultiRuntimeDefinition(defaultRuntime, new ArrayList<>(this.runtimes.values()));
  }
921351
public static ActorSystem createAndGetActorSystem() {
        if (actorSystem == null || actorSystem.isTerminated()) {
            actorSystem = ActorSystem.create(PcConstants.ACTOR_SYSTEM, conf);
        }
        return actorSystem;
    }
99285
public JellyContext createContext() {
        JellyContext context = new CustomJellyContext(ROOT_CONTEXT);
        context.setClassLoader(owner.loader);
        context.setExportLibraries(false);
        return context;
    }
702274
public OkVolley init(Context context) {
        this.mContext = context;
        InstanceRequestQueue = newRequestQueue(context);
        mUserAgent = generateUserAgent(context);
        mRequestHeaders = new HashMap<>();
        mRequestHeaders.put(OkRequest.HEADER_USER_AGENT, mUserAgent);
        mRequestHeaders.put(OkRequest.HEADER_ACCEPT_CHARSET, OkRequest.CHARSET_UTF8);
        return this;
    }
987767
@Nonnull
  public static ServletAsyncSpec createAsyncDefault ()
  {
    return createAsync (GlobalDebug.isDebugMode () ? 999_999 * CGlobal.MILLISECONDS_PER_SECOND
                                                   : 30 * CGlobal.MILLISECONDS_PER_SECOND,
                        null);
  }
944799
@Override
    protected void doInitialize() throws ComponentInitializationException {
        log.debug("Initialized {}", this.getClass().getSimpleName());
        if (getMessageContext() == null) {
            throw new ComponentInitializationException("Message context cannot be null");
        }
        if (getVelocityEngine() == null) {
            throw new ComponentInitializationException("VelocityEngine must be supplied");
        }
        if (getVelocityTemplateId() == null) {
            throw new ComponentInitializationException("Velocity template id must be supplied");
        }
    }
609442
public ReturnValue create() {
        if (forcedStatus == null) {
            retVal.withStatus(status);
        } else {
            retVal.withStatus(forcedStatus);
        }

        StringBuilder msg = new StringBuilder(pluginName).append(" : ").append(retVal.getStatus());
        if (!StringUtils.isEmpty(retValMessage)) {
            msg.append(" - ").append(retValMessage);
        }

        retVal.withMessage(msg.toString());

        return retVal;
    }
169088
public static ScmOperationContextBuilder builder(ScmOperationContext context) {
        ScmOperationContextBuilder builder = new ScmOperationContextBuilder();
        builder.impl = new ScmOperationContextImpl(context);
        return builder;
    }