Ejemplo n.º 1
0
 /** Update all displayed text */
 public void updateText() {
   tableColumns =
       new String[] {
         " ",
         Lang.getString("TedTableModel.Name"), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         Lang.getString("TedTableModel.Searching"),
         Lang.getString("TedTableModel.Progress"),
         Lang.getString("TedTableModel.Status")
       }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
 }
Ejemplo n.º 2
0
  @Override
  public void meet(Lang lang) throws RuntimeException {
    if (lang.getArg() instanceof Var) {
      String var = getVariableAlias((Var) lang.getArg());
      Preconditions.checkState(var != null, "no alias available for variable");

      builder.append(var);
      builder.append(".lang");
    }
  }
Ejemplo n.º 3
0
  public static void main(String args[]) {
    String s = "Richard's office is in NSH-4622";
    Set<Lang> langSet = detect(s);

    System.out.println(s);
    if (!langSet.isEmpty()) for (Lang lang : langSet) System.out.println(lang.getName());

    s = "波ㄆㄛ羅ㄌㄨㄛˊ蜜ㄇㄧˋ";
    System.out.println(LangProvider.getLang("zh-TW").pattern.matcher(s).matches());
  }
Ejemplo n.º 4
0
  @Override
  protected void doGet(HttpAction action) {
    // Assume success - do the set up before grabbing the lock.
    // Sets content type.
    MediaType mediaType = ActionLib.contentNegotationRDF(action);

    ServletOutputStream output;
    try {
      output = action.response.getOutputStream();
    } catch (IOException ex) {
      ServletOps.errorOccurred(ex);
      output = null;
    }

    TypedOutputStream out = new TypedOutputStream(output, mediaType);
    Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentType());

    if (action.verbose)
      action.log.info(
          format(
              "[%d]   Get: Content-Type=%s, Charset=%s => %s",
              action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName()));

    action.beginRead();
    setCommonHeaders(action.response);
    try {
      Target target = determineTarget(action);
      if (action.log.isDebugEnabled()) action.log.debug("GET->" + target);
      boolean exists = target.exists();
      if (!exists) ServletOps.errorNotFound("No such graph: <" + target.name + ">");
      // If we want to set the Content-Length, we need to buffer.
      // response.setContentLength(??) ;
      String ct = lang.getContentType().toHeaderString();
      action.response.setContentType(ct);
      Graph g = target.graph();
      // Special case RDF/XML to be the plain (faster, less readable) form
      RDFFormat fmt =
          (lang == Lang.RDFXML)
              ? RDFFormat.RDFXML_PLAIN
              : RDFWriterRegistry.defaultSerialization(lang);
      try {
        RDFDataMgr.write(out, g, fmt);
      } catch (JenaException ex) {
        // Some RDF/XML data is unwritable. All we can do is pretend it's a bad
        // request (inappropriate content type).
        // Good news - this happens before any output for RDF/XML-ABBREV.
        if (fmt.getLang().equals(Lang.RDFXML))
          ServletOps.errorBadRequest("Failed to write output in RDF/XML: " + ex.getMessage());
        else ServletOps.errorOccurred("Failed to write output: " + ex.getMessage(), ex);
      }
      ServletOps.success(action);
    } finally {
      action.endRead();
    }
  }
 public String getDescription(String lang) {
   for (Lang l : descriptions) {
     if (l.getLang().equals(lang)) {
       return l.getContent();
     }
   }
   if (descriptions.size() > 0) {
     return descriptions.get(0).getContent();
   }
   return "No description set";
 }
 public String getContents(String lang) {
   for (Lang l : contents) {
     if (l.getLang().equals(lang)) {
       return l.getContent();
     }
   }
   if (contents.size() > 0) {
     return contents.get(0).getContent();
   }
   return "No content set";
 }
 public String getLocation(String lang) {
   for (Lang l : locations) {
     if (l.getLang().equals(lang)) {
       return l.getContent();
     }
   }
   if (locations.size() > 0) {
     return locations.get(0).getContent();
   }
   return "No location set";
 }
 public String getTitle(String lang) {
   for (Lang l : titles) {
     if (l.getLang().equals(lang)) {
       return l.getContent();
     }
   }
   if (titles.size() > 0) {
     return titles.get(0).getContent();
   }
   return "No title set";
 }
