private String documentRoot() {
   if (_documentRoot == null) {
     _documentRoot = ERXProperties.stringForKey("WODocumentRoot");
     if (_documentRoot == null) {
       NSBundle bundle = NSBundle.bundleForName("JavaWebObjects");
       NSDictionary dict =
           ERXDictionaryUtilities.dictionaryFromPropertyList("WebServerConfig", bundle);
       _documentRoot = (String) dict.objectForKey("DocumentRoot");
     }
   }
   return _documentRoot;
 }
Esempio n. 2
0
  public ERClientApplication() {
    NSBundle mainBundle =
        NSBundle
            .mainBundle(); // causes the bundle to be loaded and evaluated (will load Properties)
    if (mainBundle == null) {
      throw new IllegalStateException("Main bundle not found");
    }

    userDefaults = Preferences.userNodeForPackage(getClass());

    ERXLogger.configureLoggingWithSystemProperties();
  }
Esempio n. 3
0
 public NSArray allTests() {
   if (allTests == null) {
     String thisBundleName = NSBundle.bundleForClass(getClass()).name();
     NSMutableSet theClassNames = new NSMutableSet();
     Enumeration bundleEnum = bundles().objectEnumerator();
     while (bundleEnum.hasMoreElements()) {
       NSBundle bundle = (NSBundle) bundleEnum.nextElement();
       if (!bundle.name().equals(thisBundleName)) {
         Enumeration classNameEnum = bundle.bundleClassNames().objectEnumerator();
         while (classNameEnum.hasMoreElements()) {
           String className = (String) classNameEnum.nextElement();
           if (className != null
               && (className.endsWith("Test")
                   || className.endsWith("TestCase")
                   || className.indexOf("tests.") == 0
                   || className.indexOf(".tests.") > 0)
               && !className.startsWith("junit.")
               && className.indexOf("$") < 0) {
             try {
               Class c = ERXPatcher.classForName(className);
               // if(c != null && c.isAssignableFrom(TestCase.class))
               theClassNames.addObject(munge(className));
             } catch (Exception ex) {
               // ignored
               log.warn("Skipping test " + className + ": " + ex);
             }
           }
         }
       }
     }
     allTests = theClassNames.allObjects();
     try {
       allTests = allTests.sortedArrayUsingComparator(NSComparator.AscendingStringComparator);
     } catch (Exception ex) {
       log.warn(ex);
       // so we won't get sorted, oh well :)
     }
   }
   return allTests;
 }
Esempio n. 4
0
  /**
   * This is usually extracted from the the database using JDBC, but this is really inconvenient for
   * users who are trying to generate SQL at some. A specific version of the data has been written
   * into the property list of the framework and this can be used as a hard-coded equivalent.
   */
  public NSDictionary jdbcInfo() {
    // you can swap this code out to write the property list out in order
    // to get a fresh copy of the JDBCInfo.plist.
    //    try {
    //      String jdbcInfoS = NSPropertyListSerialization.stringFromPropertyList(super.jdbcInfo());
    //      FileOutputStream fos = new FileOutputStream("/tmp/JDBCInfo.plist");
    //      fos.write(jdbcInfoS.getBytes());
    //      fos.close();
    //    }
    //    catch(Exception e) {
    //      throw new IllegalStateException("problem writing JDBCInfo.plist",e);
    //    }

    NSDictionary jdbcInfo;
    // have a look at the JDBC connection URL to see if the flag has been set to
    // specify that the hard-coded jdbcInfo information should be used.
    if (shouldUseBundledJdbcInfo()) {
      if (NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelDetailed)) {
        NSLog.debug.appendln(
            "Loading jdbcInfo from JDBCInfo.plist as opposed to using the JDBCPlugIn default implementation.");
      }

      InputStream jdbcInfoStream =
          NSBundle.bundleForClass(getClass()).inputStreamForResourcePath("JDBCInfo.plist");
      if (jdbcInfoStream == null) {
        throw new IllegalStateException("Unable to find 'JDBCInfo.plist' in this plugin jar.");
      }

      try {
        jdbcInfo =
            (NSDictionary)
                NSPropertyListSerialization.propertyListFromData(
                    new NSData(jdbcInfoStream, 2048), "US-ASCII");
      } catch (IOException e) {
        throw new RuntimeException("Failed to load 'JDBCInfo.plist' from this plugin jar.", e);
      } finally {
        try {
          jdbcInfoStream.close();
        } catch (IOException e) {
        }
      }
    } else {
      jdbcInfo = super.jdbcInfo();
    }
    return jdbcInfo;
  }
