Ejemplo n.º 1
0
  public void endElement(String namespaceURI, String localName, String qName) throws SAXException {

    SAXEvent saxEvent = new SAXEvent(SAXEvent.END_ELEMENT);
    saxEvent.addParm(namespaceURI);
    saxEvent.addParm(localName);
    saxEvent.addParm(qName);
    events.add(saxEvent);

    // check to see if a we issued a start prefix mapping event
    // for DOMDocument namespace decls

    QName elementName = null;
    if (namespaceURI != null) {
      elementName = new QName(localName, Namespace.get(namespaceURI));
    } else {
      elementName = new QName(localName);
    }

    List prefixes = (List) prefixMappings.get(elementName);
    if (prefixes != null) {
      Iterator itr = prefixes.iterator();
      while (itr.hasNext()) {
        SAXEvent prefixEvent = new SAXEvent(SAXEvent.END_PREFIX_MAPPING);
        prefixEvent.addParm(itr.next());
        events.add(prefixEvent);
      }
    }
  }
Ejemplo n.º 2
0
public class VoiceAdminConstants {
  public static final String NAMESPACE_STR = AdminConstants.NAMESPACE_STR;
  public static final Namespace NAMESPACE = Namespace.get(NAMESPACE_STR);

  public static final String E_GET_ALL_UC_PROVIDERS_REQUEST = "GetAllUCProvidersRequest";
  public static final String E_GET_ALL_UC_PROVIDERS_RESPONSE = "GetAllUCProvidersResponse";
  public static final String E_UPDATE_PRESENCE_SESSION_ID_REQUEST =
      "UpdatePresenceSessionIdRequest";
  public static final String E_UPDATE_PRESENCE_SESSION_ID_RESPONSE =
      "UpdatePresenceSessionIdResponse";

  public static final QName GET_ALL_UC_PROVIDERS_REQUEST =
      QName.get(E_GET_ALL_UC_PROVIDERS_REQUEST, NAMESPACE);
  public static final QName GET_ALL_UC_PROVIDERS_RESPONSE =
      QName.get(E_GET_ALL_UC_PROVIDERS_RESPONSE, NAMESPACE);
  public static final QName UPDATE_PRESENCE_SESSION_ID_REQUEST =
      QName.get(E_UPDATE_PRESENCE_SESSION_ID_REQUEST, NAMESPACE);
  public static final QName UPDATE_PRESENCE_SESSION_ID_RESPONSE =
      QName.get(E_UPDATE_PRESENCE_SESSION_ID_RESPONSE, NAMESPACE);

  public static final String E_PROVIDER = "provider";
}
Ejemplo n.º 3
0
public class FeedUtils {

  private static final Namespace CMISRA =
      Namespace.get("http://docs.oasis-open.org/ns/cmis/restatom/200908/");
  private static final Namespace CMIS =
      Namespace.get("http://docs.oasis-open.org/ns/cmis/core/200908/");

  private static final QName CMISRA_REPO_INFO = QName.get("repositoryInfo", CMISRA);
  private static final QName CMIS_REPO_NAME = QName.get("repositoryName", CMIS);
  private static final QName CMIS_REPO_CAPABILITES = QName.get("capabilities", CMIS);
  private static final QName CMIS_REPO_ACL_CAPABILITES = QName.get("aclCapability", CMIS);
  private static final QName CMISRA_COLLECTION_TYPE = QName.get("collectionType", CMISRA);
  private static final QName CMISRA_URI_TEMPLATE = QName.get("uritemplate", CMISRA);
  private static final QName CMISRA_TYPE = QName.get("type", CMISRA);
  private static final QName CMISRA_TEMPLATE = QName.get("template", CMISRA);
  private static final QName CMISRA_OBJECT = QName.get("object", CMISRA);
  private static final QName CMISRA_NUMITEMS = QName.get("numItems", CMISRA);
  private static final QName CMIS_PROPERTIES = QName.get("properties", CMIS);
  private static final QName CMIS_VALUE = QName.get("value", CMIS);

  public static Document readAtomFeed(final String feed, final String user, final String password)
      throws FeedLoadException {
    Document document = null;
    try {
      InputStream is = HttpUtils.getWebRessourceAsStream(feed, user, password);
      SAXReader reader = new SAXReader(); // dom4j SAXReader
      document = reader.read(is); // dom4j Document

    } catch (ClientProtocolException e) {
      throw new FeedLoadException(e);
    } catch (IOException e) {
      throw new FeedLoadException(e);
    } catch (DocumentException e) {
      throw new FeedLoadException(e);
    } catch (Exception e) {
      throw new FeedLoadException(e);
    }
    return document;
  }

  public static List<String> getRootFeedsFromRepo(String url, String user, String password)
      throws Exception {
    try {
      Document doc = readAtomFeed(url, user, password);
      return getWorkspacesFromRepoFeed(doc);
    } catch (Exception e) {
      throw new Exception("Wrong Parameters");
    }
  }