Ejemplo n.º 9
0
  /**
   * Creates a Lang object using id1's ID and id2's pattern
   *
   * @param id1
   * @param id2
   * @return
   */
  public static Lang getLang(String id1, String id2) {
    Lang lang1 = getLang(id1);
    if (lang1 == null) return null;
    Lang lang2 = getLang(id2);
    if (lang2 == null) return null;

    Lang lang = new Lang();
    lang.setName(lang1.getName() + " + " + lang2.getName());
    lang.setId(lang1.getId()); // web page retrieval langId
    lang.setPattern(lang2.getPattern()); // text extraction langId
    return lang;
  }
 public String getTitleJSONString() {
   JSONArray array = new JSONArray();
   for (Lang l : titles) {
     JSONObject obj = new JSONObject();
     try {
       obj.put(l.getLang(), l.getContent());
     } catch (JSONException e) {
       e.printStackTrace();
     }
     array.put(obj);
   }
   return array.toString();
 }
Ejemplo n.º 11
0
  /**
   * Constructs a new LanguagePreference object. The passed string should be an http Accept-Language
   * header.
   */
  public LanguagePreferences(String langString) {
    Hashtable specific = new Hashtable();
    StringTokenizer t = new StringTokenizer(langString, ",");
    float ndx = 0.000099F;
    while (t.hasMoreTokens()) {
      String tok = t.nextToken().trim();
      String lang = null;
      float weight = 1.0F;
      int pos = tok.indexOf(';');
      if (pos == -1) lang = tok;
      else {
        lang = tok.substring(0, pos);
        pos = tok.indexOf('=');
        if (pos > -1) {
          String work = tok.substring(pos + 1);
          try {
            weight = Float.parseFloat(work);
          } catch (Exception e) {
          }
          ;
        }
      }
      if (lang == null) continue;
      Lang l = new Lang();
      l.lang = lang.toLowerCase();
      l.weight = weight + ndx;
      ndx -= 0.000001F;
      _list.add(l);
      pos = lang.indexOf("-");
      if (pos == -1) specific.put(lang, lang);
    }
    _list.sort();

    int size = _list.size();
    for (int i = 0; i < size; i++) {
      Lang l = (Lang) _list.elementAt(i);
      String lang = l.lang;
      int pos = lang.indexOf('-');
      if (pos > -1) {
        lang = lang.substring(0, pos);
        if (!specific.containsKey(lang)) {
          l = new Lang();
          l.lang = lang;
          _list.add(l);
          specific.put(lang, lang);
        }
      }
    }
  }
Ejemplo n.º 12
0
 private void setMusic_lang(Map<String, Object> inUpdateMap, Lang inValue) {
   final long theUpdateValue = inValue.getId().longValue();
   if (theUpdateValue != this.music_lang) {
     this.music_lang = theUpdateValue;
     inUpdateMap.put("music_lang", theUpdateValue);
   }
 }
Ejemplo n.º 13
0
 /**
  * @param file
  * @return
  */
 public static String canonical(File file) {
   try {
     return file.getCanonicalPath();
   } catch (Exception e) {
     throw Lang.uncheck(e);
   }
 }
Ejemplo n.º 14
0
 /**
  * @param file
  * @param encoding
  * @return
  */
 public static String read(File file, String encoding) {
   try {
     return new String(read(file), encoding);
   } catch (UnsupportedEncodingException e) {
     throw Lang.uncheck(e);
   }
 }
Ejemplo n.º 15
0
  /**
   * @param file
   * @param data
   * @param encoding
   */
  public static void appendTo(File file, String data, String encoding) {
    try {

      appendTo(file, data.getBytes(encoding));
    } catch (UnsupportedEncodingException e) {
      throw Lang.uncheck(e);
    }
  }
Ejemplo n.º 16
0
  /**
   * @param source
   * @param target
   */
  public static void copy(File source, File target) {
    try {

      new CopyFileCommand(source, target).execute();
    } catch (Exception e) {
      throw Lang.uncheck(e);
    }
  }
