Example usage for java.util Locale getDisplayLanguage

List of usage examples for java.util Locale getDisplayLanguage

Introduction

In this page you can find the example usage for java.util Locale getDisplayLanguage.

Prototype

public final String getDisplayLanguage() 

Source Link

Document

Returns a name for the locale's language that is appropriate for display to the user.

Usage

From source file:morphy.command.SetCommand.java

private String[] getDistinctLocalesByLanguage() {
    List<String> list = new ArrayList<String>();
    Locale[] arr = Locale.getAvailableLocales();
    for (Locale l : arr) {
        String v = l.getDisplayLanguage();
        if (!list.contains(v))
            list.add(v);/*from   w w w.j  av a  2  s  . c o m*/
    }
    return list.toArray(new String[list.size()]);
}

From source file:no.abmu.common.locale.LocaleUtil.java

/**
 * Method for logging of locale. Used under test and development.
 * /*www.  j a v  a2  s. c  o  m*/
 * @param request current HTTP request
 */

public void logLocale(HttpServletRequest request) {
    HttpSession session = request.getSession(false);

    String parameterSiteLocale = request.getParameter("siteLocale");
    String parameterStartLocale = request.getParameter("startLocale");
    String rcSiteLocale = (String) request.getAttribute("siteLocale");
    //        String seSiteLocale = (String) session.getAttribute("siteLocale");

    Locale locale = RequestContextUtils.getLocale(request);

    logger.info("request siteLocale: " + rcSiteLocale);
    logger.info("request parameter siteLocale: " + parameterSiteLocale);
    logger.info("request parameter startLocale: " + parameterStartLocale);
    //        logger.info("session siteLocale: " + seSiteLocale);

    logger.info("Locale getDisplayCountry: " + locale.getDisplayCountry());
    logger.info("Locale getDisplayLanguage: " + locale.getDisplayLanguage());
    logger.info("Locale getDisplayVariant: " + locale.getDisplayVariant());
    logger.info("Locale getDisplayName: " + locale.getDisplayName());
    logger.info("Locale getISO3Country: " + locale.getISO3Country());
    logger.info("Locale getLanguage: " + locale.getLanguage());
    logger.info("Locale getVariant: " + locale.getVariant());
    logger.info("Locale toString: " + locale.toString());

}

