You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by an...@apache.org on 2014/06/30 15:32:35 UTC

svn commit: r1606726 - in /syncope/trunk: console/src/main/java/org/apache/syncope/console/init/ console/src/main/java/org/apache/syncope/console/pages/ console/src/main/java/org/apache/syncope/console/preview/ console/src/main/java/org/apache/syncope/...

Author: andreapatricelli
Date: Mon Jun 30 13:32:34 2014
New Revision: 1606726

URL: http://svn.apache.org/r1606726
Log:
[SYNCOPE-516] provided some smart binary schema enhancements to improve its usability

Added:
    syncope/trunk/console/src/main/java/org/apache/syncope/console/init/
    syncope/trunk/console/src/main/java/org/apache/syncope/console/init/MIMETypesInitializer.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/init/PreviewPanelClassInitializer.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/init/SpringContextInitializer.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/
    syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/BinaryPreview.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/PreviewUtil.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/PreviewerClassScanner.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/
    syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryCertPreviewer.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryImagePreviewer.java
    syncope/trunk/console/src/main/resources/MIMETypes
    syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/
    syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.html
    syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryCertPreviewer.html
    syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryImagePreviewer.html
    syncope/trunk/console/src/main/webapp/img/file-download.png   (with props)
    syncope/trunk/console/src/main/webapp/img/file-upload.png   (with props)
Modified:
    syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/AbstractBasePage.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/RoleModalPage.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/SchemaModalPage.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/AjaxTextFieldPanel.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/BinaryFieldPanel.java
    syncope/trunk/console/src/main/resources/applicationContext.xml
    syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/BinaryFieldPanel.html
    syncope/trunk/core/src/test/resources/content.xml

Added: syncope/trunk/console/src/main/java/org/apache/syncope/console/init/MIMETypesInitializer.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/init/MIMETypesInitializer.java?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/init/MIMETypesInitializer.java (added)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/init/MIMETypesInitializer.java Mon Jun 30 13:32:34 2014
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+package org.apache.syncope.console.init;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.wicket.util.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MIMETypesInitializer {
+
+    /**
+     * Logger.
+     */
+    private static final Logger LOG = LoggerFactory.getLogger(MIMETypesInitializer.class);
+
+    private List<String> mimeTypes;
+
+    public void load() {
+        final Set<String> mediaTypes = new HashSet<String>();
+        this.mimeTypes = new ArrayList<String>();
+        try {
+            final String mimeTypesFile = IOUtils.toString(this.getClass().getResourceAsStream("/MIMETypes"));
+            for (String fileRow : mimeTypesFile.split("\n")) {
+                if (StringUtils.isNotBlank(fileRow) && !fileRow.startsWith("#")) {
+                    mediaTypes.add(fileRow);
+                }
+            }
+            this.mimeTypes.addAll(mediaTypes);
+            Collections.sort(this.mimeTypes);
+        } catch (Exception e) {
+            LOG.error("Error reading file MIMETypes from resources", e);
+        }
+    }
+
+    public List<String> getMimeTypes() {
+        LOG.debug("Returning loaded MIME types list");
+        return mimeTypes;
+    }
+}

Added: syncope/trunk/console/src/main/java/org/apache/syncope/console/init/PreviewPanelClassInitializer.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/init/PreviewPanelClassInitializer.java?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/init/PreviewPanelClassInitializer.java (added)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/init/PreviewPanelClassInitializer.java Mon Jun 30 13:32:34 2014
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+package org.apache.syncope.console.init;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.syncope.console.preview.BinaryPreview;
+import org.apache.syncope.console.preview.PreviewerClassScanner;
+import org.apache.syncope.console.wicket.markup.html.form.preview.AbstractBinaryPreviewer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class PreviewPanelClassInitializer {
+
+    /**
+     * Logger.
+     */
+    private static final Logger LOG = LoggerFactory.getLogger(PreviewPanelClassInitializer.class);
+
+    @Autowired
+    private PreviewerClassScanner classScanner;
+
+    private List<Class<? extends AbstractBinaryPreviewer>> classes;
+
+    public void load() {
+        classes = new ArrayList<Class<? extends AbstractBinaryPreviewer>>();
+        for (Class<? extends AbstractBinaryPreviewer> candidate : classScanner.getComponentClasses()) {
+            classes.add(candidate);
+        }
+    }
+
+    public List<Class<? extends AbstractBinaryPreviewer>> getClasses() {
+        LOG.debug("Returning loaded classes: {}", classes);
+        return classes;
+    }
+
+    public Class<? extends AbstractBinaryPreviewer> getClass(final String mimeType) {
+        LOG.debug("Searching for previewer class for MIME type: {}", mimeType);
+        Class<? extends AbstractBinaryPreviewer> previewer = null;
+        for (Class<? extends AbstractBinaryPreviewer> candidate : classes) {
+            LOG.debug("Evaluating previewer class {} for MIME type {}", candidate.getName(), mimeType);
+            if (Arrays.asList(candidate.getAnnotation(BinaryPreview.class).mimeTypes()).contains(mimeType)) {
+                LOG.debug("Found existing previewer for MIME type {}: {}", mimeType, candidate.getName());
+                previewer = candidate;
+            }
+        }
+        return previewer;
+    }
+}

