Skip to main content
summaryrefslogtreecommitdiffstats
blob: b47c1d1844fff4a6e7fc1191e7aa4dc19cd11cbd (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
182
183
184
185
186
187
188
189
190
191
192
/*******************************************************************************
 * Copyright (c) 2002-2005 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsi.internal.core.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.eclipse.wst.wsi.internal.core.ToolInfo;
import org.eclipse.wst.wsi.internal.core.WSIConstants;
import org.eclipse.wst.wsi.internal.core.common.AddStyleSheet;
import org.eclipse.wst.wsi.internal.core.xml.XMLUtils;
import org.w3c.dom.Element;

/**
 * Test Utility class.
 * 
 * @version 1.0.1
 * @author Peter Brittenham  (peterbr@us.ibm.com)
 */
public final class TestUtils
{
  /**
   * Format a style sheet declaration from the addStyleSheet element.
   * @param element an Element object.
   * @param addStyleSheet an addStyleSheet element.
   * @param defaultHref default href.
   */
  public static final void parseAddStyleSheet(
    Element element,
    AddStyleSheet addStyleSheet,
    String defaultHref)
  {
    addStyleSheet.setHref(
      XMLUtils.getAttributeValue(element, WSIConstants.ATTR_HREF, defaultHref));
    addStyleSheet.setType(
      XMLUtils.getAttributeValue(
        element,
        WSIConstants.ATTR_TYPE,
        WSIConstants.DEFAULT_XSL_TYPE));
    addStyleSheet.setTitle(
      XMLUtils.getAttributeValue(element, WSIConstants.ATTR_TITLE));
    addStyleSheet.setMedia(
      XMLUtils.getAttributeValue(element, WSIConstants.ATTR_MEDIA));
    addStyleSheet.setCharset(
      XMLUtils.getAttributeValue(element, WSIConstants.ATTR_CHARSET));
    addStyleSheet.setAlternate(
      XMLUtils.getAttributeValue(element, WSIConstants.ATTR_ALTERNATE));
  }

  /**
   * Display tool name and copyright notice.
   * @param toolInfo a ToolInfo object.
   */
  public static void printToolInfo(ToolInfo toolInfo)
  {
    System.out.println(
      "Conformance "
        + toolInfo.getName()
        + " Tool"
        + ", Version: "
        + toolInfo.getVersion()
        + ", Release Date: "
        + toolInfo.getReleaseDate());
    // System.out.println(WSIConstants.COPYRIGHT);
    // System.out.println(" ");
  }

  /** 
   * Get XML comment used in log and report file.
   * @return XML comment used in log and report file.
   */
  public static String getXMLComment()
  {
    String comment = null;
    String readLine = null;

    try
    {
      // Add required comments (copyright, etc.)
      BufferedReader bufferedReader =
        new BufferedReader(
          new InputStreamReader(
            Utils.getInputStream(WSIConstants.COMMENTS_FILE)));

      // Initialize string to empty string
      comment = "";

      while (bufferedReader.ready())
      {
        if ((readLine = bufferedReader.readLine()) != null)
          comment += readLine + WSIConstants.LINE_SEPARATOR;
      }
    }

    catch (Exception e)
    {
      // Ignore exception and just return null
    }

    return comment;
  }

  /**
   * Get schema location for XML schema.
   * @return schema location for XML schema.
   */
  public static String getXMLSchemaLocation()
  {
    return getSchemaLocation(
      WSIProperties.PROP_XML_SCHEMA,
      WSIProperties.DEF_XML_SCHEMA);
  }

  /**
   * Get SOAP schema location.
   * @return SOAP schema location.
   */
  public static String getSOAPSchemaLocation()
  {
    return getSchemaLocation(
      WSIProperties.PROP_SOAP_SCHEMA,
      WSIProperties.DEF_SOAP_SCHEMA);
  }

  /**
   * Get WSDL schema location.
   * @return WSDL schema location.
   */
  public static String getWSDLSchemaLocation()
  {
    return getSchemaLocation(
      WSIProperties.PROP_WSDL_SCHEMA,
      WSIProperties.DEF_WSDL_SCHEMA);
  }

  /**
  * Get WSDL SOAP schema location.
  * @return WSDL SOAP schema location.
  */
  public static String getWSDLSOAPSchemaLocation()
  {
    return getSchemaLocation(
      WSIProperties.PROP_WSDL_SOAP_SCHEMA,
      WSIProperties.DEF_WSDL_SOAP_SCHEMA);
  }
  /**
   * Get WSDL schema location.
   * @return WSDL schema location.
   */
  private static String getSchemaLocation(
    String propertyName,
    String defaultValue)
  {
    //String schemaLocation = null;

    // Get the wsi.home system property
    //String wsiHome = System.getProperty(WSIProperties.PROP_WSI_HOME);
    //String fileLocation = WSIProperties.getProperty(propertyName, defaultValue);
    //
    // If the file location is specified in the wsi.properties file then build location
    //if (fileLocation != null)
    //{
    // If wsi.home is set, then use it
    //  if (wsiHome != null)
    //  {
    //     schemaLocation = wsiHome;
    //   }
    //   if (schemaLocation == null)
    //   {
    //    schemaLocation = fileLocation;
    //  }
    //  else
    //  {
    //   if (!schemaLocation.endsWith("/"))
    //    {
    //     schemaLocation += "/";
    //   }
    //
    //    schemaLocation += fileLocation;
    //  }
    // }
    return defaultValue;
  }
}

Back to the top