From source file:edu.cornell.mannlib.vitro.webapp.filters.WebappDaoFactorySparqlPrep.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {

    if (request.getAttribute("WebappDaoFactorySDBPrep.setup") != null) {
        // don't run multiple times
        filterChain.doFilter(request, response);
        return;/*from   w  ww. j  ava 2  s  . com*/
    }

    for (Pattern skipPattern : skipPatterns) {
        Matcher match = skipPattern.matcher(((HttpServletRequest) request).getRequestURI());
        if (match.matches()) {
            log.debug("request matched a skipPattern, skipping VitroRequestPrep");
            filterChain.doFilter(request, response);
            return;
        }
    }

    javax.sql.DataSource ds = JenaDataSourceSetupBase.getApplicationDataSource(_ctx);
    StoreDesc storeDesc = (StoreDesc) _ctx.getAttribute("storeDesc");
    OntModelSelector oms = (OntModelSelector) _ctx.getAttribute("unionOntModelSelector");
    String defaultNamespace = (String) _ctx.getAttribute("defaultNamespace");
    Connection sqlConn = null;
    SDBConnection conn = null;
    Store store = null;
    Dataset dataset = null;
    WebappDaoFactory wadf = null;

    try {
        if (ds == null || storeDesc == null || oms == null) {
            throw new RuntimeException("SDB store not property set up");
        }

        try {
            sqlConn = ds.getConnection();
            conn = new SDBConnection(sqlConn);
        } catch (SQLException sqe) {
            throw new RuntimeException("Unable to connect to database", sqe);
        }
        if (conn != null) {
            store = SDBFactory.connectStore(conn, storeDesc);
            dataset = SDBFactory.connectDataset(store);
            VitroRequest vreq = new VitroRequest((HttpServletRequest) request);

            log.info("---------");

            Enumeration<String> headStrs = vreq.getHeaderNames();
            while (headStrs.hasMoreElements()) {
                String head = headStrs.nextElement();
                log.info(head + " : " + vreq.getHeader(head));
            }

            List<String> langs = new ArrayList<String>();

            log.info("Accept-Language: " + vreq.getHeader("Accept-Language"));
            Enumeration<Locale> locs = vreq.getLocales();
            while (locs.hasMoreElements()) {
                Locale locale = locs.nextElement();
                langs.add(locale.toString().replace("_", "-"));
                log.info(locale.toString() + " / " + locale.getLanguage() + " + " + locale.getCountry() + " : "
                        + locale.getDisplayCountry() + " | " + locale.getLanguage() + " : "
                        + locale.getDisplayLanguage());
            }
            WebappDaoFactoryConfig config = new WebappDaoFactoryConfig();
            config.setDefaultNamespace(defaultNamespace);
            config.setPreferredLanguages(langs);

            //okay let's make a graph-backed model
            String endpointURI = ConfigurationProperties.getBean(request)
                    .getProperty("VitroConnection.DataSource.endpointURI");

            Graph g = new SparqlGraphMultilingual(endpointURI, langs);
            //Graph g = new SparqlGraph(endpointURI);

            Model m = ModelFactory.createModelForGraph(g);
            OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, m);
            oms = new SingleContentOntModelSelector(om, oms.getDisplayModel(), oms.getUserAccountsModel());

            dataset = DatasetFactory.create(new SparqlDatasetGraph(endpointURI));

            //DataSource datasource = DatasetFactory.create();
            //datasource.addNamedModel("fake:fake", m);
            //dataset = datasource;         

            vreq.setAssertionsWebappDaoFactory(wadf);

            wadf = new WebappDaoFactoryJena(oms, config);
            //wadf = new WebappDaoFactorySDB(oms, dataset, config);
            vreq.setWebappDaoFactory(wadf);
            vreq.setFullWebappDaoFactory(wadf);
            vreq.setUnfilteredWebappDaoFactory(wadf);
            vreq.setWebappDaoFactory(wadf);
            vreq.setDataset(dataset);
            vreq.setJenaOntModel(om);
            vreq.setOntModelSelector(oms);
        }
    } catch (Throwable t) {
        log.error("Unable to filter request to set up SDB connection", t);
    }

    request.setAttribute("WebappDaoFactorySDBPrep.setup", 1);

    try {
        filterChain.doFilter(request, response);
        return;
    } finally {
        if (conn != null) {
            conn.close();
        }
        if (dataset != null) {
            dataset.close();
        }
        if (store != null) {
            store.close();
        }
        if (wadf != null) {
            wadf.close();
        }
    }

}

From source file:countries.ListCountry.java

public void getListOfCountries() {
    int supportedLocale = 0, nonSupportedLocale = 0;

    for (String countryCode : getISOCountries()) {

        Locale locale = null;
        if (!languagesOfCountries.containsKey(countryCode)) {
            locale = new Locale("", countryCode);
            nonSupportedLocale++;//from w  w  w.  j a  v  a  2s  .c o m
        } else {
            // create a Locale with own country's languages
            locale = new Locale(languagesOfCountries.get(countryCode), countryCode);
            supportedLocale++;
        }
        out.printf("Country Code: %1$2s, Name: %2$-45s %3$-45s %4$-45s Languages: %5$10s\n",
                locale.getCountry(), locale.getDisplayCountry(ENGLISH),
                parens(locale.getDisplayCountry(FRENCH)), parens(locale.getDisplayCountry(locale)),
                locale.getDisplayLanguage());
    }
    out.println("nonSupportedLocale: " + nonSupportedLocale);
    out.println("supportedLocale: " + supportedLocale);
}

From source file:org.opencms.workplace.tools.database.CmsHtmlImportDialog.java

/**
 * Returns a list with all available local's.<p>
 * //from   w w w.j a va  2 s  . c o m
 * @return a list with all available local's
 */
private List getLocales() {

    ArrayList ret = new ArrayList();

    try {
        Iterator i = OpenCms.getLocaleManager().getAvailableLocales().iterator();

        // loop through all local's and build the entries
        while (i.hasNext()) {
            Locale locale = (Locale) i.next();
            String language = locale.getLanguage();
            String displayLanguage = locale.getDisplayLanguage();

            ret.add(new CmsSelectWidgetOption(language, false, displayLanguage));
        }
    } catch (Exception e) {
        // not necessary
    }
    return ret;
}