Added: syncope/trunk/console/src/main/java/org/apache/syncope/console/init/SpringContextInitializer.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/init/SpringContextInitializer.java?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/init/SpringContextInitializer.java (added)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/init/SpringContextInitializer.java Mon Jun 30 13:32:34 2014
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.syncope.console.init;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Configurable;
+import org.springframework.stereotype.Component;
+
+/**
+ * Take care of all initializations needed by Syncope Console to run up and safe.
+ */
+@Component
+@Configurable
+public class SpringContextInitializer implements InitializingBean {
+
+    @Autowired
+    private PreviewPanelClassInitializer previewPanelClassInitializer;
+
+    @Autowired
+    private MIMETypesInitializer mimeTypesInitializer;
+
+    @Override
+    public void afterPropertiesSet() {
+        previewPanelClassInitializer.load();
+        mimeTypesInitializer.load();
+    }
+
+}

Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/AbstractBasePage.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/AbstractBasePage.java?rev=1606726&r1=1606725&r2=1606726&view=diff
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/AbstractBasePage.java (original)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/AbstractBasePage.java Mon Jun 30 13:32:34 2014
@@ -20,6 +20,7 @@ package org.apache.syncope.console.pages
 
 import org.apache.syncope.console.commons.Constants;
 import org.apache.syncope.console.commons.XMLRolesReader;
+import org.apache.syncope.console.init.MIMETypesInitializer;
 import org.apache.syncope.console.pages.panels.NotificationPanel;
 import org.apache.syncope.console.rest.ReportRestClient;
 import org.apache.syncope.console.rest.ResourceRestClient;
@@ -84,6 +85,9 @@ public class AbstractBasePage extends We
 
     @SpringBean
     protected ReportRestClient reportRestClient;
+    
+    @SpringBean
+    protected MIMETypesInitializer mimeTypesInitializer;
 
     protected NotificationPanel feedbackPanel;
 

Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/RoleModalPage.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/RoleModalPage.java?rev=1606726&r1=1606725&r2=1606726&view=diff
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/RoleModalPage.java (original)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/RoleModalPage.java Mon Jun 30 13:32:34 2014
@@ -81,6 +81,7 @@ public class RoleModalPage extends BaseM
         }
 
         final Form<RoleTO> form = new Form<RoleTO>("RoleForm");
+        form.setMultiPart(true);
 
         add(new Label("displayName", roleTO.getId() == 0 ? "" : roleTO.getDisplayName()));
 

Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/SchemaModalPage.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/SchemaModalPage.java?rev=1606726&r1=1606725&r2=1606726&view=diff
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/SchemaModalPage.java (original)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/SchemaModalPage.java Mon Jun 30 13:32:34 2014
@@ -141,7 +141,8 @@ public class SchemaModalPage extends Abs
         // -- binary
         final AjaxTextFieldPanel mimeType = new AjaxTextFieldPanel("mimeType",
                 getString("mimeType"), new PropertyModel<String>(schema, "mimeType"));
-
+        mimeType.setChoices(mimeTypesInitializer.getMimeTypes());
+        
         final WebMarkupContainer binaryParams = new WebMarkupContainer("binaryParams");
         binaryParams.setOutputMarkupPlaceholderTag(true);
         binaryParams.add(mimeType);

Added: syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/BinaryPreview.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/BinaryPreview.java?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/BinaryPreview.java (added)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/BinaryPreview.java Mon Jun 30 13:32:34 2014
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.syncope.console.preview;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ ElementType.TYPE })
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface BinaryPreview {
+
+    public String[] mimeTypes() default {};
+
+}

Added: syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/PreviewUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/PreviewUtil.java?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/PreviewUtil.java (added)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/PreviewUtil.java Mon Jun 30 13:32:34 2014
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+package org.apache.syncope.console.preview;
+
+import java.lang.reflect.InvocationTargetException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.console.init.PreviewPanelClassInitializer;
+import org.apache.syncope.console.wicket.markup.html.form.preview.AbstractBinaryPreviewer;
+import org.apache.wicket.Component;
+import org.apache.wicket.util.crypt.Base64;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@org.springframework.stereotype.Component
+public class PreviewUtil {
+
+    /**
+     * Logger.
+     */
+    private static final Logger LOG = LoggerFactory.getLogger(PreviewUtil.class);
+
+    @Autowired
+    private PreviewPanelClassInitializer previewPanelClassInitializer;
+
+    public Component getPreviewer(final String mimeType, final String file) throws ClassNotFoundException,
+            NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
+
+        final Class<? extends AbstractBinaryPreviewer> previewer = StringUtils.isBlank(file)
+                ? null
+                : previewPanelClassInitializer.getClass(mimeType);
+
+        return previewer == null
+                ? null
+                : ((AbstractBinaryPreviewer) Class.forName(previewer.getName()).
+                getConstructor(String.class, String.class, byte[].class).newInstance(
+                        new Object[] { "previewer", mimeType, Base64.decodeBase64(file) })).preview();
+    }
+
+    public Component getPreviewer(final String mimeType, final byte[] file) throws ClassNotFoundException,
+            NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
+
+        final Class<? extends AbstractBinaryPreviewer> previewer = previewPanelClassInitializer.getClass(mimeType);
+
+        return previewer == null
+                ? null
+                : ((AbstractBinaryPreviewer) Class.forName(previewer.getName()).
+                getConstructor(String.class, String.class, byte[].class).newInstance(
+                        new Object[] { "previewer", mimeType, file })).preview();
+    }
+}