Ejemplo n.º 17
0
 /** Update text of the status menu */
 public void updateText() {
   menuEdit.setText(Lang.getString("TedMainMenuBar.Edit.Edit")); // $NON-NLS-1$
   menuDelete.setText(Lang.getString("TedMainMenuBar.Edit.Delete")); // $NON-NLS-1$
   menuParse.setText(Lang.getString("TedTablePopupMenu.CheckShow")); // $NON-NLS-1$
   buyDVD.setText(Lang.getString("TedTablePopupMenu.BuyDVD"));
   menuEnableShow.setText(Lang.getString("TedMainMenuBar.Edit.EnableShow"));
   menuDisableShow.setText(Lang.getString("TedMainMenuBar.Edit.DisableShow"));
   menuEnableAutoSchedule.setText(Lang.getString("TedMainMenuBar.Edit.EnableAutoSchedule"));
   menuDisableAutoSchedule.setText(Lang.getString("TedMainMenuBar.Edit.DisableAutoSchedule"));
 }
Ejemplo n.º 18
0
  /**
   * @param file
   * @param content
   * @param encoding
   */
  public static void write(File file, String content, String encoding) {

    try {

      write(file, content.getBytes(encoding));
    } catch (Exception e) {
      Lang.uncheck(e);
    }
  }
Ejemplo n.º 19
0
 private NewsContent getNewsContent() {
   for (NewsContent newsContent : newsContents) {
     if (newsContent.getLang().getSymbol().equals(lang)) {
       return newsContent;
     }
   }
   NewsContent newsContent = new NewsContent();
   newsContent.setLang(Lang.valueOf(lang));
   newsContent.setNews(this);
   newsContents.add(newsContent);
   return newsContent;
 }
Ejemplo n.º 20
0
 public static String underscoreToCamel(String str) {
   String ret =
       join(
           Lang.mapcar(
               Arrays.asList(str.split("_")),
               new Lambda<String, String>() {
                 public String lambda(String val) {
                   return val.substring(0, 1).toUpperCase() + val.substring(1);
                 }
               }),
           "");
   return ret.substring(0, 1).toLowerCase() + ret.substring(1);
 }
Ejemplo n.º 21
0
  /**
   * @param file
   * @param content
   */
  public static void write(File file, byte[] content) {

    try {

      new MakeFileCommand(file).execute();
      if (file.isDirectory()) {
        throw new IllegalStateException("file[" + file.getName() + "] is a directory!");
      }

      new WriteBytesToFileCommand(file, content).execute();
    } catch (Exception e) {
      throw Lang.uncheck(e);
    }
  }
Ejemplo n.º 22
0
  public MusicImpl(
      Files inFileId, User inOwner, Lang lang, String name, int styleid, int share, int inMusicType)
      throws SQLException {
    this.music_name = name;
    this.file_id = inFileId.getId();
    if (inOwner != null) {
      this.music_owner = inOwner.getId().intValue();

      if (lang == null) {
        final Annu theAnnu = inOwner.getAnnu();
        if (theAnnu != null) {
          final Lang theUserLang = theAnnu.getLangPreferences();
          if (theUserLang != null) {
            this.music_lang =
                ObjectLangData.getDefaultObjectLanguage(theUserLang.getIsoCode()).getId();
          }
        }
      }
    } else {
      this.music_owner = 0;
    }
    this.music_styleid = styleid;
    this.music_share = share;

    if (lang != null) {
      this.music_lang = lang.getId().longValue();
    }

    this.music_type = inMusicType;
    init(MusicImpl.NEW_COLUMNS);
    this.mFile =
        new SingleAssociationNotNull<Music, Files, FilesImpl>(
            this, StringShop.FILE_ID, FilesImpl.SPECIFICATION);
    this.mOwner =
        new SingleAssociationNotNull<Music, User, UserImpl>(
            this, "music_owner", UserImpl.SPECIFICATION);
  }
Ejemplo n.º 23
0
  /**
   * @param file
   * @return
   */
  public static byte[] read(File file) {

    if (!file.exists() || !file.canRead()) {
      throw new IllegalStateException("file is not exist or can not read!");
    }

    ByteArrayOutputStream out = null;
    try {

      out = new ByteArrayOutputStream();
      new WriteFileToCommand(file, out, true).execute();
      return out.toByteArray();
    } catch (Exception e) {
      throw Lang.uncheck(e);
    } finally {
      IOs.freeQuietly(out);
    }
  }
Ejemplo n.º 24
0
  /**
   * @param oldname
   * @param newname
   */
  public static void rename(String oldname, String newname) {
    try {

      File file = new File(oldname);
      if (!file.exists()) {
        throw new FileNotFoundException("the old file is not exist!");
      }

      File newFile = new File(newname);
      if (newFile.exists()) {
        throw new IllegalStateException("the new file is exist!");
      }

      file.renameTo(newFile);
    } catch (Exception e) {
      throw Lang.uncheck(e);
    }
  }
