Esempio n. 1
0
  public static Element[] filterChildElements(Element parent, String ns, String lname) {
    /*
    way too noisy
            if (LOGGER.isDebugEnabled()) {
                StringBuilder buf = new StringBuilder(100);
                buf.append("XmlaUtil.filterChildElements: ");
                buf.append(" ns=\"");
                buf.append(ns);
                buf.append("\", lname=\"");
                buf.append(lname);
                buf.append("\"");
                LOGGER.debug(buf.toString());
            }
    */

    List<Element> elems = new ArrayList<Element>();
    NodeList nlst = parent.getChildNodes();
    for (int i = 0, nlen = nlst.getLength(); i < nlen; i++) {
      Node n = nlst.item(i);
      if (n instanceof Element) {
        Element e = (Element) n;
        if ((ns == null || ns.equals(e.getNamespaceURI()))
            && (lname == null || lname.equals(e.getLocalName()))) {
          elems.add(e);
        }
      }
    }
    return elems.toArray(new Element[elems.size()]);
  }
  /**
   * Set a property of a resource to a value.
   *
   * @param name the property name
   * @param value the property value
   * @exception com.ibm.webdav.WebDAVException
   */
  public void setProperty(String name, Element value) throws WebDAVException {
    // load the properties
    Document propertiesDocument = resource.loadProperties();
    Element properties = propertiesDocument.getDocumentElement();
    String ns = value.getNamespaceURI();

    Element property = null;
    if (ns == null) {
      property = (Element) ((Element) properties).getElementsByTagName(value.getTagName()).item(0);
    } else {
      property = (Element) properties.getElementsByTagNameNS(ns, value.getLocalName()).item(0);
    }

    if (property != null) {
      try {
        properties.removeChild(property);
      } catch (DOMException exc) {
      }
    }

    properties.appendChild(propertiesDocument.importNode(value, true));

    // write out the properties
    resource.saveProperties(propertiesDocument);
  }
Esempio n. 3
0
  /**
   * This will invoke the <code>startElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param nsAtts <code>List</code> of namespaces to declare with the element or <code>null</code>.
   */
  private void startElement(Element element, Attributes nsAtts) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    // Allocate attribute list.
    AttributesImpl atts = (nsAtts != null) ? new AttributesImpl(nsAtts) : new AttributesImpl();

    List attributes = element.getAttributes();
    Iterator i = attributes.iterator();
    while (i.hasNext()) {
      Attribute a = (Attribute) i.next();
      atts.addAttribute(
          a.getNamespaceURI(),
          a.getName(),
          a.getQualifiedName(),
          getAttributeTypeName(a.getAttributeType()),
          a.getValue());
    }

    try {
      contentHandler.startElement(namespaceURI, localName, rawName, atts);
    } catch (SAXException se) {
      throw new JDOMException("Exception in startElement", se);
    }
  }