  public static List<String> getWorkspacesFromRepoFeed(Document doc) {
    List<String> listWorkspace = new ArrayList<String>(2);
    if (doc != null) {
      List<Element> workspaces = doc.getRootElement().elements("workspace");
      if (workspaces.size() > 0) {
        for (Element workspace : workspaces) {
          Element repoInfo = workspace.element(CMISRA_REPO_INFO);
          Element repoId = repoInfo.element(CMIS_REPO_NAME);
          listWorkspace.add(repoId.getText());
        }
      }
    }
    return listWorkspace;
  }

  public static String getCollectionUrlFromRepoFeed(String type, Element workspace) {
    if (workspace != null) {

      List<Element> collections = workspace.elements("collection");

      for (Element collection : collections) {
        String currentType = collection.elementText(CMISRA_COLLECTION_TYPE);
        if (type.equals(currentType.toLowerCase())) {
          return collection.attributeValue("href");
        }
      }
    }
    return "";
  }

  public static int getNumItemsFeed(Document doc) {
    if (doc != null) {
      Element numItems = doc.getRootElement().element(CMISRA_NUMITEMS);
      if (numItems != null) {
        return Integer.parseInt(numItems.getText());
      }
    }
    return 0;
  }

  public static Element getWorkspace(Document doc, String workspaceName) {
    List<Element> workspaces = doc.getRootElement().elements("workspace");
    Element workspace = null;
    if (workspaces.size() > 0) {
      for (Element wSpace : workspaces) {
        Element repoInfo = wSpace.element(CMISRA_REPO_INFO);
        Element repoId = repoInfo.element(CMIS_REPO_NAME);
        if (workspaceName.equals(repoId.getData())) {
          return workspace = wSpace;
        }
      }
    } else {
      workspace = null;
    }
    return workspace;
  }

  public static Element getWorkspace(String workspace, String url, String user, String password)
      throws Exception {
    return getWorkspace(readAtomFeed(url, user, password), workspace);
  }

  public static String getSearchQueryFeedTitle(String urlTemplate, String query, boolean isExact) {
    if (isExact) {
      return getSearchQueryFeedCmisQuery(
          urlTemplate, "SELECT * FROM cmis:document WHERE cmis:name LIKE '" + query + "'");
    } else {
      return getSearchQueryFeedCmisQuery(
          urlTemplate, "SELECT * FROM cmis:document WHERE cmis:name LIKE '%" + query + "%'");
    }
  }

  public static String getSearchQueryFeedFolderTitle(
      String urlTemplate, String query, boolean isExact) {
    if (isExact) {
      return getSearchQueryFeedCmisQuery(
          urlTemplate, "SELECT * FROM cmis:folder WHERE cmis:name LIKE '" + query + "'");
    } else {
      return getSearchQueryFeedCmisQuery(
          urlTemplate, "SELECT * FROM cmis:folder WHERE cmis:name LIKE '%" + query + "%'");
    }
  }

  public static String getSearchQueryFeed(String urlTemplate, String query) {
    final CharSequence feedUrl =
        TextUtils.replace(
            urlTemplate,
            new String[] {
              "{q}",
              "{searchAllVersions}",
              "{maxItems}",
              "{skipCount}",
              "{includeAllowableActions}",
              "{includeRelationships}"
            },
            new String[] {query, "false", "50", "0", "false", "false"});

    return feedUrl.toString();
  }

  public static String getSearchQueryFeedFullText(String urlTemplate, String query) {
    String[] words = TextUtils.split(query.trim(), "\\s+");

    for (int i = 0; i < words.length; i++) {
      words[i] = "contains ('" + words[i] + "')";
    }

    String condition = TextUtils.join(" AND ", words);

    return getSearchQueryFeedCmisQuery(
        urlTemplate, "SELECT * FROM cmis:document WHERE " + condition);
  }

  public static String getSearchQueryFeedCmisQuery(String urlTemplate, String cmisQuery) {
    String encodedCmisQuery = "";
    try {
      encodedCmisQuery = URLEncoder.encode(cmisQuery, "iso-8859-1");
    } catch (UnsupportedEncodingException e) {
      encodedCmisQuery = URLEncoder.encode(cmisQuery);
    }

    final CharSequence feedUrl =
        TextUtils.replace(
            urlTemplate,
            new String[] {
              "{q}",
              "{searchAllVersions}",
              "{maxItems}",
              "{skipCount}",
              "{includeAllowableActions}",
              "{includeRelationships}"
            },
            new String[] {encodedCmisQuery, "false", "50", "0", "false", "false"});

    return feedUrl.toString();
  }

  public static String getUriTemplateFromRepoFeed(String type, Element workspace) {

    List<Element> templates = workspace.elements(CMISRA_URI_TEMPLATE);

    for (Element template : templates) {
      String currentType = template.elementText(CMISRA_TYPE);
      if (type.equals(currentType.toLowerCase())) {
        return template.elementText(CMISRA_TEMPLATE);
      }
    }
    return null;
  }