From source file:org.opensextant.util.TextUtils.java

/**
 * Initialize language codes and metadata. This establishes a map for the
 * most common language codes/names that exist in at least ISO-639-1 and
 * have a non-zero 2-char ID.//from w w w.  j  av a2s.  co  m
 *
 * <pre>
 * Based on:
 * http://stackoverflow.com/questions/674041/is-there-an-elegant-way
 * -to-convert-iso-639-2-3-letter-language-codes-to-java-lo
 *
 * Actual code mappings: en =&gt; eng eng =&gt; en
 *
 * cel =&gt; '' // Celtic; Avoid this.
 *
 * tr =&gt; tur tur =&gt; tr
 *
 * Names: tr =&gt; turkish tur =&gt; turkish turkish =&gt; tr // ISO2 only
 *
 * </pre>
 */
public static void initLanguageData() {
    Locale[] locales = Locale.getAvailableLocales();
    for (Locale locale : locales) {
        Language l = new Language(locale.getISO3Language(), locale.getLanguage(), locale.getDisplayLanguage());
        addLanguage(l);
    }
}

From source file:org.opencms.ui.sitemap.CmsLocaleLinkTargetSelectionDialog.java

/**
 * Creates a new instance.<p>//from www. j  av a  2s. c om
 *
 * @param context the dialog context
 * @param localeContext the locale compare context
 *
 * @throws CmsException if something goes wrong
 */
public CmsLocaleLinkTargetSelectionDialog(I_CmsDialogContext context, I_CmsLocaleCompareContext localeContext)
        throws CmsException {
    super(CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireFolder());

    m_localeContext = localeContext;
    CmsResource contextResource = context.getResources().get(0);
    CmsResource realFile = contextResource;
    if (realFile.isFolder()) {
        CmsResource defaultFile = context.getCms().readDefaultFile(realFile,
                CmsResourceFilter.IGNORE_EXPIRATION);
        if (defaultFile != null) {
            realFile = defaultFile;
        }
    }
    getContents().displayResourceInfo(Collections.singletonList(realFile));

    IndexedContainer siteData = (IndexedContainer) getContents().getSiteSelector().getContainerDataSource();

    m_context = context;

    CmsLocaleGroup localeGroup = localeContext.getLocaleGroup();
    Map<Locale, CmsResource> resourcesByLocale = localeGroup.getResourcesByLocale();
    int index = 0;
    for (Map.Entry<Locale, CmsResource> entry : resourcesByLocale.entrySet()) {
        Locale localeKey = entry.getKey();
        CmsResource resourceValue = entry.getValue();
        String folderPath = null;
        if (resourceValue.isFile()) {
            folderPath = CmsResource.getParentFolder(resourceValue.getRootPath());
        } else {
            folderPath = resourceValue.getRootPath();
        }

        Item item = siteData.addItemAt(index, folderPath);
        index++;
        item.getItemProperty(getContents().getSiteSelector().getItemCaptionPropertyId()).setValue(CmsVaadinUtils
                .getMessageText(Messages.GUI_LOCALECOMPARE_LOCALE_LABEL_1, localeKey.getDisplayLanguage()));
    }

    addSelectionHandler(new I_CmsSelectionHandler<CmsResource>() {

        public void onSelection(CmsResource selected) {

            onClickOk(selected);
        }
    });
    getFileTree().setSelectionFilter(new Predicate<Item>() {

        public boolean apply(Item item) {

            CmsResource resource = (CmsResource) (item
                    .getItemProperty(CmsResourceTreeContainer.PROPERTY_RESOURCE).getValue());
            CmsResource srcResource = m_context.getResources().get(0);
            switch (A_CmsUI.getCmsObject().getLocaleGroupService().checkLinkable(srcResource, resource)) {
            case linkable:
                return true;
            default:
                return false;

            }
        }
    });

    Locale secondaryLocale = m_localeContext.getComparisonLocale();
    CmsLocaleGroup group = m_localeContext.getLocaleGroup();
    CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(m_localeContext.getRoot().getRootPath());
    if (group.hasLocale(secondaryLocale)) {

        CmsResource res = group.getResourcesByLocale().get(secondaryLocale);
        String folder = res.getRootPath();
        if (res.isFile()) {
            folder = CmsResource.getParentFolder(folder);
        }
        getContents().getSiteSelector().setValue(folder);
    } else if (site != null) {
        getContents().getSiteSelector().setValue(site.getSiteRoot());
    }

}

