Exemple #1
0
void t4p::UrlTagFinderClass::DeleteUrl(const wxURI& url, const std::vector<wxFileName>& sourceDirs) {
    if (sourceDirs.empty()) {
        return;
    }
    std::string stdUrl = t4p::WxToChar(url.BuildURI());
    try {
        std::vector<std::string> stdSourceDirs;
        std::string sql = "DELETE FROM url_tags WHERE url = ? AND source_id IN(SELECT source_id FROM sources WHERE directory IN(";
        for (size_t i = 0; i < sourceDirs.size(); ++i) {
            stdSourceDirs.push_back(t4p::WxToChar(sourceDirs[i].GetPathWithSep()));
            if (0 == i) {
                sql += "?";
            } else {
                sql += ",?";
            }
        }
        sql += "))";
        soci::statement stmt = Session.prepare << sql;
        stmt.exchange(soci::use(stdUrl));
        for (size_t i = 0; i < stdSourceDirs.size(); ++i) {
            stmt.exchange(soci::use(stdSourceDirs[i]));
        }
        stmt.define_and_bind();
        stmt.execute(true);
    } catch (std::exception& e) {
        wxUnusedVar(e);
        wxString msg = t4p::CharToWx(e.what());
        wxASSERT_MSG(false, msg);
    }
}
void  t4p::RunBrowserFeatureClass::ExternalBrowser(const wxString& browserName, const wxURI& url) {
    wxFileName webBrowserPath;
    bool found = App.PhpModule.Environment.FindBrowserByName(browserName, webBrowserPath);
    if (!found || !webBrowserPath.IsOk()) {
        t4p::EditorLogWarning(t4p::ERR_BAD_WEB_BROWSER_EXECUTABLE, webBrowserPath.GetFullPath());
        return;
    }
    wxString cmd = wxT("\"") + webBrowserPath.GetFullPath() + wxT("\"");

    wxPlatformInfo info;
    if (info.GetOperatingSystemId() == wxOS_MAC_OSX_DARWIN && browserName.CmpNoCase(wxT("Safari")) == 0) {
        // safari on Mac does not handle command line URL arguments
        // need to use the "open" program
        // see http://superuser.com/questions/459268/run-safari-from-command-line-with-url-parameter
        cmd = wxT("open -a safari ");
    }
    cmd += wxT(" \"");
    cmd += url.BuildURI();
    cmd += wxT("\"");

    // dont track this PID, let the browser stay open if the editor is closed.
    // if we dont do pass the make group leader flag the browser thinks it crashed and will tell the user
    // that the browser crashed.
    long pid = wxExecute(cmd, wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER);
    if (pid <= 0) {
        t4p::EditorLogWarning(t4p::ERR_BAD_WEB_BROWSER_EXECUTABLE, cmd);
    }
}
Exemple #3
0
bool t4p::UrlTagFinderClass::FindByUrl(const wxURI& url, const std::vector<wxFileName>& sourceDirs, t4p::UrlTagClass& urlTag) {
    bool ret = false;
    if (sourceDirs.empty()) {
        return ret;
    }
    std::string stdUrlWhere = t4p::WxToChar(url.BuildURI());
    std::string stdUrl;
    std::string stdFullPath;
    std::string stdClassName;
    std::string stdMethodName;
    std::string sql = "SELECT url, full_path, class_name, method_name ";
    sql += "FROM url_tags LEFT JOIN sources ON sources.source_id = url_tags.source_id ";
    sql += "WHERE  url = ? AND directory IN(";
    std::vector<std::string> stdSourceDirs;
    for (size_t i = 0; i < sourceDirs.size(); ++i) {
        stdSourceDirs.push_back(t4p::WxToChar(sourceDirs[i].GetPathWithSep()));
        if (0 == i) {
            sql += "?";
        } else {
            sql += ",?";
        }
    }
    sql += ")";
    try {
        soci::statement stmt = Session.prepare << sql;
        stmt.exchange(soci::use(stdUrlWhere));
        for (size_t i = 0; i < stdSourceDirs.size(); ++i) {
            stmt.exchange(soci::use(stdSourceDirs[i]));
        }
        stmt.exchange(soci::into(stdUrl));
        stmt.exchange(soci::into(stdFullPath));
        stmt.exchange(soci::into(stdClassName));
        stmt.exchange(soci::into(stdMethodName));
        stmt.define_and_bind();
        if (stmt.execute(true)) {
            urlTag.Url.Create(t4p::CharToWx(stdUrl.c_str()));
            urlTag.FileName.Assign(t4p::CharToWx(stdFullPath.c_str()));
            urlTag.ClassName = t4p::CharToWx(stdClassName.c_str());
            urlTag.MethodName = t4p::CharToWx(stdMethodName.c_str());
            ret = true;
        }
    } catch (std::exception& e) {
        wxUnusedVar(e);
        wxString msg = t4p::CharToWx(e.what());
        wxASSERT_MSG(false, msg);
    }
    return ret;
}
Exemple #4
0
void wxURI::Resolve(const wxURI& base, int flags)
{
    wxASSERT_MSG(!base.IsReference(),
                "wxURI to inherit from must not be a reference!");

    // If we aren't being strict, enable the older (pre-RFC2396) loophole that
    // allows this uri to inherit other properties from the base uri - even if
    // the scheme is defined
    if ( !(flags & wxURI_STRICT) &&
            HasScheme() && base.HasScheme() &&
                m_scheme == base.m_scheme )
    {
        m_fields -= wxURI_SCHEME;
    }


    // Do nothing if this is an absolute wxURI
    //    if defined(R.scheme) then
    //       T.scheme    = R.scheme;
    //       T.authority = R.authority;
    //       T.path      = remove_dot_segments(R.path);
    //       T.query     = R.query;
    if (HasScheme())
        return;

    //No scheme - inherit
    m_scheme = base.m_scheme;
    m_fields |= wxURI_SCHEME;

    // All we need to do for relative URIs with an
    // authority component is just inherit the scheme
    //       if defined(R.authority) then
    //          T.authority = R.authority;
    //          T.path      = remove_dot_segments(R.path);
    //          T.query     = R.query;
    if (HasServer())
        return;

    //No authority - inherit
    if (base.HasUserInfo())
    {
        m_userinfo = base.m_userinfo;
        m_fields |= wxURI_USERINFO;
    }

    m_server = base.m_server;
    m_hostType = base.m_hostType;
    m_fields |= wxURI_SERVER;

    if (base.HasPort())
    {
        m_port = base.m_port;
        m_fields |= wxURI_PORT;
    }


    // Simple path inheritance from base
    if (!HasPath())
    {
        //             T.path = Base.path;
        m_path = base.m_path;
        m_fields |= wxURI_PATH;


        //             if defined(R.query) then
        //                T.query = R.query;
        //             else
        //                T.query = Base.query;
        //             endif;
        if (!HasQuery())
        {
            m_query = base.m_query;
            m_fields |= wxURI_QUERY;
        }
    }
    else if ( m_path.empty() || m_path[0u] != '/' )
    {
        //             if (R.path starts-with "/") then
        //                T.path = remove_dot_segments(R.path);
        //             else
        //                T.path = merge(Base.path, R.path);
        //                T.path = remove_dot_segments(T.path);
        //             endif;
        //             T.query = R.query;
        //
        // So we don't do anything for absolute paths and implement merge for
        // the relative ones

        wxArrayString our(SplitInSegments(m_path)),
                      result(SplitInSegments(base.m_path));

        if ( !result.empty() )
            result.pop_back();

        if ( our.empty() )
        {
            // if we have an empty path it means we were constructed from a "."
            // string or something similar (e.g. "././././"), it should count
            // as (empty) segment
            our.push_back("");
        }

        const wxArrayString::const_iterator end = our.end();
        for ( wxArrayString::const_iterator i = our.begin(); i != end; ++i )
        {
            if ( i->empty() || *i == "." )
            {
                // as in ParsePath(), while normally we ignore the empty
                // segments, we need to take account of them at the end
                if ( i == end - 1 )
                    result.push_back("");
                continue;
            }

            if ( *i == ".." )
            {
                if ( !result.empty() )
                {
                    result.pop_back();

                    if ( i == end - 1 )
                        result.push_back("");
                }
                //else: just ignore, extra ".." don't accumulate
            }
            else
            {
                if ( result.empty() )
                {
                    // ensure that the resulting path will always be absolute
                    result.push_back("");
                }

                result.push_back(*i);
            }
        }

        m_path = wxJoin(result, '/', '\0');
    }

    //T.fragment = R.fragment;
}
Exemple #5
0
bool wxURI::operator==(const wxURI& uri) const
{
    if (HasScheme())
    {
        if(m_scheme != uri.m_scheme)
            return false;
    }
    else if (uri.HasScheme())
        return false;


    if (HasServer())
    {
        if (HasUserInfo())
        {
            if (m_userinfo != uri.m_userinfo)
                return false;
        }
        else if (uri.HasUserInfo())
            return false;

        if (m_server != uri.m_server ||
            m_hostType != uri.m_hostType)
            return false;

        if (HasPort())
        {
            if(m_port != uri.m_port)
                return false;
        }
        else if (uri.HasPort())
            return false;
    }
    else if (uri.HasServer())
        return false;


    if (HasPath())
    {
        if(m_path != uri.m_path)
            return false;
    }
    else if (uri.HasPath())
        return false;

    if (HasQuery())
    {
        if (m_query != uri.m_query)
            return false;
    }
    else if (uri.HasQuery())
        return false;

    if (HasFragment())
    {
        if (m_fragment != uri.m_fragment)
            return false;
    }
    else if (uri.HasFragment())
        return false;

    return true;
}
Exemple #6
0
wxURL::wxURL(const wxURI& url) : wxURI(url)
{
    Init(url.BuildURI());
    ParseURL();
}
Exemple #7
0
void wxURI::Resolve(const wxURI& base, int flags)
{
    wxASSERT_MSG(!base.IsReference(),
                wxT("wxURI to inherit from must not be a reference!"));

    // If we arn't being strict, enable the older (pre-RFC2396)
    // loophole that allows this uri to inherit other
    // properties from the base uri - even if the scheme
    // is defined
    if ( !(flags & wxURI_STRICT) &&
            HasScheme() && base.HasScheme() &&
                m_scheme == base.m_scheme )
    {
        m_fields -= wxURI_SCHEME;
    }


    // Do nothing if this is an absolute wxURI
    //    if defined(R.scheme) then
    //       T.scheme    = R.scheme;
    //       T.authority = R.authority;
    //       T.path      = remove_dot_segments(R.path);
    //       T.query     = R.query;
    if (HasScheme())
    {
        return;
    }

    //No scheme - inherit
    m_scheme = base.m_scheme;
    m_fields |= wxURI_SCHEME;

    // All we need to do for relative URIs with an
    // authority component is just inherit the scheme
    //       if defined(R.authority) then
    //          T.authority = R.authority;
    //          T.path      = remove_dot_segments(R.path);
    //          T.query     = R.query;
    if (HasServer())
    {
        return;
    }

    //No authority - inherit
    if (base.HasUserInfo())
    {
        m_userinfo = base.m_userinfo;
        m_fields |= wxURI_USERINFO;
    }

    m_server = base.m_server;
    m_hostType = base.m_hostType;
    m_fields |= wxURI_SERVER;

    if (base.HasPort())
    {
        m_port = base.m_port;
        m_fields |= wxURI_PORT;
    }


    // Simple path inheritance from base
    if (!HasPath())
    {
        //             T.path = Base.path;
        m_path = base.m_path;
        m_fields |= wxURI_PATH;


        //             if defined(R.query) then
        //                T.query = R.query;
        //             else
        //                T.query = Base.query;
        //             endif;
        if (!HasQuery())
        {
            m_query = base.m_query;
            m_fields |= wxURI_QUERY;
        }
    }
    else
    {
        //             if (R.path starts-with "/") then
        //                T.path = remove_dot_segments(R.path);
        //             else
        //                T.path = merge(Base.path, R.path);
        //                T.path = remove_dot_segments(T.path);
        //             endif;
        //             T.query = R.query;
        if (m_path.empty() || m_path[0u] != wxT('/'))
        {
            //Merge paths
            const wxChar* op = m_path.c_str();
            const wxChar* bp = base.m_path.c_str() + base.m_path.Length();

            //not a ending directory?  move up
            if (base.m_path[0] && *(bp-1) != wxT('/'))
                UpTree(base.m_path, bp);

            //normalize directories
            while(*op == wxT('.') && *(op+1) == wxT('.') &&
                       (*(op+2) == '\0' || *(op+2) == wxT('/')) )
            {
                UpTree(base.m_path, bp);

                if (*(op+2) == '\0')
                    op += 2;
                else
                    op += 3;
            }

            m_path = base.m_path.substr(0, bp - base.m_path.c_str()) +
                    m_path.substr((op - m_path.c_str()), m_path.Length());
        }
    }

    //T.fragment = R.fragment;
}