Esempio n. 4
0
  /**
   * This will invoke the <code>endElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   */
  private void endElement(Element element) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    try {
      contentHandler.endElement(namespaceURI, localName, rawName);
    } catch (SAXException se) {
      throw new JDOMException("Exception in endElement", se);
    }
  }
 protected final void init(Element xmlaRoot) throws XmlaException {
   if (NS_XMLA.equals(xmlaRoot.getNamespaceURI())) {
     String lname = xmlaRoot.getLocalName();
     if ("Discover".equals(lname)) {
       method = Method.DISCOVER;
       initDiscover(xmlaRoot);
     } else if ("Execute".equals(lname)) {
       method = Method.EXECUTE;
       initExecute(xmlaRoot);
     } else {
       // Note that is code will never be reached because
       // the error will be caught in
       // DefaultXmlaServlet.handleSoapBody first
       StringBuilder buf = new StringBuilder(100);
       buf.append(MSG_INVALID_XMLA);
       buf.append(": Bad method name \"");
       buf.append(lname);
       buf.append("\"");
       throw new XmlaException(
           CLIENT_FAULT_FC,
           HSB_BAD_METHOD_CODE,
           HSB_BAD_METHOD_FAULT_FS,
           Util.newError(buf.toString()));
     }
   } else {
     // Note that is code will never be reached because
     // the error will be caught in
     // DefaultXmlaServlet.handleSoapBody first
     StringBuilder buf = new StringBuilder(100);
     buf.append(MSG_INVALID_XMLA);
     buf.append(": Bad namespace url \"");
     buf.append(xmlaRoot.getNamespaceURI());
     buf.append("\"");
     throw new XmlaException(
         CLIENT_FAULT_FC,
         HSB_BAD_METHOD_NS_CODE,
         HSB_BAD_METHOD_NS_FAULT_FS,
         Util.newError(buf.toString()));
   }
 }
  private void initProperties(Element propertiesRoot) throws XmlaException {
    Map<String, String> properties = new HashMap<String, String>();
    Element[] childElems = XmlaUtil.filterChildElements(propertiesRoot, NS_XMLA, "PropertyList");
    if (childElems.length == 1) {
      NodeList nlst = childElems[0].getChildNodes();
      for (int i = 0, nlen = nlst.getLength(); i < nlen; i++) {
        Node n = nlst.item(i);
        if (n instanceof Element) {
          Element e = (Element) n;
          if (NS_XMLA.equals(e.getNamespaceURI())) {
            String key = e.getLocalName();
            String value = XmlaUtil.textInElement(e);

            if (LOGGER.isDebugEnabled()) {
              LOGGER.debug(
                  "DefaultXmlaRequest.initProperties: "
                      + " key=\""
                      + key
                      + "\", value=\""
                      + value
                      + "\"");
            }

            properties.put(key, value);
          }
        }
      }
    } else if (childElems.length > 1) {
      StringBuilder buf = new StringBuilder(100);
      buf.append(MSG_INVALID_XMLA);
      buf.append(": Wrong number of PropertyList elements: ");
      buf.append(childElems.length);
      throw new XmlaException(
          CLIENT_FAULT_FC,
          HSB_BAD_PROPERTIES_LIST_CODE,
          HSB_BAD_PROPERTIES_LIST_FAULT_FS,
          Util.newError(buf.toString()));
    } else {
    }
    this.properties = Collections.unmodifiableMap(properties);
  }