From source file:me.cavar.pg2tei.TEIDoc.java

/**
 *
 * @return Document/*from  w  w  w  .  jav a2s  .c o  m*/
 * @throws ParserConfigurationException
 */
public void genTEIXMLDom() {
    try {
        DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
        this.mydom = docBuilder.newDocument();

        // TEI root element
        Element root = this.mydom.createElement("TEI");
        root.setAttribute("xmlns", "http://www.tei-c.org/ns/1.0");
        this.mydom.appendChild(root);
        this.mydom.insertBefore(this.mydom.createProcessingInstruction("xml-model",
                "href=\"http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/teilite.rng\""
                        + " schematypens=\"http://relaxng.org/ns/structure/1.0\""),
                root);

        // create teiHeader section
        Element teiHeader = this.mydom.createElement("teiHeader");
        root.appendChild(teiHeader);

        // create fileDescription section
        Element fileDesc = this.mydom.createElement("fileDesc");
        teiHeader.appendChild(fileDesc);

        // create titleStmt
        Element titleStmt = this.mydom.createElement("titleStmt");
        // check for multi-line titles
        Element ltmp;
        Element tmp = this.mydom.createElement("title");
        tmp.setAttribute("type", "full");
        int numTitles = this.title.size();
        if (numTitles > 0) {
            String tmpStr = this.title.get(numTitles - 1);
            if (tmpStr.contains("\n")) {
                // make multiple title statements
                String[] subStrs = tmpStr.split("\n");

                // the first one is main
                ltmp = this.mydom.createElement("title");
                ltmp.setAttribute("type", "main");
                ltmp.appendChild(this.mydom.createTextNode(subStrs[0]));
                tmp.appendChild(ltmp);

                // TODO
                // all others are sub should not be... but...
                for (int i = 1; i < subStrs.length; i++) {
                    ltmp = this.mydom.createElement("title");
                    ltmp.setAttribute("type", "sub");
                    ltmp.appendChild(this.mydom.createTextNode(subStrs[i]));
                    tmp.appendChild(ltmp);
                }
                // titleStmt.appendChild(tmp);
            } else { // make single title statement
                ltmp = this.mydom.createElement("title");
                ltmp.setAttribute("type", "main");
                ltmp.appendChild(this.mydom.createTextNode(this.title.get(numTitles - 1)));
                tmp.appendChild(ltmp);
            }
        }
        ltmp = this.mydom.createElement("title");
        ltmp.setAttribute("type", "alt");
        ltmp.appendChild(this.mydom.createTextNode(this.friendlyTitle));
        tmp.appendChild(ltmp);
        titleStmt.appendChild(tmp);

        // add author information
        tmp = this.mydom.createElement("author");
        if (this.creator != null) {
            // split year of from author string
            Pattern nameSplitRE = Pattern
                    .compile("(?<name>[\\w,\\s]+)(?<year>,\\s+\\d\\d\\d\\d\\s?-+\\s?\\d\\d\\d\\d)");
            Matcher matcher = nameSplitRE.matcher(this.creator);
            if (matcher.find(0)) {
                String tmpN = matcher.group("name");
                //String tmpY = matcher.group("year");
                tmp.appendChild(this.mydom.createTextNode(tmpN));
            } else {
                tmp.appendChild(this.mydom.createTextNode(this.creator));
            }
        }
        titleStmt.appendChild(tmp);
        fileDesc.appendChild(titleStmt);

        // publicationStmt in fileDesc
        Element publicationStmt = this.mydom.createElement("publicationStmt");
        tmp = this.mydom.createElement("publisher");
        if (this.publisher != null) {
            tmp.appendChild(this.mydom.createTextNode(this.publisher));
        }
        publicationStmt.appendChild(tmp);
        // date
        tmp = this.mydom.createElement("date");
        if (this.createdW3CDTF != null) {
            tmp.appendChild(this.mydom.createTextNode(this.createdW3CDTF));
        }
        publicationStmt.appendChild(tmp);
        // availability
        tmp = this.mydom.createElement("availability");
        ltmp = this.mydom.createElement("licence");
        for (String right : this.rights) {
            Element ptmp = this.mydom.createElement("p");
            ptmp.appendChild(this.mydom.createTextNode(right));
            ltmp.appendChild(ptmp);
        }
        tmp.appendChild(ltmp);
        publicationStmt.appendChild(tmp);
        // distributor
        tmp = this.mydom.createElement("distributor");
        // tmp.appendChild(doc.createTextNode("Distributed in the TEI XML format by:"));
        Element ptmp;
        ptmp = this.mydom.createElement("name");
        ptmp.setAttribute("xml:id", "DC");
        ptmp.appendChild(this.mydom.createTextNode("Damir Cavar"));
        tmp.appendChild(ptmp);
        ptmp = this.mydom.createElement("name");
        ptmp.setAttribute("xml:id", "LTL");
        ptmp.appendChild(this.mydom.createTextNode("Language Technology Lab"));
        tmp.appendChild(ptmp);
        ptmp = this.mydom.createElement("name");
        ptmp.setAttribute("xml:id", "ILIT");
        ptmp.appendChild(this.mydom.createTextNode("Institute for Language Information and Technology"));
        tmp.appendChild(ptmp);
        ptmp = this.mydom.createElement("name");
        ptmp.setAttribute("xml:id", "EMU");
        ptmp.appendChild(this.mydom.createTextNode("Eastern Michigan University"));
        tmp.appendChild(ptmp);

        ltmp = this.mydom.createElement("address");
        // add address info
        ptmp = this.mydom.createElement("addrLine");
        ptmp.appendChild(this.mydom.createTextNode("2000 E. Huron River Dr., Suite 104"));
        ltmp.appendChild(ptmp);
        ptmp = this.mydom.createElement("addrLine");
        ptmp.appendChild(this.mydom.createTextNode("Ypsilanti, MI 48197"));
        ltmp.appendChild(ptmp);
        ptmp = this.mydom.createElement("addrLine");
        ptmp.appendChild(this.mydom.createTextNode("USA"));
        ltmp.appendChild(ptmp);
        tmp.appendChild(ltmp);
        publicationStmt.appendChild(tmp);
        // idno
        tmp = this.mydom.createElement("idno");
        if (this.id != null) {
            tmp.appendChild(this.mydom.createTextNode(Integer.toString(this.idN)));
        }
        publicationStmt.appendChild(tmp);
        fileDesc.appendChild(publicationStmt);

        // --------------------------------------------
        // sourceDesc in fileDesc
        Element sourceDesc = this.mydom.createElement("sourceDesc");
        // contains a <p> with a description of the source
        tmp = this.mydom.createElement("p");
        tmp.appendChild(this.mydom.createTextNode("This text was automatically "
                + "converted from the corresponding HTML formated text found in the "
                + "Project Gutenberg (http://www.gutenberg.org/) collection."));
        sourceDesc.appendChild(tmp);
        if (this.creator != null) {
            tmp = this.mydom.createElement("p");
            tmp.appendChild(this.mydom.createTextNode("Creator: " + this.creator));
            sourceDesc.appendChild(tmp);
        }
        if (this.description != null) {
            tmp = this.mydom.createElement("p");
            tmp.appendChild(this.mydom.createTextNode(this.description));
            sourceDesc.appendChild(tmp);
        }
        fileDesc.appendChild(sourceDesc);

        // --------------------------------------------
        // encodingDesc in teiHeader
        Element encodingDesc = this.mydom.createElement("encodingDesc");
        // contains a appInfo with a description of the source
        tmp = this.mydom.createElement("appInfo");
        // appInfo contains application
        ltmp = this.mydom.createElement("application");
        ltmp.setAttribute("ident", "gutenberg2tei");
        ltmp.setAttribute("version", "1.0");
        ptmp = this.mydom.createElement("desc");
        ptmp.appendChild(
                this.mydom.createTextNode("Conversion tool using the RDF file catalog and meta-information "
                        + "and conversion of HTML to TEI XML."));
        ltmp.appendChild(ptmp);
        tmp.appendChild(ltmp);
        encodingDesc.appendChild(tmp);
        // contains projectDesc
        tmp = this.mydom.createElement("projectDesc");
        ltmp = this.mydom.createElement("p");
        ltmp.appendChild(this.mydom.createTextNode("The conversion of the Project Gutenberg "
                + "texts to the TEI XML format started as an independent project at ILIT, EMU."));
        tmp.appendChild(ltmp);
        encodingDesc.appendChild(tmp);
        // contains samplingDecl
        tmp = this.mydom.createElement("samplingDecl");
        ltmp = this.mydom.createElement("p");
        ltmp.appendChild(this.mydom.createTextNode(""));
        tmp.appendChild(ltmp);
        encodingDesc.appendChild(tmp);
        // classDecl
        tmp = this.mydom.createElement("classDecl");
        ltmp = this.mydom.createElement("taxonomy");
        ltmp.setAttribute("xml:id", "lcsh");
        ptmp = this.mydom.createElement("bibl");
        ptmp.appendChild(this.mydom.createTextNode("Library of Congress Subject Headings"));
        ltmp.appendChild(ptmp);
        tmp.appendChild(ltmp);
        ltmp = this.mydom.createElement("taxonomy");
        ltmp.setAttribute("xml:id", "lc");
        ptmp = this.mydom.createElement("bibl");
        ptmp.appendChild(this.mydom.createTextNode("Library of Congress Classification"));
        ltmp.appendChild(ptmp);
        tmp.appendChild(ltmp);
        ltmp = this.mydom.createElement("taxonomy");
        ltmp.setAttribute("xml:id", "pg");
        ptmp = this.mydom.createElement("bibl");
        ptmp.appendChild(this.mydom.createTextNode("Project Gutenberg Category"));
        ltmp.appendChild(ptmp);
        tmp.appendChild(ltmp);
        encodingDesc.appendChild(tmp);

        teiHeader.appendChild(encodingDesc);

        // --------------------------------------------
        // profileDesc in teiHeader
        Element profileDesc = this.mydom.createElement("profileDesc");
        // contains creation contains date
        tmp = this.mydom.createElement("creation");
        ltmp = this.mydom.createElement("date");
        ltmp.appendChild(this.mydom.createTextNode(this.createdW3CDTF));
        tmp.appendChild(ltmp);
        // add the author name here too, although not correct...
        //ltmp = doc.createElement("name");
        //ltmp.appendChild(doc.createTextNode(this.creator));
        //tmp.appendChild(ltmp);
        profileDesc.appendChild(tmp);
        // contains langUsage
        if (this.languageCode != null) {
            tmp = this.mydom.createElement("langUsage");
            ltmp = this.mydom.createElement("language");
            ltmp.setAttribute("ident", this.languageCode);
            Locale aLocale = Locale.forLanguageTag(this.languageCode);
            ltmp.appendChild(this.mydom.createTextNode(aLocale.getDisplayLanguage() + "."));
            tmp.appendChild(ltmp);
            profileDesc.appendChild(tmp);
        }
        // textClass
        tmp = this.mydom.createElement("textClass");
        ltmp = this.mydom.createElement("keywords");
        ltmp.setAttribute("scheme", "#lcsh");
        if (this.subjectHeadingsLCC.size() > 0) {
            for (String term : this.subjectHeadingsLCC) {
                ptmp = this.mydom.createElement("term");
                ptmp.appendChild(this.mydom.createTextNode(term));
                ltmp.appendChild(ptmp);
            }
        } else {
            ptmp = this.mydom.createElement("term");
            // ptmp.appendChild(doc.createTextNode(term));
            ltmp.appendChild(ptmp);
        }
        tmp.appendChild(ltmp);
        if (this.classificationLCC != null) {
            ltmp = this.mydom.createElement("classCode");
            ltmp.setAttribute("scheme", "#lc");
            ltmp.appendChild(this.mydom.createTextNode(this.classificationLCC));
            tmp.appendChild(ltmp);
        }
        if (this.projGCategory != null) {
            ltmp = this.mydom.createElement("classCode");
            ltmp.setAttribute("scheme", "#pg");
            ltmp.appendChild(this.mydom.createTextNode(this.projGCategory));
            tmp.appendChild(ltmp);
        }
        profileDesc.appendChild(tmp);
        teiHeader.appendChild(profileDesc);

        // --------------------------------------------
        // revisionDesc in teiHeader
        Element revisionDesc = this.mydom.createElement("revisionDesc");
        // contains a list of change tags
        tmp = this.mydom.createElement("change");
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        Date t = new Date();
        tmp.setAttribute("when", ft.format(t));
        tmp.setAttribute("who", "#DC");
        tmp.appendChild(this.mydom.createTextNode("Initial conversion from HTML to TEI XML."));
        revisionDesc.appendChild(tmp);
        teiHeader.appendChild(revisionDesc);
        // create text section
        // Element text = this.mydom.createElement("text");
        // !!!
        // skip that and just append the text-Element from the converted HTML-document.
        // !!!
        // root.appendChild(text);
    } catch (ParserConfigurationException e) {
        Logger.getLogger(Fetcher.class.getName()).log(Level.SEVERE, null, e);
    }
}

