Esempio n. 1
0
  public void SendMail(String correo, String ruta)
      throws FileNotFoundException, UnsupportedEncodingException {

    SendgridEmailServiceProxy envio = new SendgridEmailServiceProxy();
    envio.setEndpoint(PropertiesUtil.getInstance().recuperaValor("EnvioMail"));
    String emailFrom = PropertiesUtil.getInstance().recuperaValor("FROM");
    String[] emailTo = new String[1];
    emailTo[0] = correo;
    String[] cc = new String[1];
    String subject = PropertiesUtil.getInstance().recuperaValor("subject");
    String message = PropertiesUtil.getInstance().recuperaValor("body");
    boolean isHtml = true;

    VariablesDTO[] variables = new VariablesDTO[1];
    VariablesDTO v = new VariablesDTO();
    v.setName("jjj");
    v.setValue("dddd");
    variables[0] = v;
    AttachmentDTO[] attachments = new AttachmentDTO[1];
    AttachmentDTO att = new AttachmentDTO();
    att.setFileName(getName(ruta));
    att.setBase64File(getArchivo(ruta));
    attachments[0] = att;

    try {
      envio.sendSendGridEmail(
          emailFrom, emailTo, cc, subject, message, variables, attachments, isHtml);
    } catch (RemoteException e) {
      logg.error(e);
    }
  }
Esempio n. 2
0
 public static void instanceSystemInfo() {
   if (systemInfo == null) {
     systemInfo = new SystemInfo();
     systemInfo.setEnv(PropertiesUtil.getProperties().getProperty("system.env"));
     systemInfo.setLoginEnv(PropertiesUtil.getProperties().getProperty("system.loginEnv"));
   }
 }
