Skip to main content
summaryrefslogtreecommitdiffstats
blob: c25c8a82079a41e83d7da2e1e89165ccab8bac05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*******************************************************************************
 * Copyright (c) 2010, 2019 IBM Corporation and others.
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.validation.internal.strategy;

import java.util.Locale;

import org.eclipse.core.resources.IResource;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.jst.jsf.common.dom.TagIdentifier;
import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
import org.eclipse.jst.jsf.validation.internal.appconfig.ILocalizedMessage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;

/**
 * Diagnostic factory for JSF views 
 *
 */
public final class DiagnosticFactory {
	
    /**
     * The id used in the source field of all Diagnostic's created by this factory
     * to uniquely identify tag validation as their source type.
     */
    public final static String SOURCE_ID = "org.eclipse.jst.jsf.validation.tag.Diagnostics";//$NON-NLS-1$

    /**
     * Problem id
     */
    public final static int CONTAINMENT_ERROR_MISSING_VIEW = 1;
    
    /**
     * Problem id
     */
    public final static int CONTAINMENT_ERROR_MISSING_FORM = 2;

    /**
     * Problem id
     */
	public static final int CONTAINMENT_ERROR_MISSING_ANCESTOR = 3;
    

    /**
     * @param tagName 
     * @return message indicating a JSF view tag is missing as an ancestor     
     */
    public static Diagnostic create_CONTAINMENT_ERROR_MISSING_VIEW(final String tagName)
    {
    	return create(CONTAINMENT_ERROR_MISSING_VIEW,
    			NLS.bind(Messages.CONTAINMENT_ERROR_MISSING_VIEW, tagName));                
    }
    
    /**
     * @param tagName 
     * @return message indicating a JSF form tag is missing as an ancestor     
     */
    public static Diagnostic create_CONTAINMENT_ERROR_MISSING_FORM(final String tagName)
    {    	
        return create(CONTAINMENT_ERROR_MISSING_FORM,
               NLS.bind(Messages.CONTAINMENT_ERROR_MISSING_FORM, tagName));
    }
    
    /**  
     * @param tagName 
     * @param missingTag 
     * @return message indicating some tag is missing as an ancestor     
     */
    public static Diagnostic create_CONTAINMENT_ERROR_MISSING_ANCESTOR(final String tagName, final TagIdentifier missingTag)
    {
    	
        return create(CONTAINMENT_ERROR_MISSING_ANCESTOR,
        		NLS.bind(Messages.CONTAINMENT_ERROR_MISSING_ANCESTOR, 
        				new Object[]{ tagName, missingTag.getUri(), missingTag.getTagName()}));
    }

    private static BasicDiagnostic create(final int diagnosticId, final String message)
    {
        final int severity = IMessage.NORMAL_SEVERITY;//ELValidationPreferences.getDefaultSeverity(diagnosticId);
        return new BasicDiagnostic(severity, SOURCE_ID 
                , diagnosticId
                , message
                , null);
    }
	/**
     * Customized localizable message for view validation
     * @author cbateman
     *
     */
    static class MyLocalizedMessage extends Message implements ILocalizedMessage
    {
        private final String _message;
        private final int    _errorCode;

        /**
         * @param severity
         * @param messageText
         * @param targetObject
         * @param errorCode 
         */
        public MyLocalizedMessage(int severity, String messageText, IResource targetObject, int errorCode) {
            this(severity, messageText, (Object) targetObject, errorCode);
        }

        /**
         * @param severity
         * @param messageText
         * @param targetObject
         * @param errorCode 
         */
        private MyLocalizedMessage(int severity, String messageText, Object targetObject, int errorCode) {
            super(JSFCorePlugin.getDefault().getBundle().getSymbolicName(), severity, 
                    messageText);
            _message = messageText;
            setTargetObject(targetObject);
            _errorCode = errorCode;
        }

        /**
         * @return the localized message
         */
        public String getLocalizedMessage() {
            return _message;
        }

        /**
         * @see org.eclipse.wst.validation.internal.core.Message#getText()
         */
        public String getText() {
            return getLocalizedMessage();
        }

        /**
         * @see org.eclipse.wst.validation.internal.core.Message#getText(java.lang.ClassLoader)
         */
        public String getText(ClassLoader cl) {
            return getLocalizedMessage();
        }

        /**
         * @see org.eclipse.wst.validation.internal.core.Message#getText(java.util.Locale)
         */
        public String getText(Locale l) {
            return getLocalizedMessage();
        }

        public String getText(Locale l, ClassLoader cl) {
            return getLocalizedMessage();
        }

        /**
         * @return the error code related to this message
         */
        public int getErrorCode() {
            return _errorCode;
        }


        /**
         * @param offset
         * @return true if this message applies to document offset
         */
        public boolean appliesTo(int offset)
        {
            return (offset >= getOffset() && offset < getOffset()+getLength());
        }
    }


}

Back to the top