Esempio n. 7
0
  @Test
  public void testNamespaceURIPrefixLocalName() throws Exception {
    //		builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);

    String xml =
        "<?xml version=\"1.0\"?>"
            + "<t:root xmlns=\"http://void.com/\" xmlns:t=\"http://t.com/\">"
            + "<t:item/>"
            + "<child />"
            + "<t:item/>"
            + "</t:root>";
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
    Element root = doc.getDocumentElement();

    Assert.assertEquals("namespace uri", "http://t.com/", root.getNamespaceURI());
    Assert.assertEquals("local name", "root", root.getLocalName());
    Assert.assertEquals("prefix", "t", root.getPrefix());
    Assert.assertEquals("node name", "t:root", root.getNodeName());
  }
  // DOM output
  public void setupNamespace(Element element) {
    String uri = element.getNamespaceURI();
    String myPrefix = getPrefixByUri(uri);
    element.setPrefix(myPrefix);

    if (myPrefix != null) {
      IRNSContainer parent = (IRNSContainer) rnode_.getParentRNode();

      if (parent == null) {
        addPrefixDecl(element, myPrefix, uri);

        return;
      }

      RNSContext parentContext = parent.getRNSContext();
      String parentPrefix = parentContext.getPrefixByUri(uri);

      if (!myPrefix.equals(parentPrefix)) {
        addPrefixDecl(element, myPrefix, uri);
      }
    }
  }
 public XArchInstanceMetadata getInstanceMetadata() {
   return new XArchInstanceMetadata(XArchUtils.getPackageTitle(elt.getNamespaceURI()));
 }
  /**
   * Edit the properties of a resource. The updates must refer to a Document containing a WebDAV
   * propertyupdates element as the document root.
   *
   * @param updates an XML Document containing propertyupdate elements
   * @return the result of making the updates describing the edits to be made.
   * @exception com.ibm.webdav.WebDAVException
   */
  public MultiStatus setProperties(Document propertyUpdates) throws WebDAVException {
    // create a MultiStatus to hold the results. It will hold a MethodResponse
    // for each update, and one for the method as a whole
    MultiStatus multiStatus = new MultiStatus();
    boolean errorsOccurred = false;

    // first, load the properties so they can be edited
    Document propertiesDocument = resource.loadProperties();
    Element properties = (Element) propertiesDocument.getDocumentElement();

    // be sure the updates have at least one update
    Element propertyupdate = (Element) propertyUpdates.getDocumentElement();
    String tagName = propertyupdate.getNamespaceURI() + propertyupdate.getLocalName();

    if (!tagName.equals("DAV:propertyupdate")) {
      throw new WebDAVException(
          WebDAVStatus.SC_UNPROCESSABLE_ENTITY, "missing propertyupdate element");
    }

    NodeList updates = propertyupdate.getChildNodes();

    if (updates.getLength() == 0) {
      throw new WebDAVException(WebDAVStatus.SC_UNPROCESSABLE_ENTITY, "no updates in request");
    }

    Vector propsGood = new Vector(); // a list of properties that

    // were patched correctly or would have been if another
    // property hadn't gone bad.
    // apply the updates
    Node temp = null;

    for (int i = 0; i < updates.getLength(); i++) {
      temp = updates.item(i);

      // skip any ignorable TXText elements
      if (!(temp.getNodeType() == Node.ELEMENT_NODE)) {
        continue;
      }

      Element update = (Element) temp;
      int updateCommand = -1;
      tagName = update.getNamespaceURI() + update.getLocalName();

      if (tagName.equals("DAV:set")) {
        updateCommand = set;
      } else if (tagName.equals("DAV:remove")) {
        updateCommand = remove;
      } else {
        throw new WebDAVException(
            WebDAVStatus.SC_UNPROCESSABLE_ENTITY,
            update.getTagName() + " is not a valid property update request");
      }

      // iterate through the props in the set or remove element and update the
      // properties as directed
      Element prop = (Element) update.getElementsByTagNameNS("DAV:", "prop").item(0);

      if (prop == null) {
        throw new WebDAVException(
            WebDAVStatus.SC_UNPROCESSABLE_ENTITY, "no propeprties in update request");
      }

      NodeList propsToUpdate = prop.getChildNodes();

      for (int j = 0; j < propsToUpdate.getLength(); j++) {
        temp = propsToUpdate.item(j);

        // skip any TXText elements??
        if (!(temp.getNodeType() == Node.ELEMENT_NODE)) {
          continue;
        }

        Element propToUpdate = (Element) temp;

        // find the property in the properties element
        Element property = null;
        PropertyName propertyName = new PropertyName(propToUpdate);

        if (((Element) propToUpdate).getNamespaceURI() != null) {
          property =
              (Element)
                  properties
                      .getElementsByTagNameNS(
                          propToUpdate.getNamespaceURI(), propToUpdate.getLocalName())
                      .item(0);
        } else {
          property = (Element) properties.getElementsByTagName(propToUpdate.getTagName()).item(0);
        }

        boolean liveone = isLive(propertyName.asExpandedString());

        if (liveone) {
          errorsOccurred = true;

          PropertyResponse response = new PropertyResponse(resource.getURL().toString());
          response.addProperty(propertyName, propToUpdate, WebDAVStatus.SC_FORBIDDEN);
          multiStatus.addResponse(response);
        }

        // do the update
        if (updateCommand == set) {
          if (property != null) {
            try {
              properties.removeChild(property);
            } catch (DOMException exc) {
            }
          }

          if (!liveone) {
            // I don't think we're allowed to update live properties
            //    here.  Doing so effects the cache.  A case in
            //    point is the lockdiscoveryproperty.  properties
            //    is actually the properites cache "document" of this
            //    resource.  Even though we don't "save" the request
            //    if it includes live properties, we don't remove
            //    it from the cache after we'd set it here, so it
            //    can affect other queries. (jlc 991002)
            properties.appendChild(propertiesDocument.importNode(propToUpdate, true));

            propsGood.addElement(propToUpdate);
          }
        } else if (updateCommand == remove) {
          try {
            if (property != null) {
              properties.removeChild(property);
              propsGood.addElement(propToUpdate);
            }
          } catch (DOMException exc) {
          }
        }
      }
    }

    {
      Enumeration els = propsGood.elements();

      for (; els.hasMoreElements(); ) {
        Object ob1 = els.nextElement();
        Element elProp = (Element) ob1;
        PropertyName pn = new PropertyName(elProp);
        PropertyResponse response = new PropertyResponse(resource.getURL().toString());
        response.addProperty(
            pn,
            (Element) elProp.cloneNode(false),
            (errorsOccurred ? WebDAVStatus.SC_FAILED_DEPENDENCY : WebDAVStatus.SC_OK));

        // todo: add code for responsedescription
        multiStatus.addResponse(response);
      }
    }

    // write out the properties
    if (!errorsOccurred) {
      resource.saveProperties(propertiesDocument);
    }

    return multiStatus;
  }
  private void initRestrictions(Element restrictionsRoot) throws XmlaException {
    Map<String, List<String>> restrictions = new HashMap<String, List<String>>();
    Element[] childElems =
        XmlaUtil.filterChildElements(restrictionsRoot, NS_XMLA, "RestrictionList");
    if (childElems.length == 1) {
      NodeList nlst = childElems[0].getChildNodes();
      for (int i = 0, nlen = nlst.getLength(); i < nlen; i++) {
        Node n = nlst.item(i);
        if (n instanceof Element) {
          Element e = (Element) n;
          if (NS_XMLA.equals(e.getNamespaceURI())) {
            String key = e.getLocalName();
            String value = XmlaUtil.textInElement(e);

            List<String> values;
            if (restrictions.containsKey(key)) {
              values = restrictions.get(key);
            } else {
              values = new ArrayList<String>();
              restrictions.put(key, values);
            }

            if (LOGGER.isDebugEnabled()) {
              LOGGER.debug(
                  "DefaultXmlaRequest.initRestrictions: "
                      + " key=\""
                      + key
                      + "\", value=\""
                      + value
                      + "\"");
            }

            values.add(value);
          }
        }
      }
    } else if (childElems.length > 1) {
      StringBuilder buf = new StringBuilder(100);
      buf.append(MSG_INVALID_XMLA);
      buf.append(": Wrong number of RestrictionList elements: ");
      buf.append(childElems.length);
      throw new XmlaException(
          CLIENT_FAULT_FC,
          HSB_BAD_RESTRICTION_LIST_CODE,
          HSB_BAD_RESTRICTION_LIST_FAULT_FS,
          Util.newError(buf.toString()));
    }

    // If there is a Catalog property,
    // we have to consider it a constraint as well.
    String key = org.olap4j.metadata.XmlaConstants.Literal.CATALOG_NAME.name();

    if (this.properties.containsKey(key) && !restrictions.containsKey(key)) {
      List<String> values;
      values = new ArrayList<String>();
      restrictions.put(this.properties.get(key), values);

      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(
            "DefaultXmlaRequest.initRestrictions: "
                + " key=\""
                + key
                + "\", value=\""
                + this.properties.get(key)
                + "\"");
      }
    }

    this.restrictions = (Map) Collections.unmodifiableMap(restrictions);
  }