Beispiel #1
0
  static {
    root = new Key();
    root.name = "<root>";
    root.subKeys = new java.util.HashMap();
    java.io.File aliceHasNotExitedFile =
        new java.io.File(
            edu.cmu.cs.stage3.alice.authoringtool.JAlice.getAliceUserDirectory(),
            "aliceHasNotExited.txt");
    if (aliceHasNotExitedFile.canRead()) {
      try {
        storeConfig();
      } catch (java.io.IOException e2) {
        edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.showErrorDialog(
            java.util.ResourceBundle.getBundle(
                    "edu/cmu/cs/stage3/alice/authoringtool/util/Configuration")
                .getString("UNABLE_TO_CREATE_NEW_PREFERENCES_FILE."),
            e2);
      }
    } else {
      try {
        loadConfig(configLocation);
      } catch (Exception e) {

      }
    }
  }
Beispiel #2
0
  private static Key loadKey(org.w3c.dom.Element keyElement) {
    Key key = new Key();

    String visibility = keyElement.getAttribute("visibility").trim();
    if (visibility.equals("open")) {
      key.visibility = VIS_OPEN;
    } else if (visibility.equals("advanced")) {
      key.visibility = VIS_ADVANCED;
    } else if (visibility.equals("hidden")) {
      key.visibility = VIS_HIDDEN;
    }

    java.util.HashMap map = parseSingleNode(keyElement);

    org.w3c.dom.Element nameElement = (org.w3c.dom.Element) map.get("name");
    if (nameElement != null) {
      org.w3c.dom.Text textNode = (org.w3c.dom.Text) parseSingleNode(nameElement).get("text");
      if (textNode != null) {
        key.name = textNode.getData().trim();
      }
    }

    org.w3c.dom.Element valueElement = (org.w3c.dom.Element) map.get("value");
    if (valueElement != null) {
      org.w3c.dom.Element listElement =
          (org.w3c.dom.Element) parseSingleNode(valueElement).get("list");
      if (listElement != null) {
        key.valueList = new java.util.ArrayList();
        java.util.ArrayList items = (java.util.ArrayList) parseSingleNode(listElement).get("items");
        if (items != null) {
          for (java.util.Iterator iter = items.iterator(); iter.hasNext(); ) {
            org.w3c.dom.Element itemElement = (org.w3c.dom.Element) iter.next();
            if (itemElement != null) {
              org.w3c.dom.Text textNode =
                  (org.w3c.dom.Text) parseSingleNode(itemElement).get("text");
              if (textNode != null) {
                key.valueList.add(textNode.getData().trim());
              }
            }
          }
        }
      } else {
        org.w3c.dom.Text textNode = (org.w3c.dom.Text) parseSingleNode(valueElement).get("text");
        if (textNode != null) {
          key.value = textNode.getData().trim();
        }
      }
    }

    java.util.ArrayList keys = (java.util.ArrayList) map.get("keys");
    if (keys != null) {
      for (java.util.Iterator iter = keys.iterator(); iter.hasNext(); ) {
        org.w3c.dom.Element subKeyElement = (org.w3c.dom.Element) iter.next();
        if (subKeyElement != null) {
          if (key.subKeys == null) {
            key.subKeys = new java.util.HashMap();
          }
          Key subKey = loadKey(subKeyElement);
          if ((subKey != null) && (subKey.name != null)) {
            key.subKeys.put(subKey.name, subKey);
          }
        }
      }
    }

    return key;
  }
Beispiel #3
0
  private static void loadConfig(java.io.InputStream is) throws java.io.IOException {
    root.subKeys = new java.util.HashMap();

    javax.xml.parsers.DocumentBuilderFactory factory =
        javax.xml.parsers.DocumentBuilderFactory.newInstance();
    try {
      javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
      org.w3c.dom.Document document = builder.parse(is);

      org.w3c.dom.Element rootElement = document.getDocumentElement();
      rootElement.normalize();

      org.w3c.dom.NodeList childNodes = rootElement.getChildNodes();
      for (int i = 0; i < childNodes.getLength(); i++) {
        org.w3c.dom.Node childNode = childNodes.item(i);
        if (childNode instanceof org.w3c.dom.Element) {
          org.w3c.dom.Element childElement = (org.w3c.dom.Element) childNode;
          String tagName = childElement.getTagName();
          if (tagName.equals("key")) {
            Key subKey = loadKey(childElement);
            if ((subKey != null) && (subKey.name != null)) {
              root.subKeys.put(subKey.name, subKey);
              // System.out.println( "loaded subKey: " + subKey );
            }
          }
        }
      }
      //		} catch( org.xml.sax.SAXParseException spe ) {
      //			if( spe.getException() != null ) {
      //				edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.showErrorDialog( "Error parsing
      // preferences file; line " + spe.getLineNumber() + ", uri " + spe.getSystemId() + "\nmessage:
      // " + spe.getMessage(), spe.getException() );
      //			} else {
      //				edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.showErrorDialog( "Error parsing
      // preferences file; line " + spe.getLineNumber() + ", uri " + spe.getSystemId() + "\nmessage:
      // " + spe.getMessage(), spe );
      //			}
      //		} catch( org.xml.sax.SAXException sxe ) {
      //			if( sxe.getException() != null ) {
      //				edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.showErrorDialog( "Error parsing
      // preferences file.", sxe.getException() );
      //			} else {
      //				edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.showErrorDialog( "Error parsing
      // preferences file.", sxe );
      //			}
      //		} catch( javax.xml.parsers.ParserConfigurationException pce ) {
      //			edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.showErrorDialog( "Error parsing
      // preferences file.", pce );
      //		}
    } catch (Exception e) {
      edu.cmu.cs.stage3.swing.DialogManager.showMessageDialog(
          java.util.ResourceBundle.getBundle(
                  "edu/cmu/cs/stage3/alice/authoringtool/util/Configuration")
              .getString(
                  "ALICE_HAD_TROUBLE_READING_YOUR_PREFERENCES_BUT_WILL_CONTINUE_TO_RUN_NORMALLY"),
          java.util.ResourceBundle.getBundle(
                  "edu/cmu/cs/stage3/alice/authoringtool/util/Configuration")
              .getString("UNABLE_TO_LOAD_PREFERENCES"),
          javax.swing.JOptionPane.WARNING_MESSAGE);
    }
  }