Permalink
Browse files

Fixed bug in parser and made autoconfiginfo class more robust ( by be…

…ing more strict on server types ).
  • Loading branch information...
1 parent 0922887 commit 8e4e934c25495470eb038b422541ace099e1467e dzan committed Jul 20, 2011
@@ -13,6 +13,8 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Pair;
+import com.fsck.k9.K9;
+import org.w3c.dom.Text;
/*
NOTE: We assume here there is one emailprovider in a file with the data version information in a one-on-one relation
@@ -349,8 +351,8 @@ public void writeToParcel(Parcel parcel, int i) {
public String displayShortName;
// Possible servers for this ISP
- public List<Server> incomingServer;
- public List<Server> outgoingServer;
+ public List<IncomingServer> incomingServer;
+ public List<OutgoingServer> outgoingServer;
// Configuration help/information
public String identity;
@@ -365,8 +367,8 @@ public void writeToParcel(Parcel parcel, int i) {
*/
public AutoconfigInfo(){
// initialise the fields
- incomingServer = new ArrayList<Server>();
- outgoingServer = new ArrayList<Server>();
+ incomingServer = new ArrayList<IncomingServer>();
+ outgoingServer = new ArrayList<OutgoingServer>();
domains = new ArrayList<String>();
inputFields = new ArrayList<InputField>();
}
@@ -380,6 +382,14 @@ public AutoconfigInfo(Parcel parcel){
displayName = parcel.readString();
displayShortName = parcel.readString();
+ incomingServer = parcel.readArrayList(IncomingServer.class.getClassLoader());
+ outgoingServer = parcel.readArrayList(OutgoingServer.class.getClassLoader());
+
+ identity = parcel.readString();
+ inputFields = parcel.readArrayList(InputField.class.getClassLoader());
+ enable = (InformationBlock) parcel.readValue(InformationBlock.class.getClassLoader());
+ instruction = (InformationBlock) parcel.readValue(InformationBlock.class.getClassLoader());
+ documentation = (InformationBlock) parcel.readValue(InformationBlock.class.getClassLoader());
}
@@ -407,20 +417,21 @@ public AutoconfigInfo(Parcel parcel){
}
// filters the list of servers according to the arguments ( list of allowed specifications )
- private List<Server> getFilteredServerList
- (List<Server> serverList, List<ServerType> serverTypes, List<AuthenticationType> authenticationTypes, List<SocketType> socketTypes){
- ArrayList<Server> servers = new ArrayList<Server>();
- ArrayList<Server> toBeRemoved = new ArrayList<Server>();
+ private <T extends Server> List<T> getFilteredServerList
+ (List<T> serverList, List<ServerType> serverTypes, List<AuthenticationType> authenticationTypes, List<SocketType> socketTypes)
+ {
+ ArrayList<T> servers = new ArrayList<T>();
+ ArrayList<T> toBeRemoved = new ArrayList<T>();
// filter for servertypes
if( serverTypes != null && !serverTypes.isEmpty() )
- for( Server serv : serverList )
+ for( T serv : serverList )
if( serverTypes.contains(serv.type))
servers.add(serv);
// filter for autenticationtype
if( authenticationTypes != null & !authenticationTypes.isEmpty() ){
- for( Server serv : servers )
+ for( T serv : servers )
if( !authenticationTypes.contains(serv.authentication) )
toBeRemoved.add(serv);
}
@@ -429,7 +440,7 @@ public AutoconfigInfo(Parcel parcel){
// filter for sockettype
if( socketTypes != null & !socketTypes.isEmpty() )
- for( Server serv : servers )
+ for( T serv : servers )
if( !socketTypes.contains(serv.socketType) )
toBeRemoved.add(serv);
servers.removeAll(toBeRemoved);
@@ -438,12 +449,12 @@ public AutoconfigInfo(Parcel parcel){
}
// public wrappers for the filter method
- public List<Server> getOutgoingServers
+ public List<OutgoingServer> getOutgoingServers
(List<ServerType> serverTypes, List<AuthenticationType> authenticationTypes, List<SocketType> socketTypes){
return getFilteredServerList(outgoingServer, serverTypes, authenticationTypes, socketTypes);
}
- public List<Server> getIncomingServers
+ public List<IncomingServer> getIncomingServers
(List<ServerType> serverTypes, List<AuthenticationType> authenticationTypes, List<SocketType> socketTypes){
return getFilteredServerList(incomingServer, serverTypes, authenticationTypes, socketTypes);
}
@@ -48,6 +48,8 @@
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.OutgoingServerSMTP;
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.InputField;
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.InformationBlock;
+import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.IncomingServer;
+import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.OutgoingServer;
// Other
import java.util.HashMap;
@@ -288,7 +290,10 @@ public void startElement(String uri, String localName, String qName,
String type = attributes.getValue(ATTRIBUTE.TYPE.getXMLStringVersion());
if( type != null ){
mServerInProgress = ServerType.toType(type).getServerObject(null);
- mAutoconfigInfo.incomingServer.add(mServerInProgress);
+ if( TAG.toTag(localName) == TAG.INCOMINGSERVER )
+ mAutoconfigInfo.incomingServer.add((IncomingServer)mServerInProgress);
+ else if( TAG.toTag(localName) == TAG.OUTGOINGSERVER )
+ mAutoconfigInfo.outgoingServer.add((OutgoingServer)mServerInProgress);
}else{ // this should never happen, this file is not formed correctly ( check the relaxng scheme )
throw new SAXParseException("Incoming|Outgoing-Server tag has no type attribute!", mLocator);
}break;

0 comments on commit 8e4e934

Please sign in to comment.