下面列出了java.lang.String#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static Object instantiateXMLService(String serviceName) throws Exception {
ClassLoader backup = Thread.currentThread().getContextClassLoader();
try {
// set thread context class loader to module class loader
Thread.currentThread().setContextClassLoader(XMLFactoryHelper.class.getClassLoader());
if (serviceName.equals("org.xml.sax.XMLReader"))
return XMLReaderFactory.createXMLReader();
else if (serviceName.equals("javax.xml.validation.SchemaFactory"))
return Class.forName(serviceName).getMethod("newInstance", String.class)
.invoke(null, W3C_XML_SCHEMA_NS_URI);
else
return Class.forName(serviceName).getMethod("newInstance").invoke(null);
} finally {
Thread.currentThread().setContextClassLoader(backup);
}
}
/**
* Indentation before start tag. Always indent.
*
* @param localName the local tag name
* @throws XMLStreamException
*/
private void indentStart (String localName)
throws XMLStreamException
{
if (INDENT != null) {
// Insert visible comment lines only for measures and parts
if (localName.equals("measure")) {
doIndent();
super.writeComment("=======================================================");
} else if (localName.equals("part")) {
doIndent();
super.writeComment("= = = = = = = = = = = = = = = = = = = = = = = = = = = = =");
}
doIndent();
level++;
closing = false;
}
}
@Nullable
public SimpleXmlElement getChild(@Nonnull String tagName) {
if (myChildren.isEmpty()) {
return null;
}
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < myChildren.size(); i++) {
SimpleXmlElement element = myChildren.get(i);
if (tagName.equals(element.getName())) {
return element;
}
}
return null;
}
@Nonnull
public List<SimpleXmlElement> getChildren(@Nonnull String tagName) {
if (myChildren.isEmpty()) {
return Collections.emptyList();
}
List<SimpleXmlElement> list = new ArrayList<SimpleXmlElement>();
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < myChildren.size(); i++) {
SimpleXmlElement element = myChildren.get(i);
if (tagName.equals(element.getName())) {
list.add(element);
}
}
return list;
}
public static void refresh() {
synchronized (Net.class) {
String json = AppCache.getInstance().getString(SP_NAME);
if (json == null || json.equals("")) {
instance = null;
} else {
instance = (Net) mGson.fromJson(json, Net.class);
}
}
}
/**
* @return the navigation rule. This will be null if none was found
**/
private NavigationRule getRuleWithFromViewID(FacesConfig facesConfig, String fromViewId) {
for (NavigationRule navRule : facesConfig.getNavigationRules()) {
String rulefromViewId = FacesModelUtility.getFromViewIdFiltered(navRule);
if (rulefromViewId != null && rulefromViewId.equals(fromViewId)) {
// Match Found
return navRule;
}
}
return null;
}
/**
* Check if the file type in known.
* @param file the fileobject type to check. If null, throws NPE.
* @return if it is of type jsp, jspf, or html it will return true.
*/
public final boolean isKnownFile(FileObject file) {
String[] knownMimeTypes = {"text/x-jsp", "text/html", "text/xhtml"}; //NOI18N
String mimeType = file.getMIMEType(knownMimeTypes);
if (mimeType.equals("text/x-jsp") && !file.getExt().equals("jspf")) { //NOI18N
return true;
} else if (mimeType.equals("text/html") || mimeType.equals("text/xhtml")) { //NOI18N
return true;
}
return false;
}
/**
* Givena pageName, look through the list of predefined webFiles and return the matching fileObject
* @return FileObject for which the match was found or null of none was found.
**/
private FileObject getFileObject(String pageName) {
for (FileObject webFile : webFiles) {
//DISPLAYNAME:
String webFileName = Page.getFolderDisplayName(getWebFolder(), webFile);
// String webFileName = webFile.getNameExt();
if (webFileName.equals(pageName)) {
return webFile;
}
}
return null;
}
/**
* Remove all rules and cases with this pagename.
* @param displayName
*/
public void removePageInModel(String displayName) {
configModel.startTransaction();
FacesConfig facesConfig = configModel.getRootComponent();
List<NavigationRule> navRules = facesConfig.getNavigationRules();
for (NavigationRule navRule : navRules) {
String fromViewId = FacesModelUtility.getFromViewIdFiltered(navRule);
if (fromViewId != null && fromViewId.equals(displayName)) {
//if the rule is removed, don't check the cases.
facesConfig.removeNavigationRule(navRule);
} else {
List<NavigationCase> navCases = navRule.getNavigationCases();
for (NavigationCase navCase : navCases) {
// String toViewId = navCase.getToViewId();
String toViewId = FacesModelUtility.getToViewIdFiltered(navCase);
if (toViewId != null && toViewId.equals(displayName)) {
navRule.removeNavigationCase(navCase);
}
}
}
}
try {
configModel.endTransaction();
configModel.sync();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
} catch (IllegalStateException ise) {
Exceptions.printStackTrace(ise);
}
}
public void toggleCheckbox( String value ) {
FormControl[] controls = getControls();
for (int i = 0; i < controls.length; i++) {
FormControl control = controls[i];
if (value.equals( control.getValueAttribute())) {
control.toggle();
return;
}
}
throw new IllegalCheckboxParameterException( _name + "/" + value , "toggleCheckbox" );
}
public void setValue( String value, boolean state ) {
FormControl[] controls = getControls();
for (int i = 0; i < controls.length; i++) {
FormControl control = controls[i];
if (value.equals( control.getValueAttribute())) {
control.setState( state );
return;
}
}
throw new IllegalCheckboxParameterException( _name + "/" + value , "setCheckbox" );
}
@SuppressWarnings("deprecation")
FieldSet parseSpecialValues(String name)
{
if (name.equals("[id]")) { return new DocIdOnly(); }
else if (name.equals("[all]")) { return (new AllFields()); }
else if (name.equals("[none]")) { return (new NoFields()); }
else if (name.equals("[header]")) { return (new HeaderFields()); }
else if (name.equals("[docid]")) { return (new DocIdOnly()); }
else if (name.equals("[body]")) { return (new BodyFields()); }
else {
throw new IllegalArgumentException(
"The only special names (enclosed in '[]') allowed are " +
"id, all, none, header, body");
}
}
@Override
@Nullable
protected MatchResult matchAndParseHeader(String headerName, String headerValue) {
if (headerName.equals(TEST_HEADER_NAME) && headerValue.equals(TEST_HEADER_VALUE)) {
return new MatchResult("https://www.facebook.com", PrettyPrinterDisplayType.TEXT);
} else {
return null;
}
}
@Override
protected String getCacheKey(HttpServletRequest req, HttpMethod method, String action) {
// caching is possible only for userlist and viewuser
String editAction=req.getParameter("editAction");
if(editAction==null) editAction="userlist";
if(!editAction.equals("viewuser") && !editAction.equals("userlist")) return null;
else return super.getCacheKey(req, method, action);
}
@SuppressWarnings("unchecked")
public static String createColumnDefinition(TableInfo tableInfo, Field field) {
StringBuilder definition = new StringBuilder();
Class<?> type = field.getType();
final String name = tableInfo.getColumnName(field);
final TypeSerializer typeSerializer = Cache.getParserForType(field.getType());
final Column column = field.getAnnotation(Column.class);
if (typeSerializer != null) {
type = typeSerializer.getSerializedType();
}
if (TYPE_MAP.containsKey(type)) {
definition.append(name);
definition.append(" ");
definition.append(TYPE_MAP.get(type).toString());
}
else if (ReflectionUtils.isModel(type)) {
definition.append(name);
definition.append(" ");
definition.append(SQLiteType.INTEGER.toString());
}
else if (ReflectionUtils.isSubclassOf(type, Enum.class)) {
definition.append(name);
definition.append(" ");
definition.append(SQLiteType.TEXT.toString());
}
if (!TextUtils.isEmpty(definition)) {
if (name.equals(tableInfo.getIdName())) {
definition.append(" PRIMARY KEY AUTOINCREMENT");
}else if(column!=null){
if (column.length() > -1) {
definition.append("(");
definition.append(column.length());
definition.append(")");
}
if (column.notNull()) {
definition.append(" NOT NULL ON CONFLICT ");
definition.append(column.onNullConflict().toString());
}
if (column.unique()) {
definition.append(" UNIQUE ON CONFLICT ");
definition.append(column.onUniqueConflict().toString());
}
}
if (FOREIGN_KEYS_SUPPORTED && ReflectionUtils.isModel(type)) {
definition.append(" REFERENCES ");
definition.append(Cache.getTableInfo((Class<? extends Model>) type).getTableName());
definition.append("("+tableInfo.getIdName()+")");
definition.append(" ON DELETE ");
definition.append(column.onDelete().toString().replace("_", " "));
definition.append(" ON UPDATE ");
definition.append(column.onUpdate().toString().replace("_", " "));
}
}
else {
Log.e("No type mapping for: " + type.toString());
}
return definition.toString();
}
@SuppressWarnings("unchecked")
public static String createColumnDefinition(TableInfo tableInfo, Field field) {
StringBuilder definition = new StringBuilder();
Class<?> type = field.getType();
final String name = tableInfo.getColumnName(field);
final TypeSerializer typeSerializer = Cache.getParserForType(field.getType());
final Column column = field.getAnnotation(Column.class);
if (typeSerializer != null) {
type = typeSerializer.getSerializedType();
}
if (TYPE_MAP.containsKey(type)) {
definition.append(name);
definition.append(" ");
definition.append(TYPE_MAP.get(type).toString());
}
else if (ReflectionUtils.isModel(type)) {
definition.append(name);
definition.append(" ");
definition.append(SQLiteType.INTEGER.toString());
}
else if (ReflectionUtils.isSubclassOf(type, Enum.class)) {
definition.append(name);
definition.append(" ");
definition.append(SQLiteType.TEXT.toString());
}
if (!TextUtils.isEmpty(definition)) {
if (name.equals(tableInfo.getIdName())) {
definition.append(" PRIMARY KEY AUTOINCREMENT");
}else if(column!=null){
if (column.length() > -1) {
definition.append("(");
definition.append(column.length());
definition.append(")");
}
if (column.notNull()) {
definition.append(" NOT NULL ON CONFLICT ");
definition.append(column.onNullConflict().toString());
}
if (column.unique()) {
definition.append(" UNIQUE ON CONFLICT ");
definition.append(column.onUniqueConflict().toString());
}
}
if (FOREIGN_KEYS_SUPPORTED && ReflectionUtils.isModel(type)) {
definition.append(" REFERENCES ");
definition.append(Cache.getTableInfo((Class<? extends Model>) type).getTableName());
definition.append("("+tableInfo.getIdName()+")");
definition.append(" ON DELETE ");
definition.append(column.onDelete().toString().replace("_", " "));
definition.append(" ON UPDATE ");
definition.append(column.onUpdate().toString().replace("_", " "));
}
}
else {
Log.e("No type mapping for: " + type.toString());
}
return definition.toString();
}
@Override
protected HashMap<String, Object> getTemplateContext(Template template, HttpServletRequest req, HttpMethod method, String action, User user) throws ActionException {
String editAction=req.getParameter("editaction");
if(editAction==null || editAction.length()==0) editAction="userlist";
HashMap<String,Object> params=super.getTemplateContext(template, req, method, action, user);
String userName=req.getParameter("user");
if(userName!=null) userName=userName.trim();
if(userName!=null && userName.length()==0) userName=null;
User userObject=null;
String view="userlist";
String error=null;
try{
if(editAction.equals("userlist")){
// no side effects, do nothing
}
else if(editAction.equals("viewuser")){
view="user";
// just check that the user is valid
if(userName!=null) userObject=userStore.getUser(userName);
}
else if(editAction.equals("edituser") || editAction.equals("edituserlist")){
view="user";
if(editAction.equals("edituserlist")) view="userlist";
if(userName!=null) {
userObject=userStore.getUser(userName);
if(userObject!=null){
Enumeration<String> paramNames=req.getParameterNames();
while(paramNames.hasMoreElements()){
String key=paramNames.nextElement();
String[] values=req.getParameterValues(key);
for(String value : values){
value=value.trim();
if(key.equals("setoption")){
int ind=value.indexOf("=");
if(ind<0) userObject.setOption(value, "");
else {
String k=value.substring(0,ind);
String v=value.substring(ind+1);
userObject.setOption(k,v);
}
}
else if(key.equals("removeoption")){
userObject.removeOption(value);
}
else if(key.equals("addrole")){
userObject.addRole(value);
}
else if(key.equals("removerole")){
userObject.removeRole(value);
}
}
}
if(!userObject.saveUser()) error="NOEDIT";
}
}
}
else if(editAction.equals("deleteuser")){
if(userName!=null) {
if(!userStore.deleteUser(userName)) error="NODELETE";
}
}
else if(editAction.equals("newuser")){
view="user";
if(userName!=null) {
userObject=userStore.newUser(userName);
if(userObject==null) error="NONEW";
}
}
else return null;
if(view.equals("user") && userObject==null) {
if(error==null) error="INVALIDUSER";
view="userlist";
}
if(view.equals("userlist")){
params.put("allUsers",userStore.getAllUsers());
}
else {
params.put("user",userObject);
}
}catch(UserStoreException use){
if(error==null) error="USERSTORE";
}
params.put("editView",view);
params.put("error",error);
return params;
}