You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2011/12/19 15:43:57 UTC

svn commit: r1220779 - in /archiva/trunk/archiva-modules/archiva-web: archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/ archiva-rest/arch...

Author: olamy
Date: Mon Dec 19 14:43:57 2011
New Revision: 1220779

URL: http://svn.apache.org/viewvc?rev=1220779&view=rev
Log:
add i18n rest services for Archiva

Added:
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java   (with props)
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java   (with props)
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default.properties   (with props)
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default_fr.properties   (with props)
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/i18nload.js   (contents, props changed)
      - copied, changed from r1220778, archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/i18nload.js
Removed:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/i18nload.js
Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html

Added: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java?rev=1220779&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java Mon Dec 19 14:43:57 2011
@@ -0,0 +1,49 @@
+package org.apache.archiva.rest.api.services;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * contains some "free" services (i18n)
+ *
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+@Path( "/commonServices/" )
+public interface CommonServices
+{
+    @Path( "getI18nResources" )
+    @GET
+    @Produces( { MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( noRestriction = true )
+    /**
+     * will return properties available in org/apache/archiva/i18n/default.properties
+     * load default (en) then override with locale used so at least en are returned if no
+     * translation in the locale asked.
+     */
+    String getI18nResources( @QueryParam( "locale" ) String locale )
+        throws ArchivaRestServiceException;
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java?rev=1220779&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java Mon Dec 19 14:43:57 2011
@@ -0,0 +1,104 @@
+package org.apache.archiva.rest.services;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
+import org.apache.archiva.rest.api.services.CommonServices;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @author Olivier Lamy
+ */
+@Service( "commonServices#rest" )
+public class DefaultCommonServices
+    implements CommonServices
+{
+
+    private Logger log = LoggerFactory.getLogger( getClass() );
+
+    public String getI18nResources( String locale )
+        throws ArchivaRestServiceException
+    {
+        Properties properties = new Properties();
+
+        StringBuilder resourceName = new StringBuilder( "org/apache/archiva/i18n/default" );
+        try
+        {
+
+            loadResource( properties, resourceName, locale );
+
+        }
+        catch ( IOException e )
+        {
+            log.warn( "skip error loading properties {}", resourceName.toString() );
+        }
+
+        StringBuilder output = new StringBuilder();
+
+        for ( Map.Entry<Object, Object> entry : properties.entrySet() )
+        {
+            output.append( (String) entry.getKey() ).append( '=' ).append( (String) entry.getValue() );
+            output.append( '\n' );
+        }
+
+        return output.toString();
+    }
+
+    private void loadResource( Properties properties, StringBuilder resourceName, String locale )
+        throws IOException
+    {
+        // load default
+        loadResource( properties, new StringBuilder( resourceName ).append( ".properties" ).toString() );
+        // if locale override with locale content
+        if ( StringUtils.isNotEmpty( locale ) )
+        {
+            loadResource( properties,
+                          new StringBuilder( resourceName ).append( "_" + locale ).append( ".properties" ).toString() );
+        }
+
+    }
+
+    private void loadResource( Properties properties, String resourceName )
+        throws IOException
+    {
+        InputStream is = null;
+
+        try
+        {
+            is = Thread.currentThread().getContextClassLoader().getResourceAsStream( resourceName.toString() );
+            if ( is != null )
+            {
+                properties.load( is );
+            }
+        }
+        finally
+        {
+            IOUtils.closeQuietly( is );
+        }
+    }
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml?rev=1220779&r1=1220778&r2=1220779&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml Mon Dec 19 14:43:57 2011
@@ -57,6 +57,7 @@
       <ref bean="networkProxyService#rest"/>
       <ref bean="archivaAdministrationService#default"/>
       <ref bean="searchService#rest"/>
+      <ref bean="commonServices#rest"/>
     </jaxrs:serviceBeans>
 
     <jaxrs:outInterceptors>

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default.properties
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default.properties?rev=1220779&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default.properties (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default.properties Mon Dec 19 14:43:57 2011
@@ -0,0 +1,21 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# --------------------------------------------------------------------
+#  Archiva webapp i18n default en file
+# --------------------------------------------------------------------

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default_fr.properties
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default_fr.properties?rev=1220779&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default_fr.properties (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default_fr.properties Mon Dec 19 14:43:57 2011
@@ -0,0 +1,21 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# --------------------------------------------------------------------
+#  Archiva webapp i18n fr file
+# --------------------------------------------------------------------

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default_fr.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default_fr.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html?rev=1220779&r1=1220778&r2=1220779&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html Mon Dec 19 14:43:57 2011
@@ -45,16 +45,16 @@
        .script("jquery.tmpl.js").wait()
        .script("archiva/utils.js").wait()
        .script("jquery.i18n.properties-1.0.9.js").wait()
-       .script("redback/i18nload.js").wait()
-       .script("archiva/main-tmpl.js").wait()
+       .script("archiva/i18nload.js").wait()
        .script("jquery.cookie.1.0.0.js").wait()
        .script("knockout-debug.js").wait()
        .script("jquery-ui-1.8.16.custom.min.js").wait()
        .script("jquery.validate.js").wait()
        .script("jquery.json-2.3.min.js").wait()
+       .script("archiva/main-tmpl.js").wait()
        .script("redback/operation.js").wait()
        .script("redback/redback-tmpl.js").wait()
-       .script("bootstrap-tabs.js")
+       .script("bootstrap-tabs.js").wait()
        .script("bootstrap-modal.js").wait()
        .script("bootstrap-alerts.js").wait()
        .script("bootstrap-dropdown.js").wait()

Copied: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/i18nload.js (from r1220778, archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/i18nload.js)
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/i18nload.js?p2=archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/i18nload.js&p1=archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/i18nload.js&r1=1220778&r2=1220779&rev=1220779&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/i18nload.js (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/i18nload.js Mon Dec 19 14:43:57 2011
@@ -18,9 +18,18 @@
  */
 
 $(function() {
+  // load i18n resources from rest call
+  // first redback then archiva
+  // -- redback
   // load default
   loadAndParseFile("restServices/redbackServices/utilServices/getBundleResources", {cache:false, mode: 'map',encoding:'utf-8'});
   // load browser locale
   var browserLang = $.i18n.browserLang();
   loadAndParseFile("restServices/redbackServices/utilServices/getBundleResources?locale="+browserLang, {cache:false, mode: 'map',encoding:'utf-8'});
+  // -- archiva
+  // load default
+  loadAndParseFile("restServices/archivaServices/commonServices/getI18nResources", {cache:false, mode: 'map',encoding:'utf-8'});
+  // load browser locale
+  var browserLang = $.i18n.browserLang();
+  loadAndParseFile("restServices/archivaServices/commonServices/getI18nResources?locale="+browserLang, {cache:false, mode: 'map',encoding:'utf-8'});
 });
\ No newline at end of file

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/i18nload.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/i18nload.js
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision