You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by jk...@apache.org on 2007/08/23 13:01:35 UTC
svn commit: r568932 [4/36] - in
/incubator/woden/trunk/java/src/org/apache/woden: ./ ant/ internal/
internal/resolver/ internal/schema/ internal/util/ internal/util/dom/
internal/util/om/ internal/wsdl20/ internal/wsdl20/extensions/
internal/wsdl20/ext...
Modified: incubator/woden/trunk/java/src/org/apache/woden/ant/Report.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/ant/Report.java?rev=568932&r1=568931&r2=568932&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/ant/Report.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/ant/Report.java Thu Aug 23 04:01:23 2007
@@ -1,233 +1,233 @@
-/**
- * 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.woden.ant;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintWriter;
-import java.util.Vector;
-
-import org.apache.woden.ErrorHandler;
-import org.apache.woden.ErrorInfo;
-import org.apache.woden.ErrorLocator;
-
-/**
- * The <code>Report</code> class writes an XML file that reports the results of validating a set of WSDL files.
- *
- * @author Arthur Ryman (ryman@ca.ibm.com, arthur.ryman@gmail.com)
- *
- */
-public class Report extends XMLWriter implements ErrorHandler {
-
- private final String NS = "http://www.w3.org/2006/06/wsdl/ValidationReport";
-
- private final String REPORT = "report";
-
- private final String WSDL = "wsdl";
-
- private final String URI = "uri";
-
- private final String SUCCESS = "success";
-
- // ErrorHandler elements
-
- private final String WARNING = "warning";
-
- private final String ERROR = "error";
-
- private final String FATAL_ERROR = "fatalError";
-
- // ErrorInfo elements
-
- private final String ERROR_LOCATOR = "errorLocator";
-
- private final String KEY = "key";
-
- private final String MESSAGE = "message";
-
- private final String EXCEPTION = "exception";
-
- // ErrorLocator elements
-
- private final String DOCUMENT_BASE_URI = "documentBaseUri";
-
- private final String LOCATION_URI = "locationUri";
-
- private final String LINE_NUMBER = "lineNumber";
-
- private final String COLUMN_NUMBER = "columnNumber";
-
- // Exception element
-
- private final String DETAIL_MESSAGE = "detailMessage";
-
-
- // error handler data
- private boolean success = true;
- private Vector errorInfos = null;
- private Vector severities = null;
-
- /**
- * Creates a report writer and writes the document root.
- *
- * @param report the reort file
- * @return the report writer
- */
- public static Report openReport(File report) {
-
- if (report == null) {
-
- return new Report(null);
- }
-
- FileOutputStream fos;
- try {
- fos = new FileOutputStream(report);
- } catch (FileNotFoundException e) {
-
- e.printStackTrace();
-
- return new Report(null);
- }
-
- PrintWriter reportOut = new PrintWriter(fos);
- Report reportWriter = new Report(reportOut);
- reportWriter.xmlDeclaration("UTF-8");
- reportWriter.beginReport();
-
- return reportWriter;
- }
-
- /**
- * Ends the report and closes the output writer.
- */
- public void closeReport() {
-
- endReport();
- close();
- }
-
- /**
- * Constructs a <code>Report</code> writer.
- *
- * @param out the output writer or null
- */
- public Report(PrintWriter out) {
- super(out);
- }
-
- public void beginReport() {
- beginElement(REPORT, "xmlns='" + NS + "'");
- }
-
- public void endReport() {
- endAllElements();
- }
-
- public void beginWsdl(String uri) {
-
- success = true;
- errorInfos = new Vector();
- severities = new Vector();
-
- beginElement(WSDL);
-
- element(URI, uri);
- }
-
- public void endWsdl() {
-
- write(SUCCESS, success);
-
- for(int i = 0; i < errorInfos.size(); i ++) {
-
- ErrorInfo errorInfo = (ErrorInfo) errorInfos.elementAt(i);
- String severity = (String) severities.elementAt(i);
-
- write(severity, errorInfo);
- }
-
- endElement();
-
- success = true;
- errorInfos = null;
- severities = null;
- }
-
- public void warning(ErrorInfo errorInfo) {
-
- errorInfos.add(errorInfo);
- severities.add(WARNING);
- }
-
- public void error(ErrorInfo errorInfo) {
-
- success = false;
- errorInfos.add(errorInfo);
- severities.add(ERROR);
- }
-
- public void fatalError(ErrorInfo errorInfo) {
-
- success = false;
- errorInfos.add(errorInfo);
- severities.add(FATAL_ERROR);
- }
-
- public void write(String tag, ErrorInfo errorInfo) {
-
- if (errorInfo == null)
- return;
-
- beginElement(tag);
-
- write(ERROR_LOCATOR, errorInfo.getErrorLocator());
- element(KEY, errorInfo.getKey());
- element(MESSAGE, errorInfo.getMessage());
- write(EXCEPTION, errorInfo.getException());
-
- endElement();
- }
-
- public void write(String tag, ErrorLocator errorLocator) {
-
- if (errorLocator == null)
- return;
-
- beginElement(tag);
-
- write(DOCUMENT_BASE_URI, errorLocator.getDocumentBaseURI());
- write(LOCATION_URI, errorLocator.getLocationURI());
- write(LINE_NUMBER, errorLocator.getLineNumber());
- write(COLUMN_NUMBER, errorLocator.getColumnNumber());
-
- endElement();
- }
-
- public void write(String tag, Exception e) {
-
- if (e == null)
- return;
-
- beginElement(tag);
-
- write(DETAIL_MESSAGE, e.getMessage());
-
- endElement();
- }
-}
+/**
+ * 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.woden.ant;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.util.Vector;
+
+import org.apache.woden.ErrorHandler;
+import org.apache.woden.ErrorInfo;
+import org.apache.woden.ErrorLocator;
+
+/**
+ * The <code>Report</code> class writes an XML file that reports the results of validating a set of WSDL files.
+ *
+ * @author Arthur Ryman (ryman@ca.ibm.com, arthur.ryman@gmail.com)
+ *
+ */
+public class Report extends XMLWriter implements ErrorHandler {
+
+ private final String NS = "http://www.w3.org/2006/06/wsdl/ValidationReport";
+
+ private final String REPORT = "report";
+
+ private final String WSDL = "wsdl";
+
+ private final String URI = "uri";
+
+ private final String SUCCESS = "success";
+
+ // ErrorHandler elements
+
+ private final String WARNING = "warning";
+
+ private final String ERROR = "error";
+
+ private final String FATAL_ERROR = "fatalError";
+
+ // ErrorInfo elements
+
+ private final String ERROR_LOCATOR = "errorLocator";
+
+ private final String KEY = "key";
+
+ private final String MESSAGE = "message";
+
+ private final String EXCEPTION = "exception";
+
+ // ErrorLocator elements
+
+ private final String DOCUMENT_BASE_URI = "documentBaseUri";
+
+ private final String LOCATION_URI = "locationUri";
+
+ private final String LINE_NUMBER = "lineNumber";
+
+ private final String COLUMN_NUMBER = "columnNumber";
+
+ // Exception element
+
+ private final String DETAIL_MESSAGE = "detailMessage";
+
+
+ // error handler data
+ private boolean success = true;
+ private Vector errorInfos = null;
+ private Vector severities = null;
+
+ /**
+ * Creates a report writer and writes the document root.
+ *
+ * @param report the reort file
+ * @return the report writer
+ */
+ public static Report openReport(File report) {
+
+ if (report == null) {
+
+ return new Report(null);
+ }
+
+ FileOutputStream fos;
+ try {
+ fos = new FileOutputStream(report);
+ } catch (FileNotFoundException e) {
+
+ e.printStackTrace();
+
+ return new Report(null);
+ }
+
+ PrintWriter reportOut = new PrintWriter(fos);
+ Report reportWriter = new Report(reportOut);
+ reportWriter.xmlDeclaration("UTF-8");
+ reportWriter.beginReport();
+
+ return reportWriter;
+ }
+
+ /**
+ * Ends the report and closes the output writer.
+ */
+ public void closeReport() {
+
+ endReport();
+ close();
+ }
+
+ /**
+ * Constructs a <code>Report</code> writer.
+ *
+ * @param out the output writer or null
+ */
+ public Report(PrintWriter out) {
+ super(out);
+ }
+
+ public void beginReport() {
+ beginElement(REPORT, "xmlns='" + NS + "'");
+ }
+
+ public void endReport() {
+ endAllElements();
+ }
+
+ public void beginWsdl(String uri) {
+
+ success = true;
+ errorInfos = new Vector();
+ severities = new Vector();
+
+ beginElement(WSDL);
+
+ element(URI, uri);
+ }
+
+ public void endWsdl() {
+
+ write(SUCCESS, success);
+
+ for(int i = 0; i < errorInfos.size(); i ++) {
+
+ ErrorInfo errorInfo = (ErrorInfo) errorInfos.elementAt(i);
+ String severity = (String) severities.elementAt(i);
+
+ write(severity, errorInfo);
+ }
+
+ endElement();
+
+ success = true;
+ errorInfos = null;
+ severities = null;
+ }
+
+ public void warning(ErrorInfo errorInfo) {
+
+ errorInfos.add(errorInfo);
+ severities.add(WARNING);
+ }
+
+ public void error(ErrorInfo errorInfo) {
+
+ success = false;
+ errorInfos.add(errorInfo);
+ severities.add(ERROR);
+ }
+
+ public void fatalError(ErrorInfo errorInfo) {
+
+ success = false;
+ errorInfos.add(errorInfo);
+ severities.add(FATAL_ERROR);
+ }
+
+ public void write(String tag, ErrorInfo errorInfo) {
+
+ if (errorInfo == null)
+ return;
+
+ beginElement(tag);
+
+ write(ERROR_LOCATOR, errorInfo.getErrorLocator());
+ element(KEY, errorInfo.getKey());
+ element(MESSAGE, errorInfo.getMessage());
+ write(EXCEPTION, errorInfo.getException());
+
+ endElement();
+ }
+
+ public void write(String tag, ErrorLocator errorLocator) {
+
+ if (errorLocator == null)
+ return;
+
+ beginElement(tag);
+
+ write(DOCUMENT_BASE_URI, errorLocator.getDocumentBaseURI());
+ write(LOCATION_URI, errorLocator.getLocationURI());
+ write(LINE_NUMBER, errorLocator.getLineNumber());
+ write(COLUMN_NUMBER, errorLocator.getColumnNumber());
+
+ endElement();
+ }
+
+ public void write(String tag, Exception e) {
+
+ if (e == null)
+ return;
+
+ beginElement(tag);
+
+ write(DETAIL_MESSAGE, e.getMessage());
+
+ endElement();
+ }
+}
Propchange: incubator/woden/trunk/java/src/org/apache/woden/ant/Report.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/woden/trunk/java/src/org/apache/woden/ant/ValidateWSDL20.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/ant/ValidateWSDL20.java?rev=568932&r1=568931&r2=568932&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/ant/ValidateWSDL20.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/ant/ValidateWSDL20.java Thu Aug 23 04:01:23 2007
@@ -1,463 +1,463 @@
-/**
- * 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.woden.ant;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.net.MalformedURLException;
-
-import javax.xml.namespace.QName;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.MatchingTask;
-import org.apache.woden.WSDLException;
-import org.apache.woden.WSDLFactory;
-import org.apache.woden.WSDLReader;
-import org.apache.woden.wsdl20.Binding;
-import org.apache.woden.wsdl20.Description;
-import org.apache.woden.wsdl20.ElementDeclaration;
-import org.apache.woden.wsdl20.Interface;
-import org.apache.woden.wsdl20.Service;
-import org.apache.woden.wsdl20.TypeDefinition;
-
-/**
- * This is an Ant task to validate WSDL 2.0 files.
- *
- * Parameters: The <code>dir</code> attribute is a file directory for the
- * fileset of WSDL 2.0 files to validate. You specify files in include and
- * exclude using the usual Ant attributes and elements.
- *
- * The <code>failonerror</code> attribute is a boolean flag with the usual
- * meaning.
- *
- * The <code>verbose</code> attribute is a boolean flag that enables verbose
- * output.
- *
- * The <code>cm</code> attribute is a boolean flag that enables Component
- * Model interchange format output</code>. The default is false.
- *
- * The <code>cmdir</code> attribute is a file directory for the Component
- * Model interchange format output files. This is ignored if <code>cm</code>
- * is false. The default is to use the input directory as specified by the
- * <code>dir</code> attribute.
- *
- * The <code>cmext</code> attribute is the file extension to use for the
- * Component Model interchange format output files. This is ignored if <code>cm</code>
- * is false. The default is <code>.wsdlcm</code>.
- *
- * @author Arthur Ryman (ryman@ca.ibm.com)
- *
- * TODO: add support writing out failed assertions in XML
- *
- */
-
-public class ValidateWSDL20 extends MatchingTask {
-
- // directory for fileset
- private File dir;
-
- // flag to enable failonerror
- private boolean failOnError = false;
-
- // flag to enable verbose output
- private boolean verbose = false;
-
- // flag to enable Component Model interchange format output
- private boolean cm = false;
-
- // directory for Component Model interchange format output
- private File cmdir;
-
- // extension for Component Model interchange format output
- private String cmext;
-
- // report output file
- private File report;
-
- // report writer
- private Report reportWriter;
-
- // resolver catalog location
- private String catalog;
-
- // base URI for the catalog
- private String baseURI;
-
-
- // default extension for Component Model interchange format output
- private static final String CMEXT_DEFAULT = ".wsdlcm";
-
- /**
- * Gets the input WSDL fileset directory.
- *
- * @return the directory
- */
- public File getDir() {
- return this.dir;
- }
-
- /**
- * Sets the input WSDL fileset directory.
- *
- * @param dir the directory
- */
- public void setDir(File dir) {
- this.dir = dir;
- }
-
- /**
- * Enables fail on error behavior.
- *
- * @param failOnError the flag
- */
- public void setFailOnError(boolean failOnError) {
- this.failOnError = failOnError;
- }
-
- /**
- * Tests for fail on error behavior.
- *
- * @return the flag
- */
- public boolean isFailOnError() {
- return failOnError;
- }
-
- /**
- * Enables verbose console output.
- *
- * @param verbose the flag
- */
- public void setVerbose(boolean verbose) {
- this.verbose = verbose;
- }
-
- /**
- * Tests for verbose console output.
- *
- * @return the flag
- */
- public boolean isVerbose() {
- return verbose;
- }
-
- /**
- * Enables component model interchange format output.
- *
- * @param cm the flag
- */
- public void setCm(boolean cm) {
- this.cm = cm;
- }
-
- /**
- * Tests for component model interchange formal output.
- *
- * @return the flag
- */
- public boolean isCm() {
- return cm;
- }
-
- /**
- * Sets the directory for component model interchange formal output.
- *
- * @param cmdir the directory
- */
- public void setCmdir(File cmdir) {
- this.cmdir = cmdir;
- }
-
- /**
- * Gets the directory for component model interchange formal output.
- *
- * @return the directory
- */
- public File getCmdir() {
- return cmdir;
- }
-
- /**
- * Sets the component model interchange format file extension.
- *
- * @param cmext the extension
- */
- public void setCmext(String cmext) {
- this.cmext = cmext;
- }
-
- /**
- * Gets the component model interchange format file extension.
- *
- * @return the extension
- */
- public String getCmext() {
- return cmext;
- }
-
- /**
- * Gets the output report file.
- *
- * @return the file
- */
- public File getReport() {
- return this.report;
- }
-
- /**
- * Sets the output report file.
- *
- * @param report the file
- */
- public void setReport(File report) {
- this.report = report;
- }
-
- public void execute() throws BuildException {
-
- // check the cm input attributes and set defaults if necessary
- if (isCm()) {
- File cmdir = getCmdir();
- if (cmdir == null) {
-
- // default cmdir to dir
- cmdir = getDir();
- setCmdir(cmdir);
- }
-
- if (!cmdir.isDirectory()) {
-
- // cmdir MUST be a directory
- System.out.println("Invalid cm output directory: "
- + cmdir.toString());
-
- // disable cm output
- setCm(false);
- }
-
- String cmext = getCmext();
- if (cmext == null) {
-
- // default cmext
- setCmext(CMEXT_DEFAULT);
- }
- }
-
- WSDLReader reader = null;
-
- // create a reader
- try {
-
- WSDLFactory factory = WSDLFactory.newInstance();
- reader = factory.newWSDLReader();
-
- } catch (WSDLException e) {
-
- // fail if unable to create a reader
- throw new BuildException(e);
- }
-
- // set the features but continue even if they are not supported yet
- try {
- // always enable WSDL 2.0 validation since this is a validation task
- reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
-
- // enable verbose output
- reader.setFeature(WSDLReader.FEATURE_VERBOSE, isVerbose());
-
- // enable continue on error (opposite of fail on error)
- reader.setFeature(WSDLReader.FEATURE_CONTINUE_ON_ERROR,
- !isFailOnError());
- } catch (IllegalArgumentException e) {
- System.out.println("warning: " + e.getMessage());
- }
-
- if (isVerbose()) {
- System.out.println("File dir = " + dir.getAbsolutePath());
-
- Project project = getProject();
- File baseDir = project.getBaseDir();
- System.out.println("File baseDir = " + baseDir.getAbsolutePath());
- }
-
- DirectoryScanner directoryScanner = getDirectoryScanner(dir);
- String[] files = directoryScanner.getIncludedFiles();
-
- reportWriter = Report.openReport(report);
- // use the same reader for all the WSDL files
- for (int i = 0; i < files.length; i++) {
-
- File file = new File(dir, files[i]);
-
- // make a URL for the file
- String wsdlLoc = file.toURI().toString();
- System.out.println("validating " + wsdlLoc);
-
- reportWriter.beginWsdl(wsdlLoc);
-
- try {
- // <-- the Description component
- Description descComp = reader
- .readWSDL(wsdlLoc, reportWriter);
-
- if (isCm()) {
- // write the Component Model interchange format output file
- writeCm(descComp, files[i]);
- }
-
- if (isVerbose()) {
-
- writeVerbose(descComp);
- }
-
- } catch (Exception e) {
-
- if (isFailOnError()) {
-
- reportWriter.endWsdl();
- reportWriter.closeReport();
- throw new BuildException(e);
- }
- }
- reportWriter.endWsdl();
- }
- reportWriter.closeReport();
- }
-
- private void writeVerbose(Description descComp) {
- ElementDeclaration elementDeclarations[] = descComp
- .getElementDeclarations();
- System.out.println("There are " + elementDeclarations.length
- + " ElementDeclaration components.");
-
- for (int j = 0; j < elementDeclarations.length; j++) {
-
- ElementDeclaration elementDeclaration = elementDeclarations[j];
-
- QName name = elementDeclaration.getName();
- System.out
- .println("ElementDeclaration[" + j + "] : name = " + name);
- }
-
- TypeDefinition typeDefinitions[] = descComp.getTypeDefinitions();
- System.out.println("There are " + typeDefinitions.length
- + " TypeDefinition components.");
-
- for (int j = 0; j < typeDefinitions.length; j++) {
- TypeDefinition typeDefinition = typeDefinitions[j];
-
- QName name = typeDefinition.getName();
- System.out.println("TypeDefinition[" + j + "] : name = " + name);
- }
-
- Interface interfaces[] = descComp.getInterfaces();
- System.out.println("There are " + interfaces.length
- + " Interface components.");
-
- for (int j = 0; j < interfaces.length; j++) {
-
- System.out.println("Interface[" + j + "] : name = "
- + interfaces[j].getName());
- }
-
- Binding bindings[] = descComp.getBindings();
- System.out.println("There are " + bindings.length
- + " Binding components.");
-
- for (int j = 0; j < bindings.length; j++) {
-
- System.out.println("Binding[" + j + "] : name = "
- + bindings[j].getName());
- }
-
- Service services[] = descComp.getServices();
- System.out.println("There are " + services.length
- + " Service components.");
-
- for (int j = 0; j < services.length; j++) {
-
- System.out.println("Service[" + j + "] : name = "
- + services[j].getName());
- }
- }
-
- private void writeCm(Description descComp, String file) throws IOException {
-
- // replace the file extension
-
- int dot = file.lastIndexOf('.');
- String base = dot == -1 ? file : file.substring(0, dot);
- String ext = getCmext();
- String cmfilename = base + ext;
- File cmfile = new File(cmdir, cmfilename);
- File parent = cmfile.getParentFile();
- if (parent != null) {
- if (!parent.exists()) {
- boolean created = parent.mkdirs();
- if (!created) {
- System.out.println("Unable to create directory: "
- + parent.toString());
- }
- }
- }
-
- FileOutputStream fos = new FileOutputStream(cmfile);
- PrintWriter out = new PrintWriter(fos);
- WsdlCm wsdlCm = new WsdlCm(out);
- wsdlCm.write(descComp);
- out.close();
- fos.close();
- }
-
- /**
- * Sets the resolver catalog file.
- *
- * @param catalog resolver catalog file URI
- */
- public void setCatalog(String catalog) {
- this.catalog = getURLFilePath(catalog);
- System.setProperty("org.apache.woden.resolver.simpleresolver.catalog", this.catalog);
- }
-
- /**
- * Sets the resolver base URI path.
- *
- * @param baseURI base URI path
- */
- public void setBaseURI(String baseURI) {
- this.baseURI = getURLFilePath(baseURI);
- System.setProperty("org.apache.woden.resolver.simpleresolver.baseURIs", this.baseURI);
- }
-
- private String getURLFilePath(String localPath) {
- File localFile = new File(localPath);
- if (localFile.exists()) {
- try {
- return localFile.toURI().toURL().toString();
- } catch (MalformedURLException mue) {
- System.err.println("Got MalformedURLException trying to create a URL from " + localPath);
- return localPath;
- }
- } else {
- return localPath;
- }
- }
-}
+/**
+ * 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.woden.ant;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.MatchingTask;
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.WSDLReader;
+import org.apache.woden.wsdl20.Binding;
+import org.apache.woden.wsdl20.Description;
+import org.apache.woden.wsdl20.ElementDeclaration;
+import org.apache.woden.wsdl20.Interface;
+import org.apache.woden.wsdl20.Service;
+import org.apache.woden.wsdl20.TypeDefinition;
+
+/**
+ * This is an Ant task to validate WSDL 2.0 files.
+ *
+ * Parameters: The <code>dir</code> attribute is a file directory for the
+ * fileset of WSDL 2.0 files to validate. You specify files in include and
+ * exclude using the usual Ant attributes and elements.
+ *
+ * The <code>failonerror</code> attribute is a boolean flag with the usual
+ * meaning.
+ *
+ * The <code>verbose</code> attribute is a boolean flag that enables verbose
+ * output.
+ *
+ * The <code>cm</code> attribute is a boolean flag that enables Component
+ * Model interchange format output</code>. The default is false.
+ *
+ * The <code>cmdir</code> attribute is a file directory for the Component
+ * Model interchange format output files. This is ignored if <code>cm</code>
+ * is false. The default is to use the input directory as specified by the
+ * <code>dir</code> attribute.
+ *
+ * The <code>cmext</code> attribute is the file extension to use for the
+ * Component Model interchange format output files. This is ignored if <code>cm</code>
+ * is false. The default is <code>.wsdlcm</code>.
+ *
+ * @author Arthur Ryman (ryman@ca.ibm.com)
+ *
+ * TODO: add support writing out failed assertions in XML
+ *
+ */
+
+public class ValidateWSDL20 extends MatchingTask {
+
+ // directory for fileset
+ private File dir;
+
+ // flag to enable failonerror
+ private boolean failOnError = false;
+
+ // flag to enable verbose output
+ private boolean verbose = false;
+
+ // flag to enable Component Model interchange format output
+ private boolean cm = false;
+
+ // directory for Component Model interchange format output
+ private File cmdir;
+
+ // extension for Component Model interchange format output
+ private String cmext;
+
+ // report output file
+ private File report;
+
+ // report writer
+ private Report reportWriter;
+
+ // resolver catalog location
+ private String catalog;
+
+ // base URI for the catalog
+ private String baseURI;
+
+
+ // default extension for Component Model interchange format output
+ private static final String CMEXT_DEFAULT = ".wsdlcm";
+
+ /**
+ * Gets the input WSDL fileset directory.
+ *
+ * @return the directory
+ */
+ public File getDir() {
+ return this.dir;
+ }
+
+ /**
+ * Sets the input WSDL fileset directory.
+ *
+ * @param dir the directory
+ */
+ public void setDir(File dir) {
+ this.dir = dir;
+ }
+
+ /**
+ * Enables fail on error behavior.
+ *
+ * @param failOnError the flag
+ */
+ public void setFailOnError(boolean failOnError) {
+ this.failOnError = failOnError;
+ }
+
+ /**
+ * Tests for fail on error behavior.
+ *
+ * @return the flag
+ */
+ public boolean isFailOnError() {
+ return failOnError;
+ }
+
+ /**
+ * Enables verbose console output.
+ *
+ * @param verbose the flag
+ */
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ /**
+ * Tests for verbose console output.
+ *
+ * @return the flag
+ */
+ public boolean isVerbose() {
+ return verbose;
+ }
+
+ /**
+ * Enables component model interchange format output.
+ *
+ * @param cm the flag
+ */
+ public void setCm(boolean cm) {
+ this.cm = cm;
+ }
+
+ /**
+ * Tests for component model interchange formal output.
+ *
+ * @return the flag
+ */
+ public boolean isCm() {
+ return cm;
+ }
+
+ /**
+ * Sets the directory for component model interchange formal output.
+ *
+ * @param cmdir the directory
+ */
+ public void setCmdir(File cmdir) {
+ this.cmdir = cmdir;
+ }
+
+ /**
+ * Gets the directory for component model interchange formal output.
+ *
+ * @return the directory
+ */
+ public File getCmdir() {
+ return cmdir;
+ }
+
+ /**
+ * Sets the component model interchange format file extension.
+ *
+ * @param cmext the extension
+ */
+ public void setCmext(String cmext) {
+ this.cmext = cmext;
+ }
+
+ /**
+ * Gets the component model interchange format file extension.
+ *
+ * @return the extension
+ */
+ public String getCmext() {
+ return cmext;
+ }
+
+ /**
+ * Gets the output report file.
+ *
+ * @return the file
+ */
+ public File getReport() {
+ return this.report;
+ }
+
+ /**
+ * Sets the output report file.
+ *
+ * @param report the file
+ */
+ public void setReport(File report) {
+ this.report = report;
+ }
+
+ public void execute() throws BuildException {
+
+ // check the cm input attributes and set defaults if necessary
+ if (isCm()) {
+ File cmdir = getCmdir();
+ if (cmdir == null) {
+
+ // default cmdir to dir
+ cmdir = getDir();
+ setCmdir(cmdir);
+ }
+
+ if (!cmdir.isDirectory()) {
+
+ // cmdir MUST be a directory
+ System.out.println("Invalid cm output directory: "
+ + cmdir.toString());
+
+ // disable cm output
+ setCm(false);
+ }
+
+ String cmext = getCmext();
+ if (cmext == null) {
+
+ // default cmext
+ setCmext(CMEXT_DEFAULT);
+ }
+ }
+
+ WSDLReader reader = null;
+
+ // create a reader
+ try {
+
+ WSDLFactory factory = WSDLFactory.newInstance();
+ reader = factory.newWSDLReader();
+
+ } catch (WSDLException e) {
+
+ // fail if unable to create a reader
+ throw new BuildException(e);
+ }
+
+ // set the features but continue even if they are not supported yet
+ try {
+ // always enable WSDL 2.0 validation since this is a validation task
+ reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
+
+ // enable verbose output
+ reader.setFeature(WSDLReader.FEATURE_VERBOSE, isVerbose());
+
+ // enable continue on error (opposite of fail on error)
+ reader.setFeature(WSDLReader.FEATURE_CONTINUE_ON_ERROR,
+ !isFailOnError());
+ } catch (IllegalArgumentException e) {
+ System.out.println("warning: " + e.getMessage());
+ }
+
+ if (isVerbose()) {
+ System.out.println("File dir = " + dir.getAbsolutePath());
+
+ Project project = getProject();
+ File baseDir = project.getBaseDir();
+ System.out.println("File baseDir = " + baseDir.getAbsolutePath());
+ }
+
+ DirectoryScanner directoryScanner = getDirectoryScanner(dir);
+ String[] files = directoryScanner.getIncludedFiles();
+
+ reportWriter = Report.openReport(report);
+ // use the same reader for all the WSDL files
+ for (int i = 0; i < files.length; i++) {
+
+ File file = new File(dir, files[i]);
+
+ // make a URL for the file
+ String wsdlLoc = file.toURI().toString();
+ System.out.println("validating " + wsdlLoc);
+
+ reportWriter.beginWsdl(wsdlLoc);
+
+ try {
+ // <-- the Description component
+ Description descComp = reader
+ .readWSDL(wsdlLoc, reportWriter);
+
+ if (isCm()) {
+ // write the Component Model interchange format output file
+ writeCm(descComp, files[i]);
+ }
+
+ if (isVerbose()) {
+
+ writeVerbose(descComp);
+ }
+
+ } catch (Exception e) {
+
+ if (isFailOnError()) {
+
+ reportWriter.endWsdl();
+ reportWriter.closeReport();
+ throw new BuildException(e);
+ }
+ }
+ reportWriter.endWsdl();
+ }
+ reportWriter.closeReport();
+ }
+
+ private void writeVerbose(Description descComp) {
+ ElementDeclaration elementDeclarations[] = descComp
+ .getElementDeclarations();
+ System.out.println("There are " + elementDeclarations.length
+ + " ElementDeclaration components.");
+
+ for (int j = 0; j < elementDeclarations.length; j++) {
+
+ ElementDeclaration elementDeclaration = elementDeclarations[j];
+
+ QName name = elementDeclaration.getName();
+ System.out
+ .println("ElementDeclaration[" + j + "] : name = " + name);
+ }
+
+ TypeDefinition typeDefinitions[] = descComp.getTypeDefinitions();
+ System.out.println("There are " + typeDefinitions.length
+ + " TypeDefinition components.");
+
+ for (int j = 0; j < typeDefinitions.length; j++) {
+ TypeDefinition typeDefinition = typeDefinitions[j];
+
+ QName name = typeDefinition.getName();
+ System.out.println("TypeDefinition[" + j + "] : name = " + name);
+ }
+
+ Interface interfaces[] = descComp.getInterfaces();
+ System.out.println("There are " + interfaces.length
+ + " Interface components.");
+
+ for (int j = 0; j < interfaces.length; j++) {
+
+ System.out.println("Interface[" + j + "] : name = "
+ + interfaces[j].getName());
+ }
+
+ Binding bindings[] = descComp.getBindings();
+ System.out.println("There are " + bindings.length
+ + " Binding components.");
+
+ for (int j = 0; j < bindings.length; j++) {
+
+ System.out.println("Binding[" + j + "] : name = "
+ + bindings[j].getName());
+ }
+
+ Service services[] = descComp.getServices();
+ System.out.println("There are " + services.length
+ + " Service components.");
+
+ for (int j = 0; j < services.length; j++) {
+
+ System.out.println("Service[" + j + "] : name = "
+ + services[j].getName());
+ }
+ }
+
+ private void writeCm(Description descComp, String file) throws IOException {
+
+ // replace the file extension
+
+ int dot = file.lastIndexOf('.');
+ String base = dot == -1 ? file : file.substring(0, dot);
+ String ext = getCmext();
+ String cmfilename = base + ext;
+ File cmfile = new File(cmdir, cmfilename);
+ File parent = cmfile.getParentFile();
+ if (parent != null) {
+ if (!parent.exists()) {
+ boolean created = parent.mkdirs();
+ if (!created) {
+ System.out.println("Unable to create directory: "
+ + parent.toString());
+ }
+ }
+ }
+
+ FileOutputStream fos = new FileOutputStream(cmfile);
+ PrintWriter out = new PrintWriter(fos);
+ WsdlCm wsdlCm = new WsdlCm(out);
+ wsdlCm.write(descComp);
+ out.close();
+ fos.close();
+ }
+
+ /**
+ * Sets the resolver catalog file.
+ *
+ * @param catalog resolver catalog file URI
+ */
+ public void setCatalog(String catalog) {
+ this.catalog = getURLFilePath(catalog);
+ System.setProperty("org.apache.woden.resolver.simpleresolver.catalog", this.catalog);
+ }
+
+ /**
+ * Sets the resolver base URI path.
+ *
+ * @param baseURI base URI path
+ */
+ public void setBaseURI(String baseURI) {
+ this.baseURI = getURLFilePath(baseURI);
+ System.setProperty("org.apache.woden.resolver.simpleresolver.baseURIs", this.baseURI);
+ }
+
+ private String getURLFilePath(String localPath) {
+ File localFile = new File(localPath);
+ if (localFile.exists()) {
+ try {
+ return localFile.toURI().toURL().toString();
+ } catch (MalformedURLException mue) {
+ System.err.println("Got MalformedURLException trying to create a URL from " + localPath);
+ return localPath;
+ }
+ } else {
+ return localPath;
+ }
+ }
+}
Propchange: incubator/woden/trunk/java/src/org/apache/woden/ant/ValidateWSDL20.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/woden/trunk/java/src/org/apache/woden/ant/WsdlCm.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/ant/WsdlCm.java?rev=568932&r1=568931&r2=568932&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/ant/WsdlCm.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/ant/WsdlCm.java Thu Aug 23 04:01:23 2007
@@ -1,149 +1,149 @@
-/**
+/**
* 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.woden.ant;
-
-/**
- * This class writes a Woden WSDL 2.0 component model instance in the W3C
- * interchange format which is an XML vocabulary for serializing component model
- * instances in a canonical way so that different implementations can be easily
- * compared for interoperability.
- *
- * The latest schema for this format is available at the following URL:
- *
- * http://dev.w3.org/cvsweb/~checkout~/2002/ws/desc/test-suite/interchange/wsdlcm.xsd?content-type=text/xml
- *
- * @author Arthur Ryman (ryman@ca.ibm.com, arthur-ryman@gmail.com)
- */
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintWriter;
-
-import org.apache.woden.WSDLException;
-import org.apache.woden.WSDLFactory;
-import org.apache.woden.WSDLReader;
-import org.apache.woden.wsdl20.Description;
-
-/**
- * The <code>WsdlCm</code> class writes the component model in the W3C interchange format.
- *
- * @author Arthur Ryman (ryman@ca.ibm.com, arthur-ryman@gmail.com)
- *
- */
-public class WsdlCm extends XMLWriter {
-
- private CmWriter cm;
-
- /**
- * Constructs a component model writer.
- *
- * @param out the output writer for the component model
- */
- public WsdlCm(PrintWriter out) {
- super(out);
-
- // create the writes for each namespace
- new CmBaseWriter(this);
- new CmExtensionsWriter(this);
- new CmRpcWriter(this);
- new CmHttpWriter(this);
- new CmSoapWriter(this);
- cm = new CmWriter(this);
- }
-
- /**
- * Writes the Description component in the component model interchange format.
- *
- * @param descComp the Description component
- */
- public void write(Description descComp) {
-
- cm.write(descComp);
- }
-
- /**
- * Tests the component model interchange format writer.
- *
- * TODO Move this method into a tests package.
- *
- * @param args the command line arguments
- */
- public static void main(String[] args) {
-
- // simple program to read a WSDL 2.0 file and then poke at the component
- // model.
-
- String wsdlLoc = "file:///D:/workspaces/WSD2/woden/ant-test/test.wsdl";
- String wsdlCmLoc = "D:\\workspaces\\WSD2\\woden\\ant-test\\test.xml";
- String reportLoc = "D:\\workspaces\\WSD2\\woden\\ant-test\\report.xml";
-
- if (args.length > 0) {
- wsdlLoc = args[0];
- }
-
- if (args.length > 1) {
- wsdlCmLoc = args[1];
- }
-
- if (args.length > 2) {
- reportLoc = args[2];
- }
-
- System.out.println("Starting: " + wsdlLoc);
-
- Report reportWriter = Report.openReport(new File(reportLoc));
- reportWriter.beginWsdl(wsdlLoc);
-
- try {
-
- WSDLFactory factory = WSDLFactory.newInstance();
- WSDLReader reader = factory.newWSDLReader();
-
- // <-- enable WSDL 2.0 validation (optional)
- reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
-
- // <-- the Description component
- Description descComp = reader.readWSDL(wsdlLoc, reportWriter);
-
- File xml = new File(wsdlCmLoc);
- FileOutputStream fos = new FileOutputStream(xml);
- PrintWriter out = new PrintWriter(fos);
- WsdlCm wsdlCm = new WsdlCm(out);
-
- wsdlCm.write(descComp);
-
- out.flush();
-
- } catch (WSDLException e) {
-
- e.printStackTrace();
- } catch (FileNotFoundException e) {
-
- e.printStackTrace();
- } catch (RuntimeException e) {
-
- e.printStackTrace();
- }
-
- reportWriter.endWsdl();
- reportWriter.closeReport();
-
- System.out.println("Finished.");
- }
-}
+ *
+ * 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.woden.ant;
+
+/**
+ * This class writes a Woden WSDL 2.0 component model instance in the W3C
+ * interchange format which is an XML vocabulary for serializing component model
+ * instances in a canonical way so that different implementations can be easily
+ * compared for interoperability.
+ *
+ * The latest schema for this format is available at the following URL:
+ *
+ * http://dev.w3.org/cvsweb/~checkout~/2002/ws/desc/test-suite/interchange/wsdlcm.xsd?content-type=text/xml
+ *
+ * @author Arthur Ryman (ryman@ca.ibm.com, arthur-ryman@gmail.com)
+ */
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.WSDLReader;
+import org.apache.woden.wsdl20.Description;
+
+/**
+ * The <code>WsdlCm</code> class writes the component model in the W3C interchange format.
+ *
+ * @author Arthur Ryman (ryman@ca.ibm.com, arthur-ryman@gmail.com)
+ *
+ */
+public class WsdlCm extends XMLWriter {
+
+ private CmWriter cm;
+
+ /**
+ * Constructs a component model writer.
+ *
+ * @param out the output writer for the component model
+ */
+ public WsdlCm(PrintWriter out) {
+ super(out);
+
+ // create the writes for each namespace
+ new CmBaseWriter(this);
+ new CmExtensionsWriter(this);
+ new CmRpcWriter(this);
+ new CmHttpWriter(this);
+ new CmSoapWriter(this);
+ cm = new CmWriter(this);
+ }
+
+ /**
+ * Writes the Description component in the component model interchange format.
+ *
+ * @param descComp the Description component
+ */
+ public void write(Description descComp) {
+
+ cm.write(descComp);
+ }
+
+ /**
+ * Tests the component model interchange format writer.
+ *
+ * TODO Move this method into a tests package.
+ *
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+
+ // simple program to read a WSDL 2.0 file and then poke at the component
+ // model.
+
+ String wsdlLoc = "file:///D:/workspaces/WSD2/woden/ant-test/test.wsdl";
+ String wsdlCmLoc = "D:\\workspaces\\WSD2\\woden\\ant-test\\test.xml";
+ String reportLoc = "D:\\workspaces\\WSD2\\woden\\ant-test\\report.xml";
+
+ if (args.length > 0) {
+ wsdlLoc = args[0];
+ }
+
+ if (args.length > 1) {
+ wsdlCmLoc = args[1];
+ }
+
+ if (args.length > 2) {
+ reportLoc = args[2];
+ }
+
+ System.out.println("Starting: " + wsdlLoc);
+
+ Report reportWriter = Report.openReport(new File(reportLoc));
+ reportWriter.beginWsdl(wsdlLoc);
+
+ try {
+
+ WSDLFactory factory = WSDLFactory.newInstance();
+ WSDLReader reader = factory.newWSDLReader();
+
+ // <-- enable WSDL 2.0 validation (optional)
+ reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
+
+ // <-- the Description component
+ Description descComp = reader.readWSDL(wsdlLoc, reportWriter);
+
+ File xml = new File(wsdlCmLoc);
+ FileOutputStream fos = new FileOutputStream(xml);
+ PrintWriter out = new PrintWriter(fos);
+ WsdlCm wsdlCm = new WsdlCm(out);
+
+ wsdlCm.write(descComp);
+
+ out.flush();
+
+ } catch (WSDLException e) {
+
+ e.printStackTrace();
+ } catch (FileNotFoundException e) {
+
+ e.printStackTrace();
+ } catch (RuntimeException e) {
+
+ e.printStackTrace();
+ }
+
+ reportWriter.endWsdl();
+ reportWriter.closeReport();
+
+ System.out.println("Finished.");
+ }
+}
Propchange: incubator/woden/trunk/java/src/org/apache/woden/ant/WsdlCm.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/woden/trunk/java/src/org/apache/woden/ant/XMLWriter.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/ant/XMLWriter.java?rev=568932&r1=568931&r2=568932&view=diff
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/ant/XMLWriter.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/ant/XMLWriter.java Thu Aug 23 04:01:23 2007
@@ -1,307 +1,307 @@
-/**
- * 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.woden.ant;
-
-import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.Stack;
-
-import org.apache.woden.types.NCName;
-
-/**
- * The <code>XMLWriter</code> class writes XML files.
- *
- * @author Arthur Ryman (ryman@ca.ibm.com, arthur.ryman@gmail.com)
- *
- */
-public class XMLWriter {
-
- private HashMap registry = new HashMap();
-
- private PrintWriter out;
-
- private int indentation = 2;
-
- private Stack tags = new Stack();
-
- /**
- * Constructs an XML writer.
- *
- * @param out the output writer
- */
- public XMLWriter(PrintWriter out) {
- this.out = out;
- }
-
- /**
- * Closes the output writer.
- */
- public void close() {
-
- if (out != null) {
-
- out.close();
- }
- }
-
- /**
- * Writes the XML declaration.
- *
- * @param encoding the character encoding or null
- */
- public void xmlDeclaration(String encoding) {
-
- if (out == null)
- return;
-
- if (encoding == null) {
- out.println("<?xml version='1.0'?>");
- } else {
- out.println("<?xml version='1.0' encoding='" + encoding + "'?>");
- }
- }
-
- /**
- * Writes the begin tag for an element.
- *
- * @param tag the tag
- */
- public void beginElement(String tag) {
-
- if (out == null)
- return;
-
- beginElement(tag, "");
- }
-
- /**
- * Writes the begin tag for an element with attributes.
- *
- * @param tag the tag
- * @param attributes the attributes
- */
- public void beginElement(String tag, String attributes) {
-
- if (out == null)
- return;
-
- indent();
- if (attributes.length() == 0) {
- out.println("<" + tag + ">");
-
- } else {
- out.println("<" + tag + " " + attributes + ">");
- }
- tags.push(tag);
- }
-
- /**
- * Writes the end tag for the current element.
- */
- public void endElement() {
-
- if (out == null)
- return;
-
- String tag = (String) tags.pop();
- indent();
- out.println("</" + tag + ">");
- }
-
- /**
- * Write the end tag for all open elements. Call this to produce a well-formed document when execution ends prematurely.
- */
- public void endAllElements() {
-
- while (!tags.empty()) {
-
- endElement();
- }
- }
-
- /**
- * Writes an element with text content.
- *
- * @param tag the tag
- * @param content the content
- */
- public void element(String tag, String content) {
-
- if (out == null)
- return;
-
- indent();
- out.println("<" + tag + ">" + escape(content) + "</" + tag + ">");
- }
-
- /**
- * Writes an empty element with attributes.
- *
- * @param tag the tag
- * @param attributes the attributes
- */
- public void emptyElement(String tag, String attributes) {
-
- if (out == null)
- return;
-
- indent();
- out.println("<" + tag + " " + attributes + "/>");
- }
-
- private void indent() {
-
- if (out == null)
- return;
-
- for (int i = 0; i < tags.size(); i++) {
- for (int j = 0; j < indentation; j++) {
- out.write(' ');
- }
- }
- }
-
- /**
- * Writes an NCName element if non-null.
- *
- * @param tag the tag
- * @param ncname the NCName object or null
- */
- public void write(String tag, NCName ncname) {
-
- if (ncname == null)
- return;
-
- element(tag, ncname.toString());
- }
-
- /**
- * Writes a String element if non-null.
- *
- * @param tag the tag
- * @param content the String object or null
- */
- public void write(String tag, String content) {
-
- if (content == null)
- return;
-
- element(tag, content);
- }
-
- /**
- * Writes a Boolean element if non-null.
- *
- * @param tag the tag
- * @param o the Boolean object or null
- */
- public void write(String tag, Boolean o) {
-
- if (o == null)
- return;
-
- write(tag, o.booleanValue());
- }
-
- /**
- * Writes a boolean element.
- *
- * @param tag the tag
- * @param value the boolean value
- */
- public void write(String tag, boolean value) {
-
- element(tag, Boolean.toString(value));
- }
-
- /**
- * Writes an int element.
- *
- * @param tag the tag
- * @param value the int value
- */
- public void write(String tag, int value) {
-
- element(tag, Integer.toString(value));
- }
-
- /**
- * Replaces the special XML characters a text string with their predefined entities.
- *
- * @param x the text
- * @return the escaped text
- */
- public static String escape(String x) {
-
- if (x == null)
- return null;
-
- StringBuffer y = new StringBuffer();
-
- for (int i = 0; i < x.length(); i++) {
-
- char c = x.charAt(i);
- switch (c) {
- case '&':
- y.append("&");
- break;
-
- case '<':
- y.append("<");
- break;
-
- case '>':
- y.append(">");
- break;
-
- case '"':
- y.append(""");
- break;
-
- case '\'':
- y.append("'");
- break;
-
- default:
- y.append(c);
- }
- }
-
- return y.toString();
- }
-
- /**
- * Registers a namespace writer for this XML writer.
- *
- * @param writer the namespace writer
- */
- public void register(NamespaceWriter writer) {
-
- registry.put(writer.getNamespace(), writer);
- }
-
- /**
- * Looks up a namespace writer for this XML writer.
- *
- * @param namespace the namespace to look up
- * @return the namespace writer
- */
- public NamespaceWriter lookup(String namespace) {
-
- return (NamespaceWriter) registry.get(namespace);
- }
-}
+/**
+ * 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.woden.ant;
+
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Stack;
+
+import org.apache.woden.types.NCName;
+
+/**
+ * The <code>XMLWriter</code> class writes XML files.
+ *
+ * @author Arthur Ryman (ryman@ca.ibm.com, arthur.ryman@gmail.com)
+ *
+ */
+public class XMLWriter {
+
+ private HashMap registry = new HashMap();
+
+ private PrintWriter out;
+
+ private int indentation = 2;
+
+ private Stack tags = new Stack();
+
+ /**
+ * Constructs an XML writer.
+ *
+ * @param out the output writer
+ */
+ public XMLWriter(PrintWriter out) {
+ this.out = out;
+ }
+
+ /**
+ * Closes the output writer.
+ */
+ public void close() {
+
+ if (out != null) {
+
+ out.close();
+ }
+ }
+
+ /**
+ * Writes the XML declaration.
+ *
+ * @param encoding the character encoding or null
+ */
+ public void xmlDeclaration(String encoding) {
+
+ if (out == null)
+ return;
+
+ if (encoding == null) {
+ out.println("<?xml version='1.0'?>");
+ } else {
+ out.println("<?xml version='1.0' encoding='" + encoding + "'?>");
+ }
+ }
+
+ /**
+ * Writes the begin tag for an element.
+ *
+ * @param tag the tag
+ */
+ public void beginElement(String tag) {
+
+ if (out == null)
+ return;
+
+ beginElement(tag, "");
+ }
+
+ /**
+ * Writes the begin tag for an element with attributes.
+ *
+ * @param tag the tag
+ * @param attributes the attributes
+ */
+ public void beginElement(String tag, String attributes) {
+
+ if (out == null)
+ return;
+
+ indent();
+ if (attributes.length() == 0) {
+ out.println("<" + tag + ">");
+
+ } else {
+ out.println("<" + tag + " " + attributes + ">");
+ }
+ tags.push(tag);
+ }
+
+ /**
+ * Writes the end tag for the current element.
+ */
+ public void endElement() {
+
+ if (out == null)
+ return;
+
+ String tag = (String) tags.pop();
+ indent();
+ out.println("</" + tag + ">");
+ }
+
+ /**
+ * Write the end tag for all open elements. Call this to produce a well-formed document when execution ends prematurely.
+ */
+ public void endAllElements() {
+
+ while (!tags.empty()) {
+
+ endElement();
+ }
+ }
+
+ /**
+ * Writes an element with text content.
+ *
+ * @param tag the tag
+ * @param content the content
+ */
+ public void element(String tag, String content) {
+
+ if (out == null)
+ return;
+
+ indent();
+ out.println("<" + tag + ">" + escape(content) + "</" + tag + ">");
+ }
+
+ /**
+ * Writes an empty element with attributes.
+ *
+ * @param tag the tag
+ * @param attributes the attributes
+ */
+ public void emptyElement(String tag, String attributes) {
+
+ if (out == null)
+ return;
+
+ indent();
+ out.println("<" + tag + " " + attributes + "/>");
+ }
+
+ private void indent() {
+
+ if (out == null)
+ return;
+
+ for (int i = 0; i < tags.size(); i++) {
+ for (int j = 0; j < indentation; j++) {
+ out.write(' ');
+ }
+ }
+ }
+
+ /**
+ * Writes an NCName element if non-null.
+ *
+ * @param tag the tag
+ * @param ncname the NCName object or null
+ */
+ public void write(String tag, NCName ncname) {
+
+ if (ncname == null)
+ return;
+
+ element(tag, ncname.toString());
+ }
+
+ /**
+ * Writes a String element if non-null.
+ *
+ * @param tag the tag
+ * @param content the String object or null
+ */
+ public void write(String tag, String content) {
+
+ if (content == null)
+ return;
+
+ element(tag, content);
+ }
+
+ /**
+ * Writes a Boolean element if non-null.
+ *
+ * @param tag the tag
+ * @param o the Boolean object or null
+ */
+ public void write(String tag, Boolean o) {
+
+ if (o == null)
+ return;
+
+ write(tag, o.booleanValue());
+ }
+
+ /**
+ * Writes a boolean element.
+ *
+ * @param tag the tag
+ * @param value the boolean value
+ */
+ public void write(String tag, boolean value) {
+
+ element(tag, Boolean.toString(value));
+ }
+
+ /**
+ * Writes an int element.
+ *
+ * @param tag the tag
+ * @param value the int value
+ */
+ public void write(String tag, int value) {
+
+ element(tag, Integer.toString(value));
+ }
+
+ /**
+ * Replaces the special XML characters a text string with their predefined entities.
+ *
+ * @param x the text
+ * @return the escaped text
+ */
+ public static String escape(String x) {
+
+ if (x == null)
+ return null;
+
+ StringBuffer y = new StringBuffer();
+
+ for (int i = 0; i < x.length(); i++) {
+
+ char c = x.charAt(i);
+ switch (c) {
+ case '&':
+ y.append("&");
+ break;
+
+ case '<':
+ y.append("<");
+ break;
+
+ case '>':
+ y.append(">");
+ break;
+
+ case '"':
+ y.append(""");
+ break;
+
+ case '\'':
+ y.append("'");
+ break;
+
+ default:
+ y.append(c);
+ }
+ }
+
+ return y.toString();
+ }
+
+ /**
+ * Registers a namespace writer for this XML writer.
+ *
+ * @param writer the namespace writer
+ */
+ public void register(NamespaceWriter writer) {
+
+ registry.put(writer.getNamespace(), writer);
+ }
+
+ /**
+ * Looks up a namespace writer for this XML writer.
+ *
+ * @param namespace the namespace to look up
+ * @return the namespace writer
+ */
+ public NamespaceWriter lookup(String namespace) {
+
+ return (NamespaceWriter) registry.get(namespace);
+ }
+}
Propchange: incubator/woden/trunk/java/src/org/apache/woden/ant/XMLWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/woden/trunk/java/src/org/apache/woden/ant/about-this-package
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org