- From: Denis Tea via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 19 Feb 2008 12:51:18 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/org/w3c/unicorn/contract
In directory hutz:/tmp/cvs-serv375/org/w3c/unicorn/contract
Modified Files:
WADLUnmarshallerXPath.java
Log Message:
New contract (WADL only).
Index: WADLUnmarshallerXPath.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/contract/WADLUnmarshallerXPath.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- WADLUnmarshallerXPath.java 31 Aug 2006 09:09:21 -0000 1.1.1.1
+++ WADLUnmarshallerXPath.java 19 Feb 2008 12:51:16 -0000 1.2
@@ -12,6 +12,8 @@
import java.util.List;
import java.util.Map;
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -28,6 +30,7 @@
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.w3c.unicorn.util.LocalizedString;
import org.xml.sax.SAXException;
/**
@@ -41,20 +44,38 @@
private static NamespaceContext aNamespaceContext;
- private Map<String, List<String>> mapOfListOfStringType;
- private List<CallMethod> listOfCallMethod;
+ private List<CallMethod> listOfCallMethod = new ArrayList<CallMethod>();
private DocumentBuilderFactory aDocumentBuilderFactory;
private DocumentBuilder aDocumentBuilder;
private Document aDocument;
private XPath aXPath;
+
+
+ /**
+ * Description of a observer to complete with information from a RDF file.
+ */
+ //private ObserverDescription aObserverDescription = null;
+
+ private String sID = new String();
+ private LocalizedString aLocalizedStringName = new LocalizedString();
+ private LocalizedString aLocalizedStringDescription = new LocalizedString();
+ private LocalizedString aLocalizedStringHelpLocation = new LocalizedString();
+ private LocalizedString aLocalizedStringProvider = new LocalizedString();
+ private List<MimeType> listOfMimeType = new ArrayList<MimeType>();
+
+ //name of parameter lang if observer has one
+ private String nameOfLangParameter = null;
+
+ /**
+ * Map of different input method handle by the observer.
+ */
+ private Map<EnumInputMethod, InputMethod> mapOfInputMethod = new LinkedHashMap<EnumInputMethod, InputMethod>();
+
public WADLUnmarshallerXPath () throws ParserConfigurationException {
WADLUnmarshallerXPath.logger.trace("Constructor");
- this.mapOfListOfStringType = new LinkedHashMap<String, List<String>>();
- this.listOfCallMethod = new ArrayList<CallMethod>();
-
this.aDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
this.aDocumentBuilder = this.aDocumentBuilderFactory.newDocumentBuilder();
this.aXPath = XPathFactory.newInstance().newXPath();
@@ -70,32 +91,71 @@
this.aDocument = this.aDocumentBuilder.parse(aURL.openStream());
}
+
+
+
+
/* (non-Javadoc)
* @see org.w3c.unicorn.contract.WADLUnmarshaller#unmarshal(java.net.URL)
*/
- public void unmarshal () throws
- XPathExpressionException,
- ParserConfigurationException,
- SAXException,
- IOException {
+ public void unmarshal() throws XPathExpressionException,
+ ParserConfigurationException, SAXException, IOException, MimeTypeParseException {
WADLUnmarshallerXPath.logger.trace("unmarshal");
-
- this.parseTypes();
+ this.parseDocsHeader();
this.parseMethods();
}
- private void parseMethods () throws
- ParserConfigurationException,
- SAXException,
- IOException,
- XPathExpressionException {
+ private void parseDocsHeader() throws XPathExpressionException, MimeTypeParseException {
+ final Node aNodeResource = this.aDocument.getElementsByTagName("resources").item(0);
+ XPathExpression aXPathExpression = this.aXPath.compile("//resource/doc");
+ NodeList aNodeListResult = (NodeList) aXPathExpression.evaluate(aNodeResource,XPathConstants.NODESET);
+ for (int i=0; i<aNodeListResult.getLength(); i++) {
+ Node nodeDoc = aNodeListResult.item(i);
+
+ String vText = nodeDoc.getTextContent();
+
+ //parcours les attrb d un doc
+ String vTitle = null;
+ String vLang = null;
+ NamedNodeMap nnm = nodeDoc.getAttributes();
+ for (int j=0; j<nnm.getLength(); j++) {
+ String attrName = nnm.item(j).getNodeName();
+ String attrValue = nnm.item(j).getNodeValue();
+ if ("title".equals(attrName)) {
+ vTitle = attrValue;
+ } else if ("xml:lang".equals(attrName)) {
+ vLang = attrValue;
+ }
+ }
+
+ if ("name".equals(vTitle)) {
+ aLocalizedStringName.addLocalization(vLang, vText);
+ } else if ("description".equals(vTitle)) {
+ aLocalizedStringDescription.addLocalization(vLang, vText);
+ } else if ("help".equals(vTitle)) {
+ aLocalizedStringHelpLocation.addLocalization(vLang, vText);
+ } else if ("provider".equals(vTitle)) {
+ aLocalizedStringProvider.addLocalization(vLang, vText);
+ } else if ("paramLang".equals(vTitle)) {
+ nameOfLangParameter=vText;
+ } else if ("mimetype".equals(vTitle)) {
+ listOfMimeType.add(new MimeType(vText));
+ } else if ("reference".equals(vTitle)) {
+ sID=vText;
+ }
+ }
+ }
+
+ private void parseMethods() throws ParserConfigurationException,
+ SAXException, IOException, XPathExpressionException {
WADLUnmarshallerXPath.logger.trace("parseMethods");
// base uri
final Node aNodeResource = this.aDocument.getElementsByTagName("resources").item(0);
final String sBaseURI = aNodeResource.getAttributes().getNamedItem("base").getNodeValue();
- final NodeList aNodeListMethod = this.aDocument.getElementsByTagName("method");
+ final NodeList aNodeListMethod = this.aDocument
+ .getElementsByTagName("method");
for (int i = 0; i < aNodeListMethod.getLength(); i++) {
final Node aNodeMethod = aNodeListMethod.item(i);
@@ -105,25 +165,23 @@
// URI of the resource (will be appended to the base URI)
final String sResourceURI;
- sResourceURI = aNodeMethod.getParentNode().getAttributes().getNamedItem("uri").getNodeValue();
+ sResourceURI = aNodeMethod.getParentNode().getAttributes().getNamedItem("path").getNodeValue();
- // Type : GET or POST and id of the method
+ // Type : GET/POST and id of the method
final NamedNodeMap aNamedNodeMapAttribute = aNodeMethod.getAttributes();
final String sName = aNamedNodeMapAttribute.getNamedItem("name").getNodeValue();
final boolean bPost = "POST".equals(sName.trim());
final String sMethodID = aNamedNodeMapAttribute.getNamedItem("id").getNodeValue().trim();
// Query variables
- final XPathExpression aXPathExpression;
- aXPathExpression = this.aXPath.compile("//method[@id='" + sMethodID + "']//query_variable");
- final NodeList aNodeListResult;
- aNodeListResult = (NodeList) aXPathExpression.evaluate(aNodeMethod, XPathConstants.NODESET);
-
- // iterate over query_variable list
+ XPathExpression aXPathExpression = this.aXPath.compile("//method[@id='" + sMethodID + "']//param");
+ NodeList aNodeListResult = (NodeList) aXPathExpression.evaluate(aNodeMethod,XPathConstants.NODESET);
+
+ // iterate over param list
for (int j = 0; j < aNodeListResult.getLength(); j++) {
final NamedNodeMap aNamedNodeMap = aNodeListResult.item(j).getAttributes();
final CallParameter aCallParameter = new CallParameter();
-
+
// iterate over attributes
for (int k = 0; k < aNamedNodeMap.getLength(); k++) {
final Node aNodeCurrentAttribute = aNamedNodeMap.item(k);
@@ -133,65 +191,105 @@
if ("name".equals(sAttributeName)) {
aCallParameter.setName(sAttributeValue);
- }
- else if ("type".equals(sAttributeName)) {
- if (sAttributeValue.equals("xs:string")) {
- aCallParameter.addValue("");
- }
- else {
- aCallParameter.setPossibleValues(
- this.mapOfListOfStringType.get(sAttributeValue));
- }
- }
- else if ("required".equals(sAttributeName)) {
+ } else if ("required".equals(sAttributeName)) {
aCallParameter.setRequired("true".equals(sAttributeValue));
- }
- else if ("repeating".equals(sAttributeName)) {
+ } else if ("repeating".equals(sAttributeName)) {
aCallParameter.setRepeating("true".equals(sAttributeValue));
+ } else if ("fixed".equals(sAttributeName)) {
+ aCallParameter.setFixed(sAttributeValue);
+ } else if ("style".equals(sAttributeName)) {
+ aCallParameter.setStyle(sAttributeValue);
+ } else if ("id".equals(sAttributeName)) {
+ aCallParameter.setID(sAttributeValue);
+ } else if ("path".equals(sAttributeName)) {
+ aCallParameter.setPath(sAttributeValue);
+ } else if ("default".equals(sAttributeName)) {
+ aCallParameter.setDefaultValue(sAttributeValue);
}
- else if ("fixed".equals(sAttributeName)) {
- aCallParameter.setFixed(sAttributeValue);
- }
} // iterate over attributes
-
- mapOfCallParameter.put(new String(aCallParameter.getName()), aCallParameter);
+
+ // read option type
+
+ XPathExpression aOptionXPathExpression = this.aXPath.compile("//method[@id='"+sMethodID+"']//request//param[@name='"+aCallParameter.getName()+"']//option");
+ NodeList aOptionNodeListResult = (NodeList) aOptionXPathExpression.evaluate(aNodeMethod,XPathConstants.NODESET);
+
+ for (int k=0; k < aOptionNodeListResult.getLength(); k++) {
+ aCallParameter.addValue(aOptionNodeListResult.item(k).getAttributes().item(0).getNodeValue());
+ }
+
+ mapOfCallParameter.put(new String(aCallParameter.getName()),aCallParameter);
+
} // iterate over query_variable list
-
- final CallMethod aCallMethod = new CallMethod(
- new URL(sBaseURI + sResourceURI),
- bPost,
- sName,
- sMethodID,
+
+
+ final CallMethod aCallMethod = new CallMethod(new URL(sBaseURI
+ + sResourceURI), bPost, sName, sMethodID,
mapOfCallParameter);
this.listOfCallMethod.add(aCallMethod);
- }
- }
-
- /**
- *
- */
- private void parseTypes() {
- WADLUnmarshallerXPath.logger.trace("parseTypes");
-
- final NodeList aNodeList = this.aDocument.getElementsByTagName("xs:choice");
-
- for (int k = 0; k < aNodeList.getLength(); k++) {
- final Node aNode = aNodeList.item(k);
- final String sType = aNode.getParentNode().getParentNode().getAttributes().getNamedItem("name").getNodeValue();
- final NodeList aNodeListChildren = aNode.getChildNodes();
-
- // Values of the current type
- final ArrayList<String> listOfValue = new ArrayList<String>();
- for (int l = 0; l < aNodeListChildren.getLength(); l++) {
- final Node aNodeChild = aNodeListChildren.item(l);
- if (aNodeChild.getNodeType() == Node.ELEMENT_NODE) {
- listOfValue.add(aNodeChild.getAttributes().getNamedItem("name").getNodeValue());
+
+
+ //remplir mapOfInputMethod
+
+ NodeList listChildMethod = aNodeMethod.getChildNodes();
+ String sInputMethod=null;
+ String sInputParamName=null;
+ for (int j = 0; j < listChildMethod.getLength(); j++) {
+ Node childMethod = listChildMethod.item(j);
+ if ("doc".equals(childMethod.getNodeName())) {
+ String firstAttrName = childMethod.getAttributes().item(0).getNodeName();
+ if ("title".equals(firstAttrName)) {
+ String firstAttrValue = childMethod.getAttributes().item(0).getNodeValue();
+ if ("inputMethod".equals(firstAttrValue))
+ sInputMethod = childMethod.getTextContent();
+ else if ("inputParamName".equals(firstAttrValue))
+ sInputParamName = childMethod.getTextContent();
+ }
}
}
- this.mapOfListOfStringType.put(sType, listOfValue);
+
+ InputMethod aInputMethod = new InputMethod();
+ aInputMethod.setCallMethod(aCallMethod);
+ aInputMethod.setCallParameter(aCallMethod.getCallParameterByName(sInputParamName));
+ aInputMethod.setListOfMimeType(this.listOfMimeType);
+ //aInputMethod.setCallParameter(aInputMethod.getCallMethod().getMapOfCallParameter().get(sParameterName));
+ if ("URI".equals(sInputMethod)) {
+ this.mapOfInputMethod.put(EnumInputMethod.URI, aInputMethod);
+ } else if ("UPLOAD".equals(sInputMethod)){
+ this.mapOfInputMethod.put(EnumInputMethod.UPLOAD, aInputMethod);
+ } else if ("DIRECT".equals(sInputMethod)){
+ this.mapOfInputMethod.put(EnumInputMethod.DIRECT, aInputMethod);
+ }
+
+
+
+
+
}
}
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/* (non-Javadoc)
* @see org.w3c.unicorn.contract.WADLUnmarshaller#getMethods()
*/
@@ -199,12 +297,6 @@
return this.listOfCallMethod;
}
- public static void main (final String[] args) throws Exception {
- final WADLUnmarshaller t = new WADLUnmarshallerXPath();
- t.addURL(new URL("http://w3cstag8/~jean/xml/css-validator.wadl"));
- t.unmarshal();
- }
-
static {
WADLUnmarshallerXPath.aNamespaceContext = new NamespaceContext() {
public String getNamespaceURI(final String sPrefix) {
@@ -239,4 +331,53 @@
};
}
+
+ public LocalizedString getDescription() {
+ return this.aLocalizedStringDescription;
+ }
+
+ public LocalizedString getHelpLocation() {
+ return this.aLocalizedStringHelpLocation;
+ }
+
+ public String getID() {
+ return this.sID;
+ }
+
+ public Map<EnumInputMethod, InputMethod> getMapOfInputMethod() {
+ return this.mapOfInputMethod;
+ }
+
+ public LocalizedString getName() {
+ return this.aLocalizedStringName;
+ }
+
+ public String getNameOfLangParameter() {
+ return this.nameOfLangParameter;
+ }
+
+ public LocalizedString getProvider() {
+ return this.aLocalizedStringProvider;
+ }
+
+ public static void main (final String[] args) throws Exception {
+ final WADLUnmarshaller t = new WADLUnmarshallerXPath();
+ t.addURL(new URL("http://localhost/css.wadl"));
+ t.unmarshal();
+ System.out.println(t.getID());
+
+ /*
+ for (CallMethod cm : t.getListOfCallMethod()) {
+ System.out.println(cm);
+ System.out.println("---------------------------------");
+ }
+ */
+ System.out.println(t.getMapOfInputMethod());
+ System.out.println("***************************************");
+ for (InputMethod im : t.getMapOfInputMethod().values()) {
+ System.out.println(im.getCallParameter());
+ System.out.println("---------------------------------");
+ }
+ }
+
}
Received on Tuesday, 19 February 2008 12:51:25 UTC