Ejemplo n.º 25
0
 public void forceSpecifyLanguageForCreate(String language) {
   if (newsContents.size() == 1 && id == null) {
     newsContents.get(0).setLang(Lang.valueOf(language));
   }
 }
Ejemplo n.º 26
0
 public String getSpawnName() {
   return Lang.getString("HEAD_SPAWN_" + name());
 }
Ejemplo n.º 27
0
 public String getDisplayName() {
   return Tools.format(Lang.getString("HEAD_" + name()));
 }
Ejemplo n.º 28
0
/**
 * Dialog window for changing some project's preferences.
 *
 * @author BaseX Team 2005-12, BSD License
 * @author Christian Gruen
 */
public final class DialogPrefs extends BaseXDialog {
  /** Information on available languages. */
  private static final int[] HITS = {
    10, 25, 100, 250, 1000, 2500, 10000, 25000, 100000, 250000, 1000000, -1
  };

  /** Information on available languages. */
  private static final String[][] LANGS = Lang.parse();

  /** Directory path. */
  final BaseXTextField path;
  /** Number of hits. */
  final BaseXSlider limit;
  /** Label for number of hits. */
  final BaseXLabel label;

  /** Language label. */
  private final BaseXLabel creds;
  /** Language combobox. */
  private final BaseXCombo lang;
  /** Focus checkbox. */
  private final BaseXCheckBox focus;
  /** Show names checkbox. */
  private final BaseXCheckBox names;
  /** Simple file dialog checkbox. */
  private final BaseXCheckBox simpfd;
  /** Simple file dialog checkbox. */
  private final BaseXCheckBox javalook;
  /** Old value for show names flag. */
  private final boolean oldShowNames;

