/**
   * Import the model according to reversed dependency order among model objects: book, sheet,
   * defined name, cells, chart, pictures, validation.
   */
  @Override
  public SBook imports(InputStream is, String bookName) throws IOException {

    // clear cache for reuse
    importedStyle.clear();
    importedFont.clear();

    workbook = createPoiBook(is);
    book = SBooks.createBook(bookName);
    //		book.setDefaultCellStyle(importCellStyle(workbook.getCellStyleAt((short) 0), false));
    // //ZSS-780
    // ZSS-854
    importDefaultCellStyles();
    importNamedStyles();
    // ZSS-1140
    importExtraStyles();
    setBookType(book);

    // ZSS-715: Enforce internal Locale.US Locale so formula is in consistent internal format
    Locale old = Locales.setThreadLocal(Locale.US);
    SBookSeries bookSeries = book.getBookSeries();
    boolean isCacheClean = bookSeries.isAutoFormulaCacheClean();
    try {
      bookSeries.setAutoFormulaCacheClean(false); // disable it to avoid
      // unnecessary clean up
      // during importing

      importExternalBookLinks();
      int numberOfSheet = workbook.getNumberOfSheets();
      for (int i = 0; i < numberOfSheet; i++) {
        Sheet poiSheet = workbook.getSheetAt(i);
        importSheet(poiSheet, i);
        SSheet sheet = book.getSheet(i);
        importTables(poiSheet, sheet); // ZSS-855, ZSS-1011
      }
      importNamedRange();
      for (int i = 0; i < numberOfSheet; i++) {
        SSheet sheet = book.getSheet(i);
        Sheet poiSheet = workbook.getSheetAt(i);
        for (Row poiRow : poiSheet) {
          importRow(poiRow, sheet);
        }
        importColumn(poiSheet, sheet);
        importMergedRegions(poiSheet, sheet);
        importDrawings(poiSheet, sheet);
        importValidation(poiSheet, sheet);
        importAutoFilter(poiSheet, sheet);
        importSheetProtection(poiSheet, sheet); // ZSS-576
      }
    } finally {
      book.getBookSeries().setAutoFormulaCacheClean(isCacheClean);
      Locales.setThreadLocal(old);
    }

    return book;
  }
Esempio n. 2
0
 public void checkR() {
   if (English.isChecked()) {
     lenguaje = "en";
     Locale preferredLocale = org.zkoss.util.Locales.getLocale(lenguaje);
     session.setAttribute(org.zkoss.web.Attributes.PREFERRED_LOCALE, preferredLocale);
   } else if (Spanish.isChecked()) {
     lenguaje = "es";
     Locale preferredLocale = org.zkoss.util.Locales.getLocale(lenguaje);
     session.setAttribute(org.zkoss.web.Attributes.PREFERRED_LOCALE, preferredLocale);
   }
 }
Esempio n. 3
0
 /**
  * Returns the date format of the specified format
  *
  * <p>Default: it uses SimpleDateFormat to format the date.
  *
  * @param fmt the pattern.
  */
 protected DateFormat getDateFormat(String fmt) {
   final DateFormat df =
       new SimpleDateFormat(fmt, _locale != null ? _locale : Locales.getCurrent());
   final TimeZone tz = _tzone != null ? _tzone : TimeZones.getCurrent();
   df.setTimeZone(tz);
   return df;
 }