Esempio n. 3
0
 /*
  * 根据配置文件中key获得模块
  */
 public static InputStream getTemplateByKey(String key) {
   try {
     if (key != null && !"".equals(key)) {
       String templatePath = PropertiesUtil.getInstance().getProperty("excelExportTemplatePath");
       String k_v = PropertiesUtil.getInstance().getProperty(key);
       if (k_v != null && !"".equals(k_v)) {
         String realPath = templatePath + "/" + new String(k_v.getBytes(), "UTF-8");
         File file = new File(realPath);
         if (!file.exists()) {
           log.info(realPath + ":对应文件不存在!");
           FileException fe = new FileException(FileExceptionType.FILE_EXCEPTION_ALLOWEDTYPES);
           throw new GeneralException(fe.getErrorCode(), fe.getMessage(), fe, new Object[] {}) {};
         }
         return new FileInputStream(file);
       } else {
         log.info("配置文件中没有对应模块的键值对!");
         FileException fe =
             new FileException(FileExceptionType.FILE_EXCEPTION_PROPKEYVALNOTEXISTS);
         throw new GeneralException(fe.getErrorCode(), fe.getMessage(), fe, new Object[] {}) {};
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Esempio n. 4
0
  public void testStripStartExists() throws Exception {

    Properties p1 = PropertiesUtil.getPropertiesStartingWith("testprop", props);
    Properties p2 = PropertiesUtil.stripStart("testprop", p1);

    assertEquals(2, p2.size());
    assertEquals("myname", p2.get("name"));
    assertEquals("myaddress", p2.get("address"));
  }
Esempio n. 5
0
  // 返回Connection对象
  public static Connection getConn() throws Exception {
    Connection conn = null;
    PropertiesUtil pu = new PropertiesUtil();
    String driver = pu.getValue("driver");
    String url = pu.getValue("url");

    String userName = pu.getValue("userName");
    String password = pu.getValue("password");
    Class.forName(driver);
    conn = DriverManager.getConnection(url, userName, password);

    return conn;
  }
Esempio n. 6
0
public class SpringUtil {

  private static Configuration conf = PropertiesUtil.getConfiguration();

  private BeanFactoryReference bf = null;

  private static SpringUtil instance = null;

  public static Object getBean(String name) throws RuntimeException {

    if (instance == null) {
      instance = new SpringUtil();
    }

    try {
      Object o = instance.getApplicationContext().getBean(name);
      return o;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  private ApplicationContext getApplicationContext() {
    if (bf == null) {
      BeanFactoryLocator bfl = SingletonBeanFactoryLocator.getInstance();
      bf = bfl.useBeanFactory("smcore");
    }
    return (ApplicationContext) bf.getFactory();
  }
}
Esempio n. 7
0
 public void testStripStartNullProperties() throws Exception {
   try {
     PropertiesUtil.stripStart("blahblah", null);
     fail("Expected: NullPointerException");
   } catch (NullPointerException e) {
   }
 }
Esempio n. 8
0
 public void testStartingWithNullProperties() throws Exception {
   try {
     PropertiesUtil.getPropertiesStartingWith("blahblah", null);
     fail("Expected: NullPointerException");
   } catch (NullPointerException e) {
   }
 }
 @Test
 public void testReadPropertyNotExist() throws Exception {
   String resultExcepted = null;
   String resultActual = PropertiesUtil.readProperty("db", "wew");
   BaseLogger.info("resultExcepted = " + resultExcepted);
   BaseLogger.info("resultActual = " + resultActual);
   Assert.assertEquals(resultExcepted, resultActual);
 }
 @Test
 public void testReadPropertyExist() throws Exception {
   String resultExcepted = "jdbc:oracle:thin";
   String resultActual = PropertiesUtil.readProperty("db", "database.jdbc.connectionURL");
   BaseLogger.info("resultExcepted = " + resultExcepted);
   BaseLogger.info("resultActual = " + resultActual);
   Assert.assertEquals(true, resultActual.startsWith(resultExcepted));
 }
 public void testSuggestedCustomResourceBundleName() {
   final PsiFile file = myFixture.addFileToProject("Base_Page.properties", "");
   final PsiFile file2 = myFixture.addFileToProject("Base_Page_en.properties", "");
   final String baseName =
       PropertiesUtil.getDefaultBaseName(
           map(list(file, file2), psiFile -> PropertiesImplUtil.getPropertiesFile(file)));
   assertEquals("Base_Page", baseName);
 }
Esempio n. 12
0
  public void testStartingWithExists() throws Exception {

    Properties p = PropertiesUtil.getPropertiesStartingWith("testprop", props);

    assertEquals(2, p.size());
    assertEquals("myname", p.get("testprop.name"));
    assertEquals("myaddress", p.get("testprop.address"));
  }
Esempio n. 13
0
 public void testLoadInvalid() throws Exception {
   try {
     Properties p = PropertiesUtil.loadProperties("invalidTest.properties");
     fail("Expected: IllegalArgumentException");
   } catch (IllegalArgumentException e) {
     assertEquals(
         "Cannot override non-overrideable property flibble = flobble with new value flooble",
         e.getMessage());
   }
 }
 @Test
 public void loadByFileInputStream() {
   //        System.out.println("user.dir = " + System.getProperty("user.dir"));
   //        Properties props =
   // PropertiesUtil.loadByFileInputStream("D:\\Lab\\ws-wukong\\wukong-util\\src\\test\\resources\\test.properties");
   //        Properties props =
   // PropertiesUtil.loadByFileInputStream("./src/test/resources/test.properties");
   Properties props = PropertiesUtil.loadByFileInputStream("src/test/resources/test.properties");
   Assert.assertEquals("wukong-util", props.getProperty("project.artifactId"));
 }
Esempio n. 15
0
  public static void main(String[] args) throws InterruptedException {
    String[] locations = {"/applicationContext-load.xml"};
    // 一次性任务
    // 时间配置:每5s执行一次<value>0/5 * * * * ?</value>
    //        ApplicationContext context = new ClassPathXmlApplicationContext(locations);

    // spring 加载配置文件.
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(locations);
    context.start();
    System.out.println("默认路劲中不存在--" + PropertiesUtil.getString("hf.test.spring"));
  }
Esempio n. 16
0
 /*
  * (non-Javadoc)
  *
  * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
  */
 public void init(FilterConfig config) throws ServletException {
   this.config = config;
   HTML_PATH = PropertiesUtil.getHtmlPath();
   contextPath = config.getServletContext().getContextPath();
   supportPageList = new ArrayList<String>();
   supportPageList.add("/sort");
   supportPageList.add("/views");
   supportPageList.add("/views");
   supportPageList.add("/group");
   supportPageList.add("/group/view");
 }
 public CompleteFusionExportConverterImpl(String propertiesFileLocations) throws Exception {
   this.propertiesFileLocations = propertiesFileLocations;
   propertiesUtil = new PropertiesUtil();
   owlOntologyManager = OWLManager.createOWLOntologyManager();
   onto =
       owlOntologyManager.loadOntologyFromOntologyDocument(
           new File(
               propertiesUtil.getPropertyValue(
                   propertiesFileLocations, COSMICFUSIONEXPORT_OWL_FILE_LOCATION)));
   factory = new CosmicFusionExportFactory(onto);
 }
  /**
   * Update inventory for a product variation.
   *
   * @param productVariation ProductVariation
   * @param apiKey apiKey
   * @return JSONObject
   */
  public JSONObject updateInventoryJSONObject(ProductVariation productVariation, String apiKey) {
    String url = PropertiesUtil.getUpdateInventory();
    // 发起POST请求
    JSONObject jsonObject =
        CommonUtil.httpsRequest(
            url, "POST", productVariation.updateInventoryObject() + "key=" + apiKey);

    if (null != jsonObject) {
      return jsonObject;
    } else {
      return null;
    }
  }
  /**
   * Disable a product and all of its product variations. This marks the product available for sale.
   *
   * @param product Product
   * @param apiKey apiKey
   * @return JSONObject
   */
  public JSONObject disableProductVariationJSONObject(
      ProductVariation productVariation, String apiKey) {
    String url = PropertiesUtil.getDisableProductVariation();
    // 发起POST请求
    JSONObject jsonObject =
        CommonUtil.httpsRequest(
            url, "POST", productVariation.disableProductVariationObject() + "key=" + apiKey);

    if (null != jsonObject) {
      return jsonObject;
    } else {
      return null;
    }
  }
Esempio n. 20
0
  /**
   * Replaces ${property[:default value]} references in all attributes and text nodes of supplied
   * node. If the property is not defined neither in the given Properties instance nor in
   * System.getProperty and no default value is provided, a runtime exception is thrown.
   *
   * @param node DOM node to walk for substitutions
   * @param properties the Properties instance from which a value can be looked up
   */
  public static void substituteProperties(Node node, Properties properties) {
    // loop through child nodes
    Node child;
    Node next = node.getFirstChild();
    while ((child = next) != null) {

      // set next before we change anything
      next = child.getNextSibling();

      // handle child by node type
      if (child.getNodeType() == Node.TEXT_NODE) {
        child.setNodeValue(PropertiesUtil.substituteProperty(child.getNodeValue(), properties));
      } else if (child.getNodeType() == Node.ELEMENT_NODE) {
        // handle child elements with recursive call
        NamedNodeMap attributes = child.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
          Node attribute = attributes.item(i);
          attribute.setNodeValue(
              PropertiesUtil.substituteProperty(attribute.getNodeValue(), properties));
        }
        substituteProperties(child, properties);
      }
    }
  }
  @RequestMapping(value = "returnBankCardJSPforApproval")
  public ModelAndView returnBankCardJSPforApproval(
      Long modifyCatdAppId, Long creditapplicationId, String type) {
    System.out.println(creditapplicationId);

    ModifyCatdApp modifyCatdApp =
        modifyCatdAppService.queryModifyCatdAppByPrimarKey(modifyCatdAppId);
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("/jsp/rc/basicInfo/bankCardVeiwNew.jsp");
    modelAndView.addObject("creditapplicationId", creditapplicationId);
    modelAndView.addObject("modifyCatdAppId", modifyCatdAppId);

    Map map = new HashMap();
    DESPlus desPlus;
    try {
      desPlus = new DESPlus();
      map.put("clientid", desPlus.encrypt(creditapplicationId + "AccountCard"));
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    String clientid = (String) map.get("clientid");

    System.out.println(clientid);

    long nowTime = System.currentTimeMillis();
    String sMillis[] = new String[2];
    try {
      Properties properties = PropertiesUtil.loadProperties("spring/cm/cm.properties");
      DESPlus desPlus2 = new DESPlus();
      sMillis[0] = desPlus2.encrypt(nowTime + "");
      String cmIp = properties.getProperty("cm.hostip");
      String DESIp = desPlus2.encrypt(cmIp);
      sMillis[1] = DESIp;
    } catch (Exception e) {
      e.printStackTrace();
    }

    String signTime = sMillis[0];
    String signIp = sMillis[1];

    modelAndView.addObject("clientid", clientid);
    modelAndView.addObject("signTime", signTime);
    modelAndView.addObject("signIp", signIp);
    modelAndView.addObject("modifyCatdApp", modifyCatdApp);

    return modelAndView;
  }
  @Nullable
  private static List<Locale> extractLocalesFromString(final String rawLocales) {
    if (rawLocales.isEmpty()) {
      return Collections.emptyList();
    }
    final String[] splitRawLocales = rawLocales.split(",");
    final List<Locale> locales = new ArrayList<>(splitRawLocales.length);

    for (String rawLocale : splitRawLocales) {
      final Locale locale = PropertiesUtil.getLocale("_" + rawLocale + ".properties");
      if (locale == PropertiesUtil.DEFAULT_LOCALE) {
        return null;
      } else if (!locales.contains(locale)) {
        locales.add(locale);
      }
    }
    return locales;
  }
Esempio n. 23
0
 /*
  * 创建文件名
  */
 @SuppressWarnings("serial")
 public static String createFileName(String fileName) {
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_");
   String name = formatter.format(new Date()) + UUID.randomUUID().toString();
   if (fileName.lastIndexOf(".") != -1) {
     // 得到后缀名
     String extension = fileName.substring(fileName.lastIndexOf("."));
     String allowedTypes = PropertiesUtil.getInstance().getProperty("allowedTypes").trim();
     if (allowedTypes == null
         || "".equals(allowedTypes)
         || allowedTypes.indexOf(extension.substring(1, extension.length()).toLowerCase()) < 0) {
       FileException fe = new FileException(FileExceptionType.FILE_EXCEPTION_ALLOWEDTYPES);
       throw new GeneralException(fe.getErrorCode(), fe.getMessage(), fe, new Object[] {}) {};
     }
     name = name + extension;
   }
   return name;
 }
Esempio n. 24
0
 private static List<Date> getSpecialWorkDay() {
   List<Date> specialWork = new ArrayList<Date>();
   String specialWorkDays = PropertiesUtil.getCommonConfigProperty("specialWorkingDays");
   String[] specialWorkDaysArr = specialWorkDays.split(",");
   if (specialWorkDaysArr.length > 0) {
     for (String day : specialWorkDaysArr) {
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
       Date date = null;
       try {
         date = sdf.parse(day);
       } catch (ParseException e) {
         e.printStackTrace();
       }
       specialWork.add(date);
     }
   }
   return specialWork;
 }
  /**
   * Use the endpoint to create a new product. Each product creation must include at least one
   * variation because each product must have at least 1 variation.
   *
   * @param product Product Object
   * @param apiKey apiKey
   * @return Boolean
   */
  public Boolean createProductVariationBoolean(ProductVariation productVariation, String apiKey) {
    String url = PropertiesUtil.getCreateProductVariation();
    // 发起POST请求
    JSONObject jsonObject =
        CommonUtil.httpsRequest(
            url, "POST", productVariation.createProductVariationObject() + "key=" + apiKey);

    if (null != jsonObject) {
      int code = jsonObject.getInt("code");
      if (0 == code) {
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
  /**
   * Retrieve the details about a product which exists on the Wish platform. You must have the
   * unique product Id that was returned upon product creation.
   *
   * @param productId id
   * @param apiKey apiKey
   * @return Boolean
   */
  public Boolean retrieveProductVariationBoolean(String productId, String apiKey) {
    String url =
        PropertiesUtil.getRetrieveProductVariation()
            .replace("product_id", productId)
            .replace("an_example_api_key", apiKey);
    // 发起POST请求
    JSONObject jsonObject = CommonUtil.httpsRequest(url, "GET", null);

    if (null != jsonObject) {
      int code = jsonObject.getInt("code");
      if (0 == code) {
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
  /**
   * Retrieve the details about a product which exists on the Wish platform. You must have the
   * unique product Id that was returned upon product creation.
   *
   * @param productId id
   * @param apiKey apiKey
   * @return JSONObject
   */
  public JSONObject retrieveProductVariationJSONObject(String productId, String apiKey) {
    String url =
        PropertiesUtil.getRetrieveProductVariation()
            .replace("product_id", productId)
            .replace("an_example_api_key", apiKey);
    // 发起POST请求
    JSONObject jsonObject = CommonUtil.httpsRequest(url, "GET", null);

    if (null != jsonObject) {
      int code = jsonObject.getInt("code");
      if (0 == code) {
        return jsonObject;
      } else {
        JSONObject errorJsonObject = new JSONObject();
        return errorJsonObject.element("message", jsonObject.getString("message"));
      }
    } else {
      return null;
    }
  }
  /**
   * Returns a list of all your products currently on the Wish platform. If you have a high number
   * of products the response will be paginated. The response will contain the URL for fetching the
   * next page of products.
   *
   * @param start optional An offset into the list of returned items. Use 0 to start at the
   *     beginning. The API will return the requested number of items starting at this offset.
   *     Default to 0 if not supplied
   * @param limit A limit on the number of products that can be returned. Limit can range from 1 to
   *     500 items and the default is 50
   * @param apiKey apiKey
   * @return JSONObject
   */
  public JSONObject ListAllProductsVariationJSONObject(String start, String limit, String apiKey) {
    String url = PropertiesUtil.getListallProductVariations();

    StringBuffer buffer = new StringBuffer();
    if (!start.equals("")) {
      buffer.append("start=" + start + "&");
    }
    if (!limit.equals("")) {
      buffer.append("limit=" + limit + "&");
    }
    // 发起POST请求
    JSONObject jsonObject =
        CommonUtil.httpsRequest(url, "POST", buffer.toString() + "key=" + apiKey);

    if (null != jsonObject) {
      return jsonObject;
    } else {
      return null;
    }
  }
Esempio n. 29
0
  @Override
  public void contextInitialized(ServletContextEvent servletContextEvent) {

    Map<String, String> map = PropertiesUtil.getAllProperty();
    String up = map.get("UP");
    UP = (up != null && up != "") ? up : UP;

    String down = map.get("DOWN");
    DOWN = (down != null && down != "") ? down : DOWN;

    String news_domain = map.get("NEWS_IMG_DOMAIN");
    NEWS_IMG_DOMAIN = (news_domain != null && news_domain != "") ? news_domain : NEWS_IMG_DOMAIN;

    String news_url = map.get("NEWS_URL");
    NEWS_URL = (news_url != null && news_url != "") ? news_url : NEWS_URL;

    Integer headnews_content_len = Integer.valueOf(map.get("HEADNEWS_CONTENT_LEN"));
    HEADNEWS_CONTENT_LEN =
        (headnews_content_len != null && headnews_content_len.intValue() >= 0)
            ? headnews_content_len
            : HEADNEWS_CONTENT_LEN;

    Integer week = Integer.valueOf(map.get("WEEK"));
    WEEK = (week != null && week.intValue() >= 0) ? week : WEEK;

    Integer week_items = Integer.valueOf(map.get("WEEK_ITEMS"));
    WEEK_ITEMS = (week_items != null && week_items.intValue() >= 0) ? week_items : WEEK_ITEMS;

    Integer marquee_listsize = Integer.valueOf(map.get("MARQUEE_LISTSIZE")).intValue();
    MARQUEE_LISTSIZE =
        (marquee_listsize != null && marquee_listsize.intValue() >= 0)
            ? marquee_listsize
            : MARQUEE_LISTSIZE;

    Integer page_size = Integer.valueOf(map.get("PAGE_SIZE"));
    PAGE_SIZE = (page_size != null && page_size.intValue() >= 0) ? page_size : PAGE_SIZE;

    Integer pagebar_size = Integer.valueOf(map.get("PAGEBAR_SIZE"));
    PAGEBAR_SIZE =
        (pagebar_size != null && pagebar_size.intValue() >= 0) ? pagebar_size : PAGEBAR_SIZE;
  }
 public static ArrayList<Server> getServer(String serverListConfPath, String key) {
   Properties p = PropertiesUtil.read(serverListConfPath);
   String externalServer = p.getProperty(key);
   ArrayList<Server> serverList = new ArrayList<>();
   // clear externalServer data to server
   String servers[] = externalServer.split("\\},\\{");
   for (String serString : servers) {
     serString = serString.replace("[{", "").replace("}]", "");
     Server server = new Server();
     String serfeature[] = serString.split(",");
     for (String feature : serfeature) {
       if (feature.contains("host:")) server.setIp(feature.replace("host:", ""));
       else if (feature.contains("device:")) server.setDeviceName(feature.replace("device:", ""));
       else if (feature.contains("password:"******"password:"******""));
       else if (feature.contains("user:"******"user:"******""));
       else if (feature.contains("owner:")) server.setOwner(feature.replace("owner:", ""));
       else System.out.println(feature);
     }
     serverList.add(server);
   }
   return serverList;
 }