  public static Map<String, CmisProperty> getCmisPropertiesForEntry(Element feedEntry) {
    Map<String, CmisProperty> props = new HashMap<String, CmisProperty>();

    Element objectElement = feedEntry.element(CMISRA_OBJECT);
    if (objectElement != null) {
      Element properitesElement = objectElement.element(CMIS_PROPERTIES);
      if (properitesElement != null) {
        List<Element> properties = properitesElement.elements();

        for (Element property : properties) {
          final String id = property.attributeValue("propertyDefinitionId");

          props.put(
              id,
              new CmisProperty(
                  property.getName(),
                  id,
                  property.attributeValue("localName"),
                  property.attributeValue("displayName"),
                  property.elementText(CMIS_VALUE)));
        }
      }
    }
    return props;
  }

  public static Map<String, ArrayList<CmisProperty>> getCmisRepositoryProperties(
      Element feedEntry) {
    Map<String, ArrayList<CmisProperty>> infoServerList =
        new HashMap<String, ArrayList<CmisProperty>>();
    ArrayList<CmisProperty> propsList = new ArrayList<CmisProperty>();
    ArrayList<CmisProperty> propsCapabilities = new ArrayList<CmisProperty>();
    ArrayList<CmisProperty> propsACLCapabilities = new ArrayList<CmisProperty>();

    Element objectElement = feedEntry.element(CMISRA_REPO_INFO);
    if (objectElement != null) {
      List<Element> properties = objectElement.elements();
      for (Element property : properties) {
        if (CMIS_REPO_CAPABILITES.equals(property.getQName())) {
          List<Element> props = property.elements();
          for (Element prop : props) {
            propsCapabilities.add(
                new CmisProperty(
                    null, null, null, prop.getName().replace("capability", ""), prop.getText()));
          }
        } else if (CMIS_REPO_ACL_CAPABILITES.equals(property.getQName())) {
          /*List<Element> props = property.elements();
          for (Element prop : props) {
          	propsACLCapabilities.add(new CmisProperty(null, null, null, prop.getName().replace("cmis:", ""), prop.getText()));
          }*/
        } else {
          propsList.add(new CmisProperty(null, null, null, property.getName(), property.getText()));
        }
      }
      infoServerList.put(Server.INFO_GENERAL, propsList);
      infoServerList.put(Server.INFO_CAPABILITIES, propsCapabilities);
      infoServerList.put(Server.INFO_ACL_CAPABILITIES, propsACLCapabilities);
    }
    return infoServerList;
  }
}
Ejemplo n.º 4
0
  public void startElement(
      String namespaceURI, String localName, String qualifiedName, Attributes attributes)
      throws SAXException {
    SAXEvent saxEvent = new SAXEvent(SAXEvent.START_ELEMENT);
    saxEvent.addParm(namespaceURI);
    saxEvent.addParm(localName);
    saxEvent.addParm(qualifiedName);

    QName qName = null;
    if (namespaceURI != null) {
      qName = new QName(localName, Namespace.get(namespaceURI));
    } else {
      qName = new QName(localName);
    }

    if ((attributes != null) && (attributes.getLength() > 0)) {
      List attParmList = new ArrayList(attributes.getLength());
      String[] attParms = null;

      for (int i = 0; i < attributes.getLength(); i++) {

        String attLocalName = attributes.getLocalName(i);

        if (attLocalName.startsWith(XMLNS)) {

          // if SAXWriter is writing a DOMDocument, namespace
          // decls are treated as attributes. record a start
          // prefix mapping event
          String prefix = null;
          if (attLocalName.length() > 5) {
            prefix = attLocalName.substring(6);
          } else {
            prefix = EMPTY_STRING;
          }

          SAXEvent prefixEvent = new SAXEvent(SAXEvent.START_PREFIX_MAPPING);
          prefixEvent.addParm(prefix);
          prefixEvent.addParm(attributes.getValue(i));
          events.add(prefixEvent);

          // 'register' the prefix so that we can generate
          // an end prefix mapping event within endElement
          List prefixes = (List) prefixMappings.get(qName);
          if (prefixes == null) {
            prefixes = new ArrayList();
            prefixMappings.put(qName, prefixes);
          }
          prefixes.add(prefix);

        } else {

          attParms = new String[5];
          attParms[0] = attributes.getURI(i);
          attParms[1] = attLocalName;
          attParms[2] = attributes.getQName(i);
          attParms[3] = attributes.getType(i);
          attParms[4] = attributes.getValue(i);
          attParmList.add(attParms);
        }
      }

      saxEvent.addParm(attParmList);
    }

    events.add(saxEvent);
  }
Ejemplo n.º 5
0
 public Namespace createNamespace(String uri) {
   return new NamespaceImpl(org.dom4j.Namespace.get(uri));
 }