Esempio n. 4
0
  /**
   * Returns the preferred locale of the specified request. You rarely need to invoke this method
   * directly, because it is done automatically by {@link #setup}.
   *
   * <ol>
   *   <li>It checks whether any attribute stored in HttpSession called {@link
   *       Attributes#PREFERRED_LOCALE}. If so, return it.
   *   <li>If not found, it checks if the servlet context has the attribute called {@link
   *       Attributes#PREFERRED_LOCALE}. If so, return it.
   *   <li>If not found, it checks if the library property called {@link
   *       Attributes#PREFERRED_LOCALE} is defined. If so, return it.
   *   <li>Otherwise, use ServletRequest.getLocale().
   * </ol>
   *
   * @param sess the session to look for the preferred locale. Ignored if null.
   */
  public static final Locale getPreferredLocale(HttpSession sess, ServletRequest request) {
    if (sess != null) {
      Object v = sess.getAttribute(Attributes.PREFERRED_LOCALE);
      if (v == null)
        v = sess.getAttribute(PX_PREFERRED_LOCALE); // backward compatible (prior to 5.0.3)
      if (v != null) {
        if (v instanceof Locale) return (Locale) v;
        logLocaleError(v);
      }

      v = sess.getServletContext().getAttribute(Attributes.PREFERRED_LOCALE);
      if (v == null)
        v =
            sess.getServletContext()
                .getAttribute(PX_PREFERRED_LOCALE); // backward compatible (prior to 5.0.3)
      if (v != null) {
        if (v instanceof Locale) return (Locale) v;
        logLocaleError(v);
      }

      final String s = Library.getProperty(Attributes.PREFERRED_LOCALE);
      if (s != null) return Locales.getLocale(s);
    }

    Locale l = request.getLocale();
    // B65-ZK-1916: convert zh_HANS-XX and zh_HANT-XX to zh_XX
    return l != null ? fixZhLocale(l) : Locale.getDefault();
  }
Esempio n. 5
0
 private static final DateFormat getDateFormat(
     String pattern, Locale locale, TimeZone timezone, String dateStyle, String timeStyle) {
   if (locale == null) locale = Locales.getCurrent();
   if (timezone == null) timezone = TimeZones.getCurrent();
   pattern = getRealFormat(pattern, locale, dateStyle, timeStyle);
   final DateFormat df = new SimpleDateFormat(pattern, locale);
   df.setTimeZone(timezone);
   return df;
 }
Esempio n. 6
0
  /** Sets up the charset for the request and response based on
   * {@link #getPreferredLocale(HttpSession,ServletRequest)}. After setting up, you shall invoke
   * {@link #cleanup} before exiting.
   *
   * <pre><code> final Object old = setup(request, response, null);
   * try {
   *	  ....
   * } finally {
   *    cleanup(request, old);
   * }
   *
   * <p>It is OK to call this method multiple time, since it is smart
   * enough to ignore redundant calls.
   *
   * <p>{@link CharsetFilter} actually use this method to setup
   * the proper charset and locale. By mapping {@link CharsetFilter} to
   * all servlets, the encoding charset could be prepared correctly.
   * However, if you are writing libraries to be as independent of
   * web.xml as possible, you might choose to invoke this method directly.
   *
   * @param sess the session to look for the preferred locale. Ignored if null.
   * @param charset the response's charset. If null or empty,
   * response.setCharacterEncoding won't be called, i.e., the container's
   * default is used.
   * @return an object that must be passed to {@link #cleanup}
   */
  public static final Object setup(
      HttpSession sess, ServletRequest request, ServletResponse response, String charset) {
    if (hasSetup(request)) // processed before?
    return Objects.UNKNOWN;

    final Locale locale = getPreferredLocale(sess, request);
    response.setLocale(locale);
    if (charset != null && charset.length() > 0) {
      try {
        if (Servlets.isServlet24()) {
          response.setCharacterEncoding(charset);
        } else {
          // don't access 2.4 API: setCharacterEncoding, getContentType
          response.setContentType(";charset=" + charset);
        }
      } catch (Throwable ex) {
        try {
          final String v = response.getCharacterEncoding();
          if (!Objects.equals(v, charset))
            log.warn("Unable to set response's charset: " + charset + " (current=" + v + ')', ex);
        } catch (Throwable t) { // just in case
        }
      }
    }

    if (request.getCharacterEncoding() == null) {
      charset = response.getCharacterEncoding();
      try {
        request.setCharacterEncoding(charset);
      } catch (Throwable ex) {
        final String v = request.getCharacterEncoding();
        if (!Objects.equals(v, charset))
          log.warn(
              "Unable to set request's charset: "
                  + charset
                  + " (current="
                  + v
                  + "): "
                  + Exceptions.getMessage(ex));
      }
    }

    markSetup(request, true);
    return Locales.setThreadLocal(locale);
  }