Esempio n. 5
0
  private boolean isRobot(String userAgent) {
    synchronized (robotExpressions) {
      if (robotExpressions.count() == 0) {
        String strings =
            ERXStringUtilities.stringFromResource(
                "robots", "txt", NSBundle.bundleForName("ERExtensions"));
        for (String item : NSArray.componentsSeparatedByString(strings, "\n")) {
          if (item.trim().length() > 0 && item.charAt(0) != '#') {
            robotExpressions.addObject(Pattern.compile(item));
          }
        }
      }
      userAgent = userAgent.toLowerCase();
      for (Pattern pattern : robotExpressions) {
        if (pattern.matcher(userAgent).find()) {
          log.debug(pattern + " matches  " + userAgent);
          return true;
        }
      }
    }

    return false;
  }
Esempio n. 6
0
 protected NSArray bundles() {
   NSMutableArray bundles = new NSMutableArray(NSBundle.frameworkBundles());
   bundles.addObject(NSBundle.mainBundle());
   return bundles;
 }
Esempio n. 7
0
  @Override
  @SuppressWarnings({"unchecked", "rawtypes"})
  public NSDictionary<String, Object> jdbcInfo() {

    NSDictionary<String, Object> jdbcInfo;
    // have a look at the JDBC connection URL to see if the flag has been set to
    // specify that the hard-coded jdbcInfo information should be used.
    if (shouldUseBundledJdbcInfo()) {
      if (NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelDetailed)) {
        NSLog.debug.appendln(
            "Loading jdbcInfo from JDBCInfo.plist as opposed to using the JDBCPlugIn default implementation.");
      }

      InputStream jdbcInfoStream =
          NSBundle.bundleForClass(getClass()).inputStreamForResourcePath("JDBCInfo.plist");
      if (jdbcInfoStream == null) {
        throw new IllegalStateException("Unable to find 'JDBCInfo.plist' in this plugin jar.");
      }

      try {
        jdbcInfo =
            (NSDictionary<String, Object>)
                NSPropertyListSerialization.propertyListFromData(
                    new NSData(jdbcInfoStream, 2048), "US-ASCII");
      } catch (IOException e) {
        throw new RuntimeException("Failed to load 'JDBCInfo.plist' from this plugin jar.", e);
      }

    } else {

      NSMutableDictionary<String, Object> mutableInfo = super.jdbcInfo().mutableClone();
      NSMutableDictionary<String, NSDictionary> typeInfo =
          ((NSDictionary<String, NSDictionary>) mutableInfo.objectForKey("typeInfo"))
              .mutableClone();
      NSDictionary textTypeInfo = typeInfo.objectForKey("TEXT");
      if (textTypeInfo != null) {
        Object rawCreateParams = textTypeInfo.objectForKey("createParams");
        if (!rawCreateParams.equals("1")) {
          NSMutableDictionary newRawTypeInfo = textTypeInfo.mutableClone();
          newRawTypeInfo.setObjectForKey("1", "createParams");
          typeInfo.setObjectForKey(newRawTypeInfo, "RAW");
        }
      }
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "BLOB", "createParams");
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "LONGBLOB", "createParams");
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "MEDIUMBLOB", "createParams");
      JDBCPlugIn._takeValueForKeyPath(typeInfo, "0", "TINYBLOB", "createParams");
      mutableInfo.setObjectForKey(typeInfo, "typeInfo");

      NSLog.debug.appendln(
          new StringBuilder("fetched MySQL (")
              .append(databaseProductName())
              .append(") JDBC Info = ")
              .append(mutableInfo)
              .toString());

      // Write a fresh copy of JDBCInfo.plist to /tmp
      // writeJDBCInfo(mutableInfo);

      jdbcInfo = mutableInfo.immutableClone();
    }
    return jdbcInfo;
  }
  /**
   * Loads model files from all bundles in the classpath.<br>
   * Caveat: For compatibility with Apple's RuleEditor, this method automatically adds the
   * ".d2wmodel" extension to all names (with or without extension that you pass into this method.
   * That is we use "double extensions": the one specified as an argument plus the ".d2wmodel" one.
   * To the caller this is mostly transparent. Remember not to pass the extension or names including
   * the extension ".d2wmodel" as arguments. Remember to name your files including the ".d2wmodel"
   * extension.
   *
   * @param extension file name extension to look for
   * @param includeNames explicit list of file names (w/o extension) to accept, accepts all if null.
   * @param excludeNames explicit list of file names (w/o extension) to refuse, accepts all if null
   * @param includesFiles explicit list of file names (with extension) to accept in addition to
   *     otherwise accepted files
   */
  public static RuleModel loadFromBundles(
      String extension, NSSet includeNames, NSSet excludeNames, NSSet includesFiles) {
    NSMutableArray rules = new NSMutableArray();
    NSArray frameworkBundles = NSBundle.frameworkBundles();
    NSArray allBundles = frameworkBundles.arrayByAddingObject(NSBundle.mainBundle());
    Enumeration bundleEnumeration = allBundles.objectEnumerator();
    String fullExtension = extension + MODEL_EXT;
    int extLength = fullExtension.length();

    while (bundleEnumeration.hasMoreElements()) {
      NSBundle bundle = (NSBundle) bundleEnumeration.nextElement();
      NSArray ruleFilePaths = bundle.resourcePathsForLocalizedResources(fullExtension, null);
      Enumeration ruleFilePathEnumeration = ruleFilePaths.objectEnumerator();

      while (ruleFilePathEnumeration.hasMoreElements()) {
        String resourcePath = (String) ruleFilePathEnumeration.nextElement();

        if ((includeNames != null) || (excludeNames != null)) {
          int separatorIndex =
              resourcePath.lastIndexOf('.', resourcePath.length() - MODEL_EXT.length() - 1);

          if (separatorIndex < 0) {
            separatorIndex = 0;
          }

          int lastIndex = resourcePath.length() - extLength - 1;
          String resourceName = resourcePath.substring(separatorIndex + 1, lastIndex);

          if (includeNames != null) {
            if (!includeNames.containsObject(resourceName)) {
              continue;
            }
          }

          if (excludeNames != null) {
            if (excludeNames.containsObject(resourceName)) {
              continue;
            }
          }
        }

        // System.err.println("** bundle: " + bundle.name());
        // System.err.println("** resourcePath: " + resourcePath);

        InputStream inputStream = bundle.inputStreamForResourcePath(resourcePath);
        String string = StringUtilities.stringFromInputStream(inputStream);

        rules.addObjectsFromArray(RuleModelUtilities.decode(string));
      }

      if (includesFiles != null) {
        Enumeration includeFileEnumeration = includesFiles.objectEnumerator();

        while (includeFileEnumeration.hasMoreElements()) {
          String includeFile = (String) includeFileEnumeration.nextElement();

          if (includeFile.indexOf('.') > -1) {
            String includeFilePath =
                bundle.resourcePathForLocalizedResourceNamed(includeFile + MODEL_EXT, null);

            if (includeFilePath != null) {
              InputStream inputStream = bundle.inputStreamForResourcePath(includeFilePath);
              String string = StringUtilities.stringFromInputStream(inputStream);

              rules.addObjectsFromArray(RuleModelUtilities.decode(string));
            }
          }
        }
      }
    }

    return new RuleModel(rules);
  }