gt:         for (PpdSectionList gpList: ppdRec.extraList){
context: package org.cups4j.ppd;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.StringReader;
  import java.io.UnsupportedEncodingException;
  import java.net.URL;
  import java.security.MessageDigest;
  import java.util.Arrays;
  import java.util.Iterator;
  
  import org.cups4j.CupsPrinter;
  import org.cups4j.operations.AuthInfo;
  import org.cups4j.operations.cups.CupsGetPPDOperation;
  
  public class CupsPpd{
      
      CupsPpdRec ppdRec;
      AuthInfo auth;
      String serviceResolution = "";
      
      public CupsPpd(AuthInfo auth){
          ppdRec = new CupsPpdRec();
          this.auth = auth;
          createStdList();
      }
      
      public String getServiceResolution(){
          return serviceResolution;
      }
      
      public void setServiceResolution(String resolution){
          this.serviceResolution = resolution;
      }
      
      public CupsPpdRec getPpdRec(){
          return ppdRec;
      }
      
      public void setPpdRec(CupsPpdRec rec){
          this.ppdRec = rec;
      }
      
      private void createStdList(){
          ppdRec.stdList = new PpdUiList();
          PpdSectionList groupList = new PpdSectionList();
          groupList.name = "Standard";
          groupList.text = "Standard";
          ppdRec.stdList.add(groupList);
          addOrientation(groupList);
          addCopies(groupList);
          addPageRanges(groupList);
          addPageSides(groupList);
          addFitToPage(groupList);
       }
      
      public String getCupsStdString(){
          return getCupsString(ppdRec.stdList);
      }
      
      public String getCupsExtraString(){
          return getCupsString(ppdRec.extraList);
      }
      
      private String getCupsString(PpdUiList uiList){
          if (uiList == null){
              return "";
          }
          String cupsString = "";
          boolean isNext = false;
          for (PpdSectionList group: uiList){
              for (PpdItemList section: group){
                  if (section.defaultValue.equals(section.savedValue)){
                      continue;
                  }
                  if (isNext)
                      cupsString = cupsString + "#";
                  else
                      isNext = true;
                  cupsString = cupsString + section.name + ":" +
                          section.commandType.toString() + ":" +
                          section.savedValue;
              }
          }
          return cupsString;
      }
      
      public void createPpdRec(CupsPrinter printer, byte[] md5) throws UnsupportedEncodingException, IOException, Exception{
          URL printerUrl = printer.getPrinterUrl();
          CupsGetPPDOperation getPpd = new CupsGetPPDOperation();
          String ppdString = getPpd.getPPDFile(printerUrl, auth);
          createPpdRec(ppdString, md5);
      }
      
      public void createPpdRec(String ppdString, byte[] md5) throws IOException{
          ppdRec.isUpdated = false;
          byte[] mdBytes = {0};
          if (md5 == null){
              md5 = mdBytes;
          }
          try {
               MessageDigest md = MessageDigest.getInstance("MD5");
               mdBytes = md.digest(ppdString.getBytes());
               if (Arrays.equals(mdBytes, md5)){
                  ppdRec.ppdMd5 = mdBytes;
                  return;
              }
          }catch(Exception e){
              System.out.println(e.toString());
          }
          
          ppdRec.ppdMd5 = mdBytes;
          createStdList();
          ppdRec.extraList = new PpdUiList();
          ppdRec.ppdServiceInfo = new PpdServiceInfo();
          PpdSectionList currentGroup = openGroup("General", "General");
          PpdItemList currentSection = null;
          String sectionName = "";
          
          BufferedReader reader = new BufferedReader(new StringReader(ppdString));
          String line;
          while ( (line =reader.readLine()) != null){
              line = line.trim();
              line = line.replace('\t' , ' ');
              if (!line.startsWith("*")){
                  continue;
              }
              if (line.startsWith("*%")){
                  continue;
              }
              //System.out.println(line);
              int cmdPos = line.indexOf(':');
              if (cmdPos < 2){
                  continue;
              }
              //String[] cmdVal = line.split(":");
              //if (cmdVal.length < 2)
              //    continue;
              String cmdVal0 = line.substring(0, cmdPos);
              String cmdVal1 = line.substring(cmdPos+1);
              String value = cmdVal1.trim();
             
              int commandpos = cmdVal0.indexOf(" ");
              String command;
              String option;
              //if (cmdVal0.contains("Resolution")) {
              //    System.out.println();
              //}
              if (commandpos > 0){
                 command = cmdVal0.substring(0, commandpos);
                 option = cmdVal0.substring(commandpos).trim();
              }
              else {
                 command = cmdVal0.trim();
                 option = "";
              }
              command = command.substring(1);
              if (command.length()<2)
                  continue;
  
              if (command.equals("OpenGroup")){
                  OptionPair pr = OptionPair.getOptionPair(value);
                  currentGroup = openGroup(pr.option, pr.text);
              }
              else if (command.equals("CloseGroup")){
                  closeGroup();
              }
              else if (command.equals("OpenUI")){
                  OptionPair pr = OptionPair.getOptionPair(option.substring(1));
                  currentSection = openSection(pr.option, pr.text, currentGroup);
                  currentSection.commandType = CupsType.KEYWORD;
                  sectionName = pr.option;
              }
              else if (command.equals("CloseUI")){
                  currentSection = null;
                  sectionName = "";
              }
             else if (command.equals("PaperDimension")){
                  if (value.equals("")){
                      continue;
                  }
                  
                  //if (cmdVal.length < 2){
                  //   continue;
                  //}
                  
                  ppdRec.ppdServiceInfo.addPaperDimension(option, cmdVal1);
              }
              else {
                  if (currentSection == null)
                      continue;
                  if (command.startsWith("Default")){
                      command = command.substring(7);
                      if (sectionName.equals(command)){
                          currentSection.defaultValue = value;
                          currentSection.savedValue = value;
                      }
                      continue;
                  }
                  if (command.equals("Resolution")){
                      ppdRec.ppdServiceInfo.addResolution(option);
                  }
                  addItem(currentSection, option);
                      
              }
          }
          
          //remove empty groups and ensure a default exists
          Iterator<PpdSectionList> it = ppdRec.extraList.iterator();
          while (it.hasNext()){
          	PpdSectionList section = it.next();
          	if (section.size() == 0){
          		it.remove();
          	}
              else {
                  for (PpdItemList items: section){
                  	if (items.defaultValue.equals("")){
                          items.defaultValue = "default";
                          items.savedValue = "default";
                          addItem(items, "default/default");
                      }
                  	else {
                  		boolean found = false;
                  		for (PpdItem item: items){
                  			if (item.value.equals(items.defaultValue)){
                  				found = true;
                  				break;
                  			}
                  		}
                  		if (!found){
                  			items.add(0, new PpdItem(items, items.defaultValue, items.defaultValue));
                  		}
                  	}
                      if (items.name.equals("Resolution")){
                          ppdRec.ppdServiceInfo.setDefaultResolution(items.defaultValue);
                      }
                      else if (items.name.equals("PageSize")){
                          ppdRec.ppdServiceInfo.setDefaultPaperDimension(items.defaultValue);
                      }
                  }
              }
          }
          
          //if (ppdRec.ppdServiceInfo.getResolutions().isEmpty()){
          //}
  
          //move "general" section to std list
          it = ppdRec.extraList.iterator();
          while (it.hasNext()){
              PpdSectionList section = it.next();
              if (section.name.equals("General")){
                  ppdRec.stdList.add(section);
                  it.remove();
                  break;
              }
          }
          ppdRec.isUpdated = true;
      }
      
      private void addItem(PpdItemList section, String data){
          int pos = data.indexOf('/');
          if (pos < 1){
              return;
          }
          section.add(new PpdItem(section, data.substring(0, pos), data.substring(pos+1)));
      }
      
      private PpdSectionList openGroup(String groupName, String groupText){
          
  