From source file:org.sakaiproject.jsf.renderer.InputRichTextRenderer.java

/**
 * Write configuration script/*from w w w. j av a2 s  . c o  m*/
 *
 * @param clientId the client id
 * @param toolbar the toolbar configuration string (i.e from makeToolbarScript())
 * @param widthPx columns
 * @param heightPx rows
 */
protected void writeConfigurationScript(FacesContext context, UIComponent component, String clientId,
        String toolbar, int widthPx, int heightPx, String showXPath, Locale locale, ResponseWriter writer)
        throws IOException {
    // script creates unique Config object
    String configVar = "config" + createSafeRandomNumber();

    writer.write("<script type=\"text/javascript\">\n");
    writer.write("  sakaiSetLanguage(\"" + locale.getDisplayLanguage() + "\");");
    writer.write("  var " + configVar + "=new HTMLArea.Config();\n");
    writer.write("  sakaiRegisterButtons(" + configVar + ");\n");
    writer.write("  " + configVar + ".toolbar = " + toolbar + ";\n");
    writer.write("  " + configVar + ".width=\"" + widthPx + "px\";\n");
    writer.write("  " + configVar + ".height=\"" + heightPx + "px\";\n");
    writer.write("  " + configVar + ".statusBar=" + showXPath + ";\n");
    writeAdditionalConfig(context, component, configVar, clientId, toolbar, widthPx, heightPx, locale, writer);
    writer.write("sakaiSetupRichTextarea(\"");
    writer.write(clientId);
    writer.write("_inputRichText\"," + configVar + ");\n");
    writer.write("</script>\n");
}

