--- /dev/null
+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;
+}
--- /dev/null
+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 );
+ }
+ }
+}
<ref bean="networkProxyService#rest"/>
<ref bean="archivaAdministrationService#default"/>
<ref bean="searchService#rest"/>
+ <ref bean="commonServices#rest"/>
</jaxrs:serviceBeans>
<jaxrs:outInterceptors>
--- /dev/null
+#
+# 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
+# --------------------------------------------------------------------
--- /dev/null
+#
+# 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
+# --------------------------------------------------------------------
.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()
--- /dev/null
+/*
+ * 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
+++ /dev/null
-/*
- * 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