Esempio n. 7
0
 private static final DecimalFormat getDecimalFormat(String pattern, Locale locale) {
   final DecimalFormat df =
       (DecimalFormat) NumberFormat.getInstance(locale != null ? locale : Locales.getCurrent());
   if (pattern != null) df.applyPattern(pattern);
   return df;
 }
Esempio n. 8
0
 /**
  * Sets the locale used to identify the format of this datebox.
  *
  * <p>Default: null (i.e., {@link Locales#getCurrent}, the current locale is assumed)
  *
  * @since 5.0.7
  */
 public void setLocale(String locale) {
   setLocale(locale != null && locale.length() > 0 ? Locales.getLocale(locale) : null);
 }
Esempio n. 9
0
 /**
  * Returns the localized format, which is used when constructing a datebox.
  *
  * <p>You might override this method to provide your own localized format.
  */
 protected String getLocalizedFormat() {
   return new SimpleDateFormat(getRealFormat(), _locale != null ? _locale : Locales.getCurrent())
       .toLocalizedPattern();
 }
Esempio n. 10
0
 private static final Locale getLocale() {
   return Locales.getCurrent();
 }
Esempio n. 11
0
 @Before
 public void beforeTest() {
   Locales.setThreadLocal(Locale.TAIWAN);
 }
Esempio n. 12
0
 /**
  * Returns a map of segmented labels for the current locale (never null). Unlike {@link
  * #getLabel}, if a key of the label contains dot, it will be splitted into multiple keys and then
  * grouped into map. It is so-called segmented.
  *
  * <p>For example, the following property file will parsed into a couple of maps, and <code>
  * getSegmentedLabels()</code> returns a map containing a single entry. The entry's key is <code>
  * "a"</code> and the value is another map with two entries <code>"b"</code> and <code>"c"</code>.
  * And, the value for <code>"b"</code> is another two-entries map (containing <code>"c"</code> and
  * <code>"d"</code>).
  *
  * <pre><code>
  * a.b.c=1
  * a.b.d=2
  * a.e=3</pre></code>
  *
  * <p>This method is designed to make labels easier to be accessed in EL expressions.
  *
  * <p>On the other hand, {@link #getLabel} does not split them, and you could access them by, say,
  * <code>getLabel("a.b.d")</code>.
  *
  * @since 5.0.7
  */
 public Map getSegmentedLabels() {
   return getSegmentedLabels(Locales.getCurrent());
 }
Esempio n. 13
0
 /**
  * Returns the label of the specified key for the current locale, or null if not found.
  *
  * @see #getSegmentedLabels
  */
 public String getLabel(String key) {
   return getLabel(Locales.getCurrent(), key);
 }
Esempio n. 14
0
 /**
  * Converts all of the characters in this String to upper case using the rules of the current
  * Locale.
  *
  * @see Locales#getCurrent
  * @since 5.0.7
  */
 public static String toUpperCase(String s) {
   return s != null ? s.toUpperCase(Locales.getCurrent()) : null;
 }
Esempio n. 15
0
 /**
  * Cleans up what has been set in {@link #setup}. Some invocation are not undo-able, so this
  * method only does the basic cleanups.
  *
  * @param old the value must be the one returned by the last call to {@link #setup}.
  */
 public static final void cleanup(ServletRequest request, Object old) {
   if (old != Objects.UNKNOWN) {
     Locales.setThreadLocal((Locale) old);
     markSetup(request, false);
   }
 }