Added: syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/PreviewerClassScanner.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/PreviewerClassScanner.java?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/PreviewerClassScanner.java (added)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/preview/PreviewerClassScanner.java Mon Jun 30 13:32:34 2014
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+package org.apache.syncope.console.preview;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.syncope.console.wicket.markup.html.form.preview.AbstractBinaryPreviewer;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
+import org.springframework.core.type.filter.AnnotationTypeFilter;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ClassUtils;
+
+@Component
+public class PreviewerClassScanner extends ClassPathScanningCandidateComponentProvider {
+
+    private static final String BASE_PATH = "org.apache.syncope.console.wicket.markup.html.form";
+
+    public PreviewerClassScanner() {
+        super(false);
+        addIncludeFilter(new AnnotationTypeFilter(BinaryPreview.class));
+    }
+
+    @SuppressWarnings("unchecked")
+    public final List<Class<? extends AbstractBinaryPreviewer>> getComponentClasses() {
+        List<Class<? extends AbstractBinaryPreviewer>> classes =
+                new ArrayList<Class<? extends AbstractBinaryPreviewer>>();
+        for (BeanDefinition candidate : findCandidateComponents(BASE_PATH)) {
+            classes.add((Class<AbstractBinaryPreviewer>) ClassUtils.resolveClassName(candidate.getBeanClassName(),
+                    ClassUtils.getDefaultClassLoader()));
+        }
+        return classes;
+    }
+}

Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/AjaxTextFieldPanel.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/AjaxTextFieldPanel.java?rev=1606726&r1=1606725&r2=1606726&view=diff
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/AjaxTextFieldPanel.java (original)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/AjaxTextFieldPanel.java Mon Jun 30 13:32:34 2014
@@ -51,7 +51,7 @@ public class AjaxTextFieldPanel extends 
 
             @Override
             protected Iterator<String> getChoices(final String input) {
-                final Pattern pattern = Pattern.compile(Pattern.quote(input) + ".*", Pattern.CASE_INSENSITIVE);
+                final Pattern pattern = Pattern.compile(".*" + Pattern.quote(input) + ".*", Pattern.CASE_INSENSITIVE);
 
                 final List<String> result = new ArrayList<String>();
 

Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/BinaryFieldPanel.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/BinaryFieldPanel.java?rev=1606726&r1=1606725&r2=1606726&view=diff
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/BinaryFieldPanel.java (original)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/BinaryFieldPanel.java Mon Jun 30 13:32:34 2014
@@ -25,9 +25,13 @@ import org.apache.commons.lang3.StringUt
 import org.apache.syncope.common.SyncopeConstants;
 import org.apache.syncope.console.commons.Constants;
 import org.apache.syncope.console.commons.HttpResourceStream;
+import org.apache.syncope.console.preview.PreviewUtil;
+import org.apache.syncope.console.pages.BaseModalPage;
+import org.apache.wicket.Component;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
 import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink;
+import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.StatelessForm;
@@ -35,10 +39,12 @@ import org.apache.wicket.markup.html.for
 import org.apache.wicket.markup.html.form.upload.FileUpload;
 import org.apache.wicket.markup.html.form.upload.FileUploadField;
 import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.panel.Fragment;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;
 import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler;
 import org.apache.wicket.request.resource.ContentDisposition;
+import org.apache.wicket.spring.injection.annot.SpringBean;
 import org.apache.wicket.util.crypt.Base64;
 import org.apache.wicket.util.lang.Bytes;
 
@@ -48,16 +54,40 @@ public class BinaryFieldPanel extends Fi
 
     private final String mimeType;
 
+    private final WebMarkupContainer container;
+
+    private final Link<Void> downloadLink;
+
+    private final Form<?> uploadForm;
+
+    private final Fragment emptyFragment;
+
+    @SpringBean
+    private PreviewUtil previewUtil;
+
     public BinaryFieldPanel(final String id, final String name, final IModel<String> model, final String mimeType) {
         super(id, model);
         this.mimeType = mimeType;
 
+        uploadForm = new StatelessForm<Void>("uploadForm");
+        uploadForm.setMultiPart(true);
+        uploadForm.setMaxSize(Bytes.megabytes(4));
+        add(uploadForm);
+
+        container = new WebMarkupContainer("previewContainer");
+        container.setOutputMarkupId(true);
+
+        emptyFragment = new Fragment("panelPreview", "emptyFragment", container);
+        emptyFragment.setOutputMarkupId(true);
+        container.add(emptyFragment);
+        uploadForm.add(container);
+
         field = new TextField<String>("textField", model);
         add(field.setLabel(new Model<String>(name)).setOutputMarkupId(true));
 
-        add(new Label("preview", StringUtils.isBlank(mimeType) ? StringUtils.EMPTY : "(" + mimeType + ")"));
+        uploadForm.add(new Label("preview", StringUtils.isBlank(mimeType) ? StringUtils.EMPTY : "(" + mimeType + ")"));
 
-        Link<Void> downloadLink = new Link<Void>("downloadLink") {
+        downloadLink = new Link<Void>("downloadLink") {
 
             private static final long serialVersionUID = -4331619903296515985L;
 
@@ -75,19 +105,14 @@ public class BinaryFieldPanel extends Fi
                     error(getString(Constants.ERROR) + ": " + e.getMessage());
                 }
             }
-
         };
-        add(downloadLink);
-
-        Form<?> uploadForm = new StatelessForm<Void>("uploadForm");
-        uploadForm.setMultiPart(true);
-        uploadForm.setMaxSize(Bytes.megabytes(4));
-        add(uploadForm);
+        downloadLink.setOutputMarkupId(true);
+        uploadForm.add(downloadLink);
 
         @SuppressWarnings("unchecked")
         final FileUploadField fileUpload = new FileUploadField("fileUpload", new Model());
         fileUpload.setOutputMarkupId(true);
-        fileUpload.add(new AjaxFormSubmitBehavior(Constants.ON_BLUR) {
+        fileUpload.add(new AjaxFormSubmitBehavior(Constants.ON_CHANGE) {
 
             private static final long serialVersionUID = -1107858522700306810L;
 
@@ -96,16 +121,26 @@ public class BinaryFieldPanel extends Fi
                 final FileUpload uploadedFile = fileUpload.getFileUpload();
                 if (uploadedFile != null) {
                     try {
+                        final byte[] uploadedBytes = uploadedFile.getBytes();
                         final String uploaded = new String(
-                                Base64.encodeBase64(uploadedFile.getBytes()),
+                                Base64.encodeBase64(uploadedBytes),
                                 SyncopeConstants.DEFAULT_ENCODING);
                         field.setModelObject(uploaded);
                         target.add(field);
 
+                        final Component panelPreview = previewUtil.getPreviewer(mimeType, uploadedBytes);
+
+                        if (panelPreview != null) {
+                            changePreviewer(panelPreview);
+                        }
+
                         fileUpload.setModelObject(null);
-                        target.add(fileUpload);
+                        uploadForm.addOrReplace(fileUpload);
+                        downloadLink.setEnabled(StringUtils.isNotBlank(uploaded));
+                        target.add(uploadForm);
                     } catch (Exception e) {
                         error(getString(Constants.ERROR) + ": " + e.getMessage());
+                        ((BaseModalPage) getPage()).getFeedbackPanel().refresh(target);
                         LOG.error("While saving uploaded file", e);
                     }
                 }
@@ -122,7 +157,7 @@ public class BinaryFieldPanel extends Fi
             public void onClick(final AjaxRequestTarget target) {
             }
         };
-        add(uploadLink);
+        uploadForm.add(uploadLink);
 
         IndicatingAjaxLink<Void> resetLink = new IndicatingAjaxLink<Void>("resetLink") {
 
@@ -132,9 +167,13 @@ public class BinaryFieldPanel extends Fi
             public void onClick(final AjaxRequestTarget target) {
                 field.setModelObject(null);
                 target.add(field);
+                downloadLink.setEnabled(false);
+                container.addOrReplace(emptyFragment);
+                uploadForm.addOrReplace(container);
+                target.add(uploadForm);
             }
         };
-        add(resetLink);
+        uploadForm.add(resetLink);
     }
 
     private Response buildResponse() {
@@ -142,9 +181,31 @@ public class BinaryFieldPanel extends Fi
                 type(StringUtils.isBlank(mimeType) ? MediaType.APPLICATION_OCTET_STREAM : mimeType).build();
     }
 
+    private void changePreviewer(final Component panelPreview) {
+        final Fragment fragment = new Fragment("panelPreview", "previewFragment", container);
+        fragment.add(panelPreview);
+        container.addOrReplace(fragment);
+        uploadForm.addOrReplace(container);
+    }
+
     @Override
     public BinaryFieldPanel clone() {
         return (BinaryFieldPanel) super.clone();
     }
 
+    @Override
+    public FieldPanel<String> setNewModel(final IModel<String> model) {
+        field.setModel(model);
+        try {
+            final Component panelPreview = previewUtil.getPreviewer(mimeType, model.getObject());
+            if (panelPreview != null) {
+                changePreviewer(panelPreview);
+            }
+        } catch (Exception e) {
+            LOG.error("While loading saved file", e);
+        }
+        downloadLink.setEnabled(StringUtils.isNotBlank(model.getObject()));
+        uploadForm.addOrReplace(downloadLink);
+        return this;
+    }
 }

Added: syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.java?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.java (added)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.java Mon Jun 30 13:32:34 2014
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+package org.apache.syncope.console.wicket.markup.html.form.preview;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class AbstractBinaryPreviewer extends Panel {
+
+    /**
+     * Logger.
+     */
+    protected static final Logger LOG = LoggerFactory.getLogger(AbstractBinaryPreviewer.class);
+
+    private static final long serialVersionUID = -2482706463911903025L;
+
+    protected final String mimeType;
+
+    protected final byte[] uploadedBytes;
+
+    public AbstractBinaryPreviewer(final String id, final String mimeType, final byte[] uploadedBytes) {
+        super(id);
+        this.mimeType = mimeType;
+        this.uploadedBytes = uploadedBytes;
+    }
+
+    public abstract Component preview();
+}

Added: syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryCertPreviewer.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryCertPreviewer.java?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryCertPreviewer.java (added)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryCertPreviewer.java Mon Jun 30 13:32:34 2014
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+package org.apache.syncope.console.wicket.markup.html.form.preview;
+
+import org.apache.syncope.console.preview.BinaryPreview;
+import java.io.ByteArrayInputStream;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import javax.naming.ldap.LdapName;
+import javax.naming.ldap.Rdn;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.util.io.IOUtils;
+
+@BinaryPreview(mimeTypes = { "application/x-x509-ca-cert", "application/x-x509-user-cert", "application/pkix-cert" })
+public class BinaryCertPreviewer extends AbstractBinaryPreviewer {
+
+    private static final long serialVersionUID = -5843835939538055110L;
+
+    public BinaryCertPreviewer(final String id, final String mimeType, final byte[] uploadedBytes) {
+        super(id, mimeType, uploadedBytes);
+    }
+
+    @Override
+    public Component preview() {
+        final Label commonNameLabel = new Label("certCommonName", new Model<String>());
+        final ByteArrayInputStream certificateStream = new ByteArrayInputStream(uploadedBytes);
+        try {
+            final X509Certificate certificate = (X509Certificate) CertificateFactory.getInstance("X.509").
+                    generateCertificate(certificateStream);
+
+            final StringBuilder commonNameBuilder = new StringBuilder("cn=");
+
+            final LdapName ldapName = new LdapName(certificate.getIssuerDN().getName());
+
+            for (Rdn rdn : ldapName.getRdns()) {
+                if ("CN".equalsIgnoreCase(rdn.getType())) {
+                    commonNameBuilder.append(rdn.getValue() == null
+                            ? StringUtils.EMPTY
+                            : rdn.getValue().toString());
+                }
+            }
+            commonNameLabel.setDefaultModelObject(commonNameBuilder.toString());
+        } catch (Exception e) {
+            LOG.error("Error evaluating certificate file", e);
+            throw new IllegalArgumentException("Error evaluating certificate file", e);
+        } finally {
+            IOUtils.closeQuietly(certificateStream);
+        }
+        return this.add(commonNameLabel);
+    }
+}

Added: syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryImagePreviewer.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryImagePreviewer.java?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryImagePreviewer.java (added)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryImagePreviewer.java Mon Jun 30 13:32:34 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+package org.apache.syncope.console.wicket.markup.html.form.preview;
+
+import org.apache.syncope.console.preview.BinaryPreview;
+import org.apache.wicket.Component;
+import org.apache.wicket.extensions.markup.html.image.resource.ThumbnailImageResource;
+import org.apache.wicket.markup.html.image.NonCachingImage;
+import org.apache.wicket.request.resource.DynamicImageResource;
+import org.apache.wicket.request.resource.IResource;
+
+@BinaryPreview(mimeTypes = { "image/jpeg", "image/png", "image/gif", "image/bmp", "image/x-png", "image/vnd.wap.wbmp" })
+public class BinaryImagePreviewer extends AbstractBinaryPreviewer {
+
+    private static final long serialVersionUID = 3338812359368457349L;
+
+    private static final int IMG_SIZE = 230;
+
+    public BinaryImagePreviewer(final String id, final String mimeType, final byte[] uploadedBytes) {
+        super(id, mimeType, uploadedBytes);
+    }
+
+    @Override
+    public Component preview() {
+        return this.add(new NonCachingImage("previewImage", new ThumbnailImageResource(new DynamicImageResource() {
+
+            private static final long serialVersionUID = 923201517955737928L;
+
+            @Override
+            protected byte[] getImageData(final IResource.Attributes attributes) {
+                return uploadedBytes;
+            }
+        }, IMG_SIZE)));
+    }
+}

Added: syncope/trunk/console/src/main/resources/MIMETypes
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/resources/MIMETypes?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/resources/MIMETypes (added)
+++ syncope/trunk/console/src/main/resources/MIMETypes Mon Jun 30 13:32:34 2014
@@ -0,0 +1,671 @@
+# 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.
+
+x-world/x-3dmf
+x-world/x-3dmf
+application/octet-stream
+application/x-authorware-bin
+application/x-authorware-map
+application/x-authorware-seg
+text/vnd.abc
+text/html
+video/animaflex
+application/postscript
+audio/aiff
+audio/x-aiff
+audio/aiff
+audio/x-aiff
+audio/aiff
+audio/x-aiff
+application/x-aim
+text/x-audiosoft-intra
+application/x-navi-animation
+application/x-nokia-9000-communicator-add-on-software
+application/mime
+application/octet-stream
+application/arj
+application/octet-stream
+image/x-jg
+video/x-ms-asf
+text/x-asm
+text/asp
+application/x-mplayer2
+video/x-ms-asf
+video/x-ms-asf-plugin
+audio/basic
+audio/x-au
+application/x-troff-msvideo
+video/avi
+video/msvideo
+video/x-msvideo
+video/avs-video
+application/x-bcpio
+application/mac-binary
+application/macbinary
+application/octet-stream
+application/x-binary
+application/x-macbinary
+image/bmp
+image/bmp
+image/x-windows-bmp
+application/book
+application/book
+application/x-bzip2
+application/x-bsh
+application/x-bzip
+application/x-bzip2
+text/plain
+text/x-c
+text/plain
+application/vnd.ms-pki.seccat
+text/plain
+text/x-c
+application/clariscad
+application/x-cocoa
+application/cdf
+application/x-cdf
+application/x-netcdf
+application/pkix-cert
+application/x-x509-ca-cert
+application/x-chat
+application/x-chat
+application/java
+application/java-byte-code
+application/x-java-class
+application/octet-stream
+text/plain
+text/plain
+application/x-cpio
+text/x-c
+application/mac-compactpro
+application/x-compactpro
+application/x-cpt
+application/pkcs-crl
+application/pkix-crl
+application/pkix-cert
+application/x-x509-ca-cert
+application/x-x509-user-cert
+application/x-csh
+text/x-script.csh
+application/x-pointplus
+text/css
+text/plain
+application/x-director
+application/x-deepv
+text/plain
+application/x-x509-ca-cert
+video/x-dv
+application/x-director
+video/dl
+video/x-dl
+application/msword
+application/msword
+application/commonground
+application/drafting
+application/octet-stream
+video/x-dv
+application/x-dvi
+drawing/x-dwf (old)
+model/vnd.dwf
+application/acad
+image/vnd.dwg
+image/x-dwg
+application/dxf
+image/vnd.dwg
+image/x-dwg
+application/x-director
+text/x-script.elisp
+application/x-bytecode.elisp (compiled elisp)
+application/x-elc
+application/x-envoy
+application/postscript
+application/x-esrehber
+text/x-setext
+application/envoy
+application/x-envoy
+application/octet-stream
+text/plain
+text/x-fortran
+text/x-fortran
+text/plain
+text/x-fortran
+application/vnd.fdf
+application/fractals
+image/fif
+video/fli
+video/x-fli
+image/florian
+text/vnd.fmi.flexstor
+video/x-atomic3d-feature
+text/plain
+text/x-fortran
+image/vnd.fpx
+image/vnd.net-fpx
+application/freeloader
+audio/make
+text/plain
+image/g3fax
+image/gif
+video/gl
+video/x-gl
+audio/x-gsm
+audio/x-gsm
+application/x-gsp
+application/x-gss
+application/x-gtar
+application/x-compressed
+application/x-gzip
+application/x-gzip
+multipart/x-gzip
+text/plain
+text/x-h
+application/x-hdf
+application/x-helpfile
+application/vnd.hp-hpgl
+text/plain
+text/x-h
+text/x-script
+application/hlp
+application/x-helpfile
+application/x-winhelp
+application/vnd.hp-hpgl
+application/vnd.hp-hpgl
+application/binhex
+application/binhex4
+application/mac-binhex
+application/mac-binhex40
+application/x-binhex40
+application/x-mac-binhex40
+application/hta
+text/x-component
+text/html
+text/html
+text/html
+text/webviewhtml
+text/html
+x-conference/x-cooltalk
+image/x-icon
+text/plain
+image/ief
+image/ief
+application/iges
+model/iges
+application/iges
+model/iges
+application/x-ima
+application/x-httpd-imap
+application/inf
+application/x-internett-signup
+application/x-ip2
+video/x-isvideo
+audio/it
+application/x-inventor
+i-world/i-vrml
+application/x-livescreen
+audio/x-jam
+text/plain
+text/x-java-source
+text/plain
+text/x-java-source
+application/x-java-commerce
+image/jpeg
+image/pjpeg
+image/jpeg
+image/jpeg
+image/pjpeg
+image/jpeg
+image/pjpeg
+image/jpeg
+image/pjpeg
+image/x-jps
+application/x-javascript
+application/javascript
+application/ecmascript
+text/javascript
+text/ecmascript
+image/jutvision
+audio/midi
+music/x-karaoke
+application/x-ksh
+text/x-script.ksh
+audio/nspaudio
+audio/x-nspaudio
+audio/x-liveaudio
+application/x-latex
+application/lha
+application/octet-stream
+application/x-lha
+application/octet-stream
+text/plain
+audio/nspaudio
+audio/x-nspaudio
+text/plain
+application/x-lisp
+text/x-script.lisp
+text/plain
+text/x-la-asf
+application/x-latex
+application/octet-stream
+application/x-lzh
+application/lzx
+application/octet-stream
+application/x-lzx
+text/plain
+text/x-m
+video/mpeg
+audio/mpeg
+video/mpeg
+audio/x-mpequrl
+application/x-troff-man
+application/x-navimap
+text/plain
+application/mbedlet
+application/x-magic-cap-package-1.0
+application/mcad
+application/x-mathcad
+image/vasa
+text/mcf
+application/netmc
+application/x-troff-me
+message/rfc822
+message/rfc822
+application/x-midi
+audio/midi
+audio/x-mid
+audio/x-midi
+music/crescendo
+x-music/x-midi
+application/x-midi
+audio/midi
+audio/x-mid
+audio/x-midi
+music/crescendo
+x-music/x-midi
+application/x-frame
+application/x-mif
+message/rfc822
+www/mime
+audio/x-vnd.audioexplosion.mjuicemediafile
+video/x-motion-jpeg
+application/base64
+application/x-meme
+application/base64
+audio/mod
+audio/x-mod
+video/quicktime
+video/quicktime
+video/x-sgi-movie
+audio/mpeg
+audio/x-mpeg
+video/mpeg
+video/x-mpeg
+video/x-mpeq2a
+audio/mpeg3
+audio/x-mpeg-3
+video/mpeg
+video/x-mpeg
+audio/mpeg
+video/mpeg
+application/x-project
+video/mpeg
+video/mpeg
+audio/mpeg
+video/mpeg
+audio/mpeg
+application/vnd.ms-project
+application/x-project
+application/x-project
+application/x-project
+application/marc
+application/x-troff-ms
+video/x-sgi-movie
+audio/make
+application/x-vnd.audioexplosion.mzz
+image/naplps
+image/naplps
+application/x-netcdf
+application/vnd.nokia.configuration-message
+image/x-niff
+image/x-niff
+application/x-mix-transfer
+application/x-conference
+application/x-navidoc
+application/octet-stream
+application/oda
+application/x-omc
+application/x-omcdatamaker
+application/x-omcregerator
+text/x-pascal
+application/pkcs10
+application/x-pkcs10
+application/pkcs-12
+application/x-pkcs12
+application/x-pkcs7-signature
+application/pkcs7-mime
+application/x-pkcs7-mime
+application/pkcs7-mime
+application/x-pkcs7-mime
+application/x-pkcs7-certreqresp
+application/pkcs7-signature
+application/pro_eng
+text/pascal
+image/x-portable-bitmap
+application/vnd.hp-pcl
+application/x-pcl
+image/x-pict
+image/x-pcx
+chemical/x-pdb
+application/pdf
+audio/make
+audio/make.my.funk
+image/x-portable-graymap
+image/x-portable-greymap
+image/pict
+image/pict
+application/x-newton-compatible-pkg
+application/vnd.ms-pki.pko
+text/plain
+text/x-script.perl
+application/x-pixclscript
+image/x-xpixmap
+text/x-script.perl-module
+application/x-pagemaker
+application/x-pagemaker
+image/png
+application/x-portable-anymap
+image/x-portable-anymap
+application/mspowerpoint
+application/vnd.ms-powerpoint
+model/x-pov
+application/vnd.ms-powerpoint
+image/x-portable-pixmap
+application/mspowerpoint
+application/vnd.ms-powerpoint
+application/mspowerpoint
+application/powerpoint
+application/vnd.ms-powerpoint
+application/x-mspowerpoint
+application/mspowerpoint
+application/x-freelance
+application/pro_eng
+application/postscript
+application/octet-stream
+paleovu/x-pv
+application/vnd.ms-powerpoint
+text/x-script.phyton
+applicaiton/x-bytecode.python
+audio/vnd.qcelp
+x-world/x-3dmf
+x-world/x-3dmf
+image/x-quicktime
+video/quicktime
+video/x-qtc
+image/x-quicktime
+image/x-quicktime
+audio/x-pn-realaudio
+audio/x-pn-realaudio-plugin
+audio/x-realaudio
+audio/x-pn-realaudio
+application/x-cmu-raster
+image/cmu-raster
+image/x-cmu-raster
+image/cmu-raster
+text/x-script.rexx
+image/vnd.rn-realflash
+image/x-rgb
+application/vnd.rn-realmedia
+audio/x-pn-realaudio
+audio/mid
+audio/x-pn-realaudio
+audio/x-pn-realaudio
+audio/x-pn-realaudio-plugin
+application/ringing-tones
+application/vnd.nokia.ringing-tone
+application/vnd.rn-realplayer
+application/x-troff
+image/vnd.rn-realpix
+audio/x-pn-realaudio-plugin
+text/richtext
+text/vnd.rn-realtext
+application/rtf
+application/x-rtf
+text/richtext
+application/rtf
+text/richtext
+video/vnd.rn-realvideo
+text/x-asm
+audio/s3m
+application/octet-stream
+application/x-tbook
+application/x-lotusscreencam
+text/x-script.guile
+text/x-script.scheme
+video/x-scm
+text/plain
+application/sdp
+application/x-sdp
+application/sounder
+application/sea
+application/x-sea
+application/set
+text/sgml
+text/x-sgml
+text/sgml
+text/x-sgml
+application/x-bsh
+application/x-sh
+application/x-shar
+text/x-script.sh
+application/x-bsh
+application/x-shar
+text/html
+text/x-server-parsed-html
+audio/x-psid
+application/x-sit
+application/x-stuffit
+application/x-koan
+application/x-koan
+application/x-koan
+application/x-koan
+application/x-seelogo
+application/smil
+application/smil
+audio/basic
+audio/x-adpcm
+application/solids
+application/x-pkcs7-certificates
+text/x-speech
+application/futuresplash
+application/x-sprite
+application/x-sprite
+application/x-wais-source
+text/x-server-parsed-html
+application/streamingmedia
+application/vnd.ms-pki.certstore
+application/step
+application/sla
+application/vnd.ms-pki.stl
+application/x-navistyle
+application/step
+application/x-sv4cpio
+application/x-sv4crc
+image/vnd.dwg
+image/x-dwg
+application/x-world
+x-world/x-svr
+application/x-shockwave-flash
+application/x-troff
+text/x-speech
+application/x-tar
+application/toolbook
+application/x-tbook
+application/x-tcl
+text/x-script.tcl
+text/x-script.tcsh
+application/x-tex
+application/x-texinfo
+application/x-texinfo
+application/plain
+text/plain
+application/gnutar
+application/x-compressed
+image/tiff
+image/x-tiff
+image/tiff
+image/x-tiff
+application/x-troff
+audio/tsp-audio
+application/dsptype
+audio/tsplayer
+text/tab-separated-values
+image/florian
+text/plain
+text/x-uil
+text/uri-list
+text/uri-list
+application/i-deas
+text/uri-list
+text/uri-list
+application/x-ustar
+multipart/x-ustar
+application/octet-stream
+text/x-uuencode
+text/x-uuencode
+application/x-cdlink
+text/x-vcalendar
+application/vda
+video/vdo
+application/groupwise
+video/vivo
+video/vnd.vivo
+video/vivo
+video/vnd.vivo
+application/vocaltec-media-desc
+application/vocaltec-media-file
+audio/voc
+audio/x-voc
+video/vosaic
+audio/voxware
+audio/x-twinvq-plugin
+audio/x-twinvq
+audio/x-twinvq-plugin
+application/x-vrml
+model/vrml
+x-world/x-vrml
+x-world/x-vrt
+application/x-visio
+application/x-visio
+application/x-visio
+application/wordperfect6.0
+application/wordperfect6.1
+application/msword
+audio/wav
+audio/x-wav
+application/x-qpro
+image/vnd.wap.wbmp
+application/vnd.xara
+application/msword
+application/x-123
+windows/metafile
+text/vnd.wap.wml
+application/vnd.wap.wmlc
+text/vnd.wap.wmlscript
+application/vnd.wap.wmlscriptc
+application/msword
+application/wordperfect
+application/wordperfect
+application/wordperfect6.0
+application/wordperfect
+application/wordperfect
+application/x-wpwin
+application/x-lotus
+application/mswrite
+application/x-wri
+application/x-world
+model/vrml
+x-world/x-vrml
+model/vrml
+x-world/x-vrml
+text/scriplet
+application/x-wais-source
+application/x-wintalk
+image/x-xbitmap
+image/x-xbm
+image/xbm
+video/x-amt-demorun
+xgl/drawing
+image/vnd.xiff
+application/excel
+application/excel
+application/x-excel
+application/x-msexcel
+application/excel
+application/vnd.ms-excel
+application/x-excel
+application/excel
+application/vnd.ms-excel
+application/x-excel
+application/excel
+application/x-excel
+application/excel
+application/x-excel
+application/excel
+application/vnd.ms-excel
+application/x-excel
+application/excel
+application/vnd.ms-excel
+application/x-excel
+application/excel
+application/vnd.ms-excel
+application/x-excel
+application/x-msexcel
+application/excel
+application/x-excel
+application/excel
+application/x-excel
+application/excel
+application/vnd.ms-excel
+application/x-excel
+application/x-msexcel
+audio/xm
+application/xml
+text/xml
+xgl/movie
+application/x-vnd.ls-xpix
+image/x-xpixmap
+image/xpm
+image/png
+video/x-amt-showrun
+image/x-xwd
+image/x-xwindowdump
+chemical/x-pdb
+application/x-compress
+application/x-compressed
+application/x-compressed
+application/x-zip-compressed
+application/zip
+multipart/x-zip
+application/octet-stream
+text/x-script.zsh
+application/vnd.oasis.opendocument.text
+application/vnd.oasis.opendocument.graphics
+application/vnd.oasis.opendocument.presentation
+application/vnd.oasis.opendocument.spreadsheet
+application/vnd.oasis.opendocument.chart
+application/vnd.oasis.opendocument.formula
+application/vnd.oasis.opendocument.database
+application/vnd.oasis.opendocument.image
\ No newline at end of file

Modified: syncope/trunk/console/src/main/resources/applicationContext.xml
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/resources/applicationContext.xml?rev=1606726&r1=1606725&r2=1606726&view=diff
==============================================================================
--- syncope/trunk/console/src/main/resources/applicationContext.xml (original)
+++ syncope/trunk/console/src/main/resources/applicationContext.xml Mon Jun 30 13:32:34 2014
@@ -29,6 +29,8 @@ under the License.
                            http://cxf.apache.org/schemas/core.xsd">
 
   <context:component-scan base-package="org.apache.syncope.console.rest"/>
+  <context:component-scan base-package="org.apache.syncope.console.init"/>
+  <context:component-scan base-package="org.apache.syncope.console.preview"/>
 
   <bean id="systemPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="order" value="1"/>

Modified: syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/BinaryFieldPanel.html
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/BinaryFieldPanel.html?rev=1606726&r1=1606725&r2=1606726&view=diff
==============================================================================
--- syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/BinaryFieldPanel.html (original)
+++ syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/BinaryFieldPanel.html Mon Jun 30 13:32:34 2014
@@ -21,16 +21,24 @@ under the License.
     <input style="display: none;" wicket:id="textField"/>
     <span style="margin-right: 20px;">
       <div style="display: table-cell;">
-        <form wicket:id="uploadForm">
+        <form wicket:id="uploadForm" encType="multipart/form-data" method="post" accept-charset="UTF-8">
           <input wicket:id="fileUpload" type="file"/>
+          <div style="top: -25px; left: 100%; position: relative; vertical-align: middle;">
+            <a href="#" wicket:id="uploadLink"><img src="img/file-upload.png" alt="upload" title="upload" style="vertical-align: middle;"/></a>
+            <a href="#" wicket:id="downloadLink"><img src="img/file-download.png" alt="download" title="download" style="vertical-align: middle;"/></a>
+            <a href="#" wicket:id="resetLink"><img src="img/disable.png" alt="disable" title="remove value" style="vertical-align: middle;"/></a>
+            <span wicket:id="preview"/>
+          </div>
+          <span wicket:id="previewContainer">
+            <span wicket:id="panelPreview">[panelPreview]</span>
+            <wicket:fragment wicket:id="previewFragment">
+              <div wicket:id = "previewer" class="ui-widget-content ui-corner-all"></div>
+            </wicket:fragment>
+            <wicket:fragment wicket:id="emptyFragment">
+            </wicket:fragment>
+          </span>
         </form>
       </div>
-      <div style="display: table-cell; vertical-align: middle;">
-        <a href="#" wicket:id="uploadLink"><img src="img/up-icon.png" alt="upload" title="upload" style="vertical-align: middle;"/></a>
-        <a href="#" wicket:id="downloadLink"><img src="img/down-icon.png" alt="download" title="download" style="vertical-align: middle;"/></a>
-        <a href="#" wicket:id="resetLink"><img src="img/disable.png" alt="disable" title="remove value" style="vertical-align: middle;"/></a>
-        <span wicket:id="preview"/>
-      </div>
     </span>
   </wicket:extend>
 </html>

Added: syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.html
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.html?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.html (added)
+++ syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.html Mon Jun 30 13:32:34 2014
@@ -0,0 +1,24 @@
+<!--
+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.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+  <wicket:head></wicket:head>
+  <wicket:panel>
+    <wicket:child />
+  </wicket:panel>
+</html>

Added: syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryCertPreviewer.html
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryCertPreviewer.html?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryCertPreviewer.html (added)
+++ syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryCertPreviewer.html Mon Jun 30 13:32:34 2014
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<!--
+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.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+  <wicket:extend>
+    <div wicket:id = "certCommonName">[certCommonName]</div>
+  </wicket:extend>
+</html>

Added: syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryImagePreviewer.html
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryImagePreviewer.html?rev=1606726&view=auto
==============================================================================
--- syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryImagePreviewer.html (added)
+++ syncope/trunk/console/src/main/resources/org/apache/syncope/console/wicket/markup/html/form/preview/BinaryImagePreviewer.html Mon Jun 30 13:32:34 2014
@@ -0,0 +1,23 @@
+<!--
+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.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+  <wicket:extend>
+    <div><img wicket:id = "previewImage"/></div>
+  </wicket:extend>
+</html>

Added: syncope/trunk/console/src/main/webapp/img/file-download.png
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/webapp/img/file-download.png?rev=1606726&view=auto
==============================================================================
Binary file - no diff available.

Propchange: syncope/trunk/console/src/main/webapp/img/file-download.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: syncope/trunk/console/src/main/webapp/img/file-upload.png
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/webapp/img/file-upload.png?rev=1606726&view=auto
==============================================================================
Binary file - no diff available.

Propchange: syncope/trunk/console/src/main/webapp/img/file-upload.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: syncope/trunk/core/src/test/resources/content.xml
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/resources/content.xml?rev=1606726&r1=1606725&r2=1606726&view=diff
==============================================================================
--- syncope/trunk/core/src/test/resources/content.xml (original)
+++ syncope/trunk/core/src/test/resources/content.xml Mon Jun 30 13:32:34 2014
@@ -215,7 +215,7 @@ under the License.
            secretKey="7abcdefghilmnopqrstuvz9#" cipherAlgorithm="SHA"/>
   <USchema name="photo" type="Binary"
            mandatoryCondition="false" multivalue="0" uniqueConstraint="0" readonly="0"
-           mimeType="application/jpg"/>
+           mimeType="image/jpeg"/>
 
   <UDerSchema name="csvuserid" expression="firstname + ',' + surname"/>
   <UDerSchema name="cn" expression="surname + ', ' + firstname"/>