From source file:savant.view.swing.Savant.java

private static void logUsageStats() {
    try {/*w w w .  j  a v a  2 s  .com*/
        URLConnection urlConn;
        DataOutputStream printout;
        // URL of CGI-Bin script.
        // URL connection channel.
        urlConn = BrowserSettings.LOG_USAGE_STATS_URL.openConnection();
        // Let the run-time system (RTS) know that we want input.
        urlConn.setDoInput(true);
        // Let the RTS know that we want to do output.
        urlConn.setDoOutput(true);
        // No caching, we want the real thing.
        urlConn.setUseCaches(false);
        // Specify the content type.
        urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        // Send POST output.
        printout = new DataOutputStream(urlConn.getOutputStream());

        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        Locale locale = Locale.getDefault();

        String content = post("time", dateFormat.format(date)) + "&"
                + post("language", locale.getDisplayLanguage()) + "&"
                + post("user.timezone", System.getProperty("user.timezone")) + "&"
                + post("savant.version", BrowserSettings.VERSION) + "&"
                + post("savant.build", BrowserSettings.BUILD)
                //+ "&" + post("address", InetAddress.getLocalHost().getHostAddress())
                + "&" + post("java.version", System.getProperty("java.version")) + "&"
                + post("java.vendor", System.getProperty("java.vendor")) + "&"
                + post("os.name", System.getProperty("os.name")) + "&"
                + post("os.arch", System.getProperty("os.arch")) + "&"
                + post("os.version", System.getProperty("os.version")) + "&"
                + post("user.region", System.getProperty("user.region"));

        printout.writeBytes(content);
        printout.flush();
        printout.close();
        urlConn.getInputStream();
    } catch (Exception ex) {
        //LOG.error("Error logging usage stats.", ex);
    }
}