  /**
   * Default constructor.
   *
   * @param main reference to the main window
   */
  public DialogPrefs(final GUI main) {
    super(main, PREFERENCES);

    // create checkboxes
    final BaseXBack pp;
    if (Prop.langright) pp = new BaseXBack(new RTLTableLayout(12, 1));
    else pp = new BaseXBack(new TableLayout(12, 1));
    pp.add(new BaseXLabel(DATABASE_PATH + COL, true, true));

    BaseXBack p;
    if (Prop.langright) p = new BaseXBack(new RTLTableLayout(1, 2, 8, 0));
    else p = new BaseXBack(new TableLayout(1, 2, 8, 0));

    final MainProp mprop = gui.context.mprop;
    final GUIProp gprop = gui.gprop;
    path = new BaseXTextField(mprop.dbpath().path(), this);

    final BaseXButton button = new BaseXButton(BROWSE_D, this);
    button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final IOFile file =
                new BaseXFileChooser(CHOOSE_DIR, path.getText(), gui).select(Mode.DOPEN);
            if (file != null) path.setText(file.dirPath());
          }
        });

    p.add(path);
    p.add(button);
    pp.add(p);
    pp.add(new BaseXLabel(GUI_INTERACTIONS + COL, true, true).border(12, 0, 6, 0));

    // checkbox for Java look and feel
    javalook = new BaseXCheckBox(JAVA_LF, gprop.is(GUIProp.JAVALOOK), this);
    pp.add(javalook);

    // checkbox for realtime mouse focus
    focus = new BaseXCheckBox(RT_FOCUS, gprop.is(GUIProp.MOUSEFOCUS), this);
    pp.add(focus);

    // checkbox for simple file dialog
    simpfd = new BaseXCheckBox(SIMPLE_FILE_CHOOSER, gprop.is(GUIProp.SIMPLEFD), this);
    pp.add(simpfd);

    // enable only if current document contains name attributes
    final boolean sn = gprop.is(GUIProp.SHOWNAME);
    names = new BaseXCheckBox(SHOW_NAME_ATTS, sn, 6, this);
    final Data data = gui.context.data();
    names.setEnabled(data != null && ViewData.nameID(data) != 0);
    oldShowNames = sn;
    pp.add(names);

    // maximum number of hits to be displayed
    final int mh = hitsForSlider();
    limit =
        new BaseXSlider(
            0,
            HITS.length - 1,
            mh,
            this,
            new ActionListener() {
              @Override
              public void actionPerformed(final ActionEvent e) {
                action(limit);
              }
            });
    label = new BaseXLabel(" ");
    if (Prop.langright) p = new BaseXBack(new RTLTableLayout(1, 4, 12, 0));
    else p = new BaseXBack(new TableLayout(1, 4, 12, 0));
    p.add(new BaseXLabel(MAX_NO_OF_HITS + COL));
    p.add(limit);
    p.add(label);
    pp.add(p);

    // checkbox for simple file dialog
    pp.add(new BaseXLabel(LANGUAGE_RESTART + COL, true, true).border(16, 0, 6, 0));
    lang = new BaseXCombo(this, LANGS[0]);
    lang.setSelectedItem(mprop.get(MainProp.LANG));
    creds = new BaseXLabel(" ");
    if (Prop.langright) p = new BaseXBack(new RTLTableLayout(1, 2, 12, 0));
    else p = new BaseXBack(new TableLayout(1, 2, 12, 0));
    p.add(lang);
    p.add(creds);
    pp.add(p);

    set(pp, BorderLayout.CENTER);
    set(okCancel(), BorderLayout.SOUTH);
    action(null);
    finish(null);
  }

  @Override
  public void action(final Object cmp) {
    creds.setText(TRANSLATION + COLS + creds(lang.getSelectedItem().toString()));
    if (cmp == names) {
      gui.gprop.set(GUIProp.SHOWNAME, names.isSelected());
      gui.notify.layout();
    }
    final int mh = hitsAsProperty();
    label.setText(mh == -1 ? ALL : Integer.toString(mh));
  }

  @Override
  public void close() {
    final MainProp mprop = gui.context.mprop;
    mprop.set(MainProp.LANG, lang.getSelectedItem().toString());

    // new database path: close existing database
    final String dbpath = path.getText();
    if (!mprop.get(MainProp.DBPATH).equals(dbpath)) gui.execute(new Close());
    mprop.set(MainProp.DBPATH, dbpath);
    mprop.write();

    final int mh = hitsAsProperty();
    gui.context.prop.set(Prop.MAXHITS, mh);

    final GUIProp gprop = gui.gprop;
    gprop.set(GUIProp.MOUSEFOCUS, focus.isSelected());
    gprop.set(GUIProp.SIMPLEFD, simpfd.isSelected());
    gprop.set(GUIProp.JAVALOOK, javalook.isSelected());
    gprop.set(GUIProp.MAXHITS, mh);
    gprop.write();
    dispose();
  }

  @Override
  public void cancel() {
    final boolean sn = gui.gprop.is(GUIProp.SHOWNAME);
    gui.gprop.set(GUIProp.SHOWNAME, oldShowNames);
    if (sn != oldShowNames) gui.notify.layout();
    super.cancel();
  }

  /**
   * Returns the selected maximum number of hits as property value.
   *
   * @return maximum number of hits
   */
  private int hitsAsProperty() {
    return HITS[limit.value()];
  }

  /**
   * Returns the selected maximum number of hits as slider value.
   *
   * @return maximum number of hits
   */
  private int hitsForSlider() {
    int mh = gui.gprop.num(Prop.MAXHITS);
    if (mh == -1) mh = Integer.MAX_VALUE;
    final int hl = HITS.length - 1;
    int h = -1;
    while (++h < hl && HITS[h] < mh) ;
    return h;
  }

  /**
   * Returns the translation credits for the specified language.
   *
   * @param lng language
   * @return credits
   */
  static String creds(final String lng) {
    for (int i = 0; i < LANGS[0].length; ++i) {
      if (LANGS[0][i].equals(lng)) return LANGS[1][i];
    }
    return "";
  }
}
Ejemplo n.º 29
0
 public void updateText() {
   trayParse.setText(Lang.getString("TedMainDialog.TrayMenuParse")); // $NON-NLS-1$
   trayShow.setText(Lang.getString("TedMainDialog.TrayMenuShowTed")); // $NON-NLS-1$
   trayExit.setText(Lang.getString("TedMainDialog.TrayMenuExit")); // $NON-NLS-1$
 }
Ejemplo n.º 30
0
 @Test(expected = IllegalStateException.class)
 public void testInvalidLangIllegalStateException() {
   Lang.loadFromResource("thisIsAMadeUpResourceName", Languages.getInstance(NameType.GENERIC));
 }