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 (c) 2002-2012 Alibaba Group Holding Limited.
* All rights reserved.
*
* 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 com.alibaba.antx.config.generator;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.alibaba.antx.config.ConfigException;
import com.alibaba.antx.config.descriptor.ConfigDescriptor;
import com.alibaba.antx.config.descriptor.ConfigGenerate;
import com.alibaba.antx.config.props.PropertiesSet;
import com.alibaba.antx.util.StreamUtil;
import com.alibaba.antx.util.StringUtil;
import com.alibaba.antx.util.i18n.LocaleInfo;
import org.apache.velocity.app.event.EventCartridge;
import org.apache.velocity.context.AbstractContext;
import org.apache.velocity.context.Context;
/** 代表一组运行时状态。 */
public class ConfigGeneratorSession {
protected final ConfigGenerator generator;
protected final Map props;
private final Map descriptorLogs;
private final Set processedDestfiles;
private final Map lazyGenerateItems;
private ConfigGenerate currentGenerate;
private InputStream currentInputStream;
private OutputStream currentOutputStream;
protected ConfigGeneratorSession(ConfigGenerator generator, PropertiesSet propSet) {
this.generator = generator;
this.props = propSet.getMergedProperties();
this.descriptorLogs = new HashMap();
this.processedDestfiles = new HashSet();
this.lazyGenerateItems = new HashMap();
// 初始化日志,将被写入到和descriptor并列的目录中。
ConfigDescriptor[] descriptors = generator.getConfigDescriptors();
Date now = new Date();
for (ConfigDescriptor descriptor : descriptors) {
String descriptorName = descriptor.getName();
StringWriter logBuffer = new StringWriter();
PrintWriter log = new PrintWriter(logBuffer, true);
descriptorLogs.put(descriptorName, new Object[] { logBuffer, log, descriptor });
// 初始日志内容
log.println("Last Configured at: " + now);
log.println();
log.println("Base URL: " + descriptor.getBaseURL());
log.println("Descriptor: " + descriptorName);
log.println();
}
}
/** 设置当前输入流。 */
public void setInputStream(InputStream istream) {
this.currentInputStream = istream;
}
/** 设置当前输出流。 */
public void setOutputStream(OutputStream ostream) {
this.currentOutputStream = ostream;
}
/** 取得velocity context。 */
public Context getVelocityContext() {
if (currentGenerate == null) {
throw new IllegalStateException("Have not call nextEntry method yet");
}
final Map descriptorProps = new HashMap(currentGenerate.getConfigDescriptor().getContext());
EventCartridge eventCartridge = new EventCartridge();
eventCartridge.addEventHandler(new PropertiesReferenceInsertionHandler(currentGenerate.getConfigDescriptor(),
props));
Context context = new AbstractContext() {
@Override
public Object internalRemove(Object key) {
return descriptorProps.remove(key);
}
@Override
public Object internalPut(String key, Object value) {
return descriptorProps.put(key, value);
}
@Override
public Object[] internalGetKeys() {
Set