]> source.dussan.org Git - archiva.git/commitdiff
add i18n rest services for Archiva
authorOlivier Lamy <olamy@apache.org>
Mon, 19 Dec 2011 14:43:57 +0000 (14:43 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 19 Dec 2011 14:43:57 +0000 (14:43 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1220779 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default.properties [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default_fr.properties [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/i18nload.js [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/i18nload.js [deleted file]

diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java
new file mode 100644 (file)
index 0000000..c33615a
--- /dev/null
@@ -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;
+}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
new file mode 100644 (file)
index 0000000..75cffe7
--- /dev/null
@@ -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 );
+        }
+    }
+}
index 5cd75664d15bb251de3a7261d25818f57b3863ce..6f0b6b9bcbb67f15c92bf618453bdb1a573e61a7 100644 (file)
@@ -57,6 +57,7 @@
       <ref bean="networkProxyService#rest"/>
       <ref bean="archivaAdministrationService#default"/>
       <ref bean="searchService#rest"/>
+      <ref bean="commonServices#rest"/>
     </jaxrs:serviceBeans>
 
     <jaxrs:outInterceptors>
diff --git a/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default.properties b/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default.properties
new file mode 100644 (file)
index 0000000..22d5265
--- /dev/null
@@ -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
+# --------------------------------------------------------------------
diff --git a/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default_fr.properties b/archiva-modules/archiva-web/archiva-webapp-common/src/main/resources/org/apache/archiva/i18n/default_fr.properties
new file mode 100644 (file)
index 0000000..9ad0368
--- /dev/null
@@ -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
+# --------------------------------------------------------------------
index dc30547241149fe1a562e871deb505211b65247c..73fe81d0c6a3b1a492b8ab0dac1a8203d0e160fe 100644 (file)
        .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()
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/i18nload.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/i18nload.js
new file mode 100644 (file)
index 0000000..abee4c1
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+$(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
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/i18nload.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/i18nload.js
deleted file mode 100644 (file)
index 36bca5d..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.
- */
-
-$(function() {
-  // 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'});
-});
\ No newline at end of file