Java tutorial
/* * Copyright (C) 2012 NS Solutions Corporation * * 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.htmlhifive.tools.jslint.engine.option; import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.Set; import org.apache.commons.lang.StringUtils; import com.htmlhifive.tools.jslint.JSLintPluginConstant; /** * * jsHint,jsLint??.<br> * ?<br> * "jshint,jslint??"<br> * "????","","?","",""<br> * ????????.<br> * ?????jshintjslint???<br> * (?????)<br> * ex.<br> * browser = true,true,Boolean,??,??????????.... * TODO ???JSHint * * @author NS Solutions Corporation * */ public class CheckOptionPropertyWrapper implements CheckOptionFileWrapper { /** * ?. */ private String prefix; /** * . */ private Properties optionProp; /** * .?????. * * @param optionProp . */ public CheckOptionPropertyWrapper(Properties optionProp) { this.optionProp = optionProp; this.prefix = ""; } /* * (? Javadoc) * * @see * com.htmlhifive.tool.jslint.engine.option.CheckOptionWrapper#getOption * (java.lang.String) */ @Override public CheckOption getOption(String key, String engine) { String rawValue = optionProp.getProperty(getPrefix() + key); String[] valueClass = StringUtils.splitPreserveAllTokens(rawValue, JSLintPluginConstant.OPTION_SEPARATOR); Class<?> clazz = null; if (StringUtils.equals(valueClass[2], "Boolean")) { clazz = Boolean.class; } else if (StringUtils.equals(valueClass[2], "Integer")) { clazz = Integer.class; } // TODO ? CheckOption option = new CheckOption(key, "", clazz, valueClass[3], valueClass[4]); option.setValue(valueClass[1]); option.setEnable(Boolean.valueOf(valueClass[0])); return option; } /** * jslint(jshint)??????. * * @return ?. */ protected String getPrefix() { return prefix; } /* * (? Javadoc) * * @see * com.htmlhifive.tool.jslint.engine.option.CheckOptionWrapper#getOptions() */ @Override public CheckOption[] getOptions(Engine engine) { return getOptions(false); } @Override public CheckOption[] getEnableOptions(Engine engine) { return getOptions(true); } /** * ??. * * @param enable ????????. * @return ?. */ private CheckOption[] getOptions(boolean enable) { Set<Object> keySet = optionProp.keySet(); List<CheckOption> optionList = new ArrayList<CheckOption>(); for (Object obj : keySet) { String key = (String) obj; if (StringUtils.startsWith(key, getPrefix())) { String optionKey = StringUtils.remove(key, getPrefix()); CheckOption option = getOption(optionKey, "engine"); if (!enable) { optionList.add(option); } else if (option.isEnable()) { optionList.add(option); } } } return (CheckOption[]) optionList.toArray(new CheckOption[optionList.size()]); } @Override public void saveOption() { // TODO ??? } @Override public void addOption(CheckOption option) { // TODO ??? } @Override public void updateOption(CheckOption option